From e1ae299326303578b0d51b25ca6d797259fdd20c Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 22 Apr 2026 18:12:06 +0200 Subject: [PATCH] test(proxy): add PATCH forwarding and absent Content-Length coverage Closes the two untested code paths flagged in review: - PATCH method routes to backend with correct URL - Requests without Content-Length header pass through (NaN > n = false) Co-Authored-By: Claude Sonnet 4.6 --- .../src/routes/api/[...path]/proxy.spec.ts | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/frontend/src/routes/api/[...path]/proxy.spec.ts b/frontend/src/routes/api/[...path]/proxy.spec.ts index 310fa632..f681799b 100644 --- a/frontend/src/routes/api/[...path]/proxy.spec.ts +++ b/frontend/src/routes/api/[...path]/proxy.spec.ts @@ -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); + }); });