mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-30 17:50:07 +08:00
575c10c77d
CI has no .dev.vars file, so env.BETTER_AUTH_SECRET is empty. Tests that call worker.fetch now use a fallback test secret when the env binding is not set. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { env } from 'cloudflare:workers'
|
|
import { describe, expect, it } from 'vitest'
|
|
import worker from './bootstrap'
|
|
|
|
const testEnv = { ...env, BETTER_AUTH_SECRET: env.BETTER_AUTH_SECRET || 'ci-test-secret-that-is-at-least-32-chars' }
|
|
|
|
describe('[CF] Worker fetch handler', () => {
|
|
it('throws when BETTER_AUTH_SECRET is missing', async () => {
|
|
const request = new Request('http://localhost/api/health')
|
|
const envWithoutSecret = { ...env, BETTER_AUTH_SECRET: '' }
|
|
await expect(worker.fetch(request, envWithoutSecret)).rejects.toThrow(
|
|
'BETTER_AUTH_SECRET is not configured for this deployment.',
|
|
)
|
|
})
|
|
|
|
it('returns a response for a valid request', async () => {
|
|
const request = new Request('http://localhost/api/health')
|
|
const res = await worker.fetch(request, testEnv)
|
|
expect(res.status).toBe(200)
|
|
expect(await res.json()).toEqual({ status: 'ok' })
|
|
})
|
|
|
|
it('splits and trims TRUSTED_ORIGINS when provided', async () => {
|
|
const request = new Request('http://localhost/api/health')
|
|
const envWithOrigins = { ...testEnv, TRUSTED_ORIGINS: ' https://a.example.com , https://b.example.com ' }
|
|
const res = await worker.fetch(request, envWithOrigins)
|
|
expect(res.status).toBe(200)
|
|
})
|
|
})
|