Modernizes testing infrastructure with dedicated Cloudflare Workers test pool: - Replaces Nuxt Test Utils with @cloudflare/vitest-pool-workers - Adds structured test organization for API endpoints - Introduces comprehensive testing patterns and examples - Implements schema-based test data generation with zod-mock - Enhances test utilities with proper CF Workers environment The new testing setup provides better isolation, more realistic worker runtime environment, and improved test data management through structured schemas and generators.
23 lines
727 B
TypeScript
23 lines
727 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { fetch, fetchWithAuth } from '../utils'
|
|
|
|
describe('/api/location', () => {
|
|
it('returns location data with valid auth', async () => {
|
|
const response = await fetchWithAuth('/api/location')
|
|
|
|
expect(response.status).toBe(200)
|
|
|
|
// TODO: request.cf mock
|
|
// const data = await response.json()
|
|
// expect(data.latitude).toBeTypeOf('string')
|
|
// expect(data.longitude).toBeTypeOf('string')
|
|
// expect(Number(data.latitude)).not.toBeNaN()
|
|
// expect(Number(data.longitude)).not.toBeNaN()
|
|
})
|
|
|
|
it('returns 401 when accessing without auth', async () => {
|
|
const response = await fetch('/api/location')
|
|
|
|
expect(response.status).toBe(401)
|
|
})
|
|
})
|