From 5d69b824c7f2de15101c2c66fe24d19db3a7af9b Mon Sep 17 00:00:00 2001 From: Filionus Date: Sat, 28 Nov 2026 13:02:03 +0100 Subject: [PATCH] Make the API redirect test independent of the database The test expected GET /api/health to return 200. With feat/b6-health-keepalive the route queries the database and returns 503 when Supabase is not configured or unreachable. The test only has to show that API routes are not redirected to a language prefix. It now checks that there is no Location header, accepts 200 or 503, and requires a JSON response, so a 404 or an HTML page still fails. Failing-first does not apply here: the old test is green on main today. Co-Authored-By: Claude Sonnet 5.5 --- i18n/__tests__/persistence.spec.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/i18n/__tests__/persistence.spec.ts b/i18n/__tests__/persistence.spec.ts index d115c17..4b3781f 100644 --- a/i18n/__tests__/persistence.spec.ts +++ b/i18n/__tests__/persistence.spec.ts @@ -29,6 +29,7 @@ async function visit(path: string, { saved, browser }: Visitor = {}) { return { status: response.status, location: response.headers.get('location'), + contentType: response.headers.get('content-type') ?? '', cookie: response.headers.get('set-cookie') ?? '', body: await response.text(), } @@ -128,9 +129,13 @@ describe('the sign-in return page', () => { }) describe('API routes', () => { + // The status depends on the database: 200 if it answers, 503 if not. + // Both come from the API itself, which is all this test needs. test('are never redirected to a language prefix', async () => { const response = await visit('/api/health', { saved: 'nl', browser: 'nl-NL' }) - expect(response.status).toBe(200) - expect(JSON.parse(response.body)).toEqual({ status: 'ok' }) + expect(response.location).toBeNull() + expect([200, 503]).toContain(response.status) + // A page of the app would be HTML, so JSON shows that the API route answered. + expect(response.contentType).toContain('application/json') }) })