fix(transcription): replace sendBeacon with fetch keepalive; add catch-all API proxy #304

Merged
marcel merged 7 commits from fix/204-transcription-beacon-proxy into main 2026-04-23 07:12:23 +02:00
Showing only changes of commit 8eba2cda7d - Show all commits

View File

@@ -2,7 +2,7 @@ import { describe, it, expect, vi } from 'vitest';
process.env.API_INTERNAL_URL = 'http://backend:8080';
const { GET, PUT, POST } = await import('./+server');
const { GET, PUT, POST, PATCH } = await import('./+server');
function makeEvent(
path: string,
@@ -69,6 +69,21 @@ describe('catch-all API proxy — body size limit', () => {
expect(mockFetch).not.toHaveBeenCalled();
});
it('forwards request when Content-Length header is absent', async () => {
const mockFetch = vi.fn().mockResolvedValue(new Response('{}', { status: 200 }));
const event = makeEvent('documents', 'POST', mockFetch);
(event.request as Request) = new Request('http://localhost/api/documents', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title: 'hello' })
});
const response = await POST(event as never);
expect(response.status).toBe(200);
expect(mockFetch).toHaveBeenCalled();
});
it('does not reject request with Content-Length exactly at 1 MB', async () => {
const mockFetch = vi.fn().mockResolvedValue(new Response('{}', { status: 200 }));
const event = makeEvent('documents', 'POST', mockFetch);
@@ -153,4 +168,22 @@ describe('catch-all API proxy — forwarding', () => {
expect(response.headers.get('Transfer-Encoding')).toBeNull();
});
it('forwards PATCH request to backend with correct URL', async () => {
const mockFetch = vi.fn().mockResolvedValue(new Response('{}', { status: 200 }));
const event = makeEvent('documents/doc-1', 'PATCH', mockFetch);
(event.request as Request) = new Request('http://localhost/api/documents/doc-1', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title: 'updated' })
});
const response = await PATCH(event as never);
expect(mockFetch).toHaveBeenCalledWith(
'http://backend:8080/api/documents/doc-1',
expect.objectContaining({ method: 'PATCH' })
);
expect(response.status).toBe(200);
});
});