From 76ef54e0648b6460eeb553c645439c8a24694060 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 19 May 2026 21:28:39 +0200 Subject: [PATCH] test(transcription): cover non-JSON fallback in markAllReviewed error path Adds a test for when the server returns a non-JSON body (e.g. an nginx 502 HTML page). Confirms the res.json().catch(() => ({})) fallback produces 'INTERNAL_ERROR' as the thrown message and leaves blocks intact. Co-Authored-By: Claude Sonnet 4.6 --- .../useTranscriptionBlocks.svelte.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/frontend/src/lib/document/transcription/useTranscriptionBlocks.svelte.test.ts b/frontend/src/lib/document/transcription/useTranscriptionBlocks.svelte.test.ts index dd837f48..044aaed3 100644 --- a/frontend/src/lib/document/transcription/useTranscriptionBlocks.svelte.test.ts +++ b/frontend/src/lib/document/transcription/useTranscriptionBlocks.svelte.test.ts @@ -280,6 +280,25 @@ describe('createTranscriptionBlocks.markAllReviewed', () => { await expect(ctrl.markAllReviewed()).rejects.toThrow('INTERNAL_ERROR'); expect(ctrl.blocks[0].reviewed).toBe(false); }); + + it('throws INTERNAL_ERROR when PUT returns non-JSON body (e.g. nginx 502)', async () => { + const fetchImpl = vi.fn(async (url: RequestInfo | URL, init?: RequestInit) => { + const u = url.toString(); + const method = init?.method ?? 'GET'; + if (u.includes('/review-all') && method === 'PUT') { + return new Response('Bad Gateway', { status: 502 }); + } + return new Response(JSON.stringify([baseBlock({ id: 'b-1', reviewed: false })]), { + status: 200, + headers: { 'Content-Type': 'application/json' } + }); + }); + + const ctrl = createTranscriptionBlocks({ documentId: () => 'doc-1', fetchImpl }); + await ctrl.load(); + await expect(ctrl.markAllReviewed()).rejects.toThrow('INTERNAL_ERROR'); + expect(ctrl.blocks[0].reviewed).toBe(false); + }); }); describe('createTranscriptionBlocks.createFromDraw', () => {