From 4b84f609b753277c314ccd3f8cc73ddc08e6598f Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Mon, 23 Feb 2026 21:01:48 -0800 Subject: [PATCH] Fix content type and offset detection --- frontend/src/api.ts | 7 ++++--- frontend/src/test/api.test.ts | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 9fdee96..ee7f396 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -21,10 +21,11 @@ import type { const API_BASE = '/api'; async function fetchJson(url: string, options?: RequestInit): Promise { + const hasBody = options?.body !== undefined; const res = await fetch(`${API_BASE}${url}`, { ...options, headers: { - 'Content-Type': 'application/json', + ...(hasBody && { 'Content-Type': 'application/json' }), ...options?.headers, }, }); @@ -148,8 +149,8 @@ export const api = { signal?: AbortSignal ) => { const searchParams = new URLSearchParams(); - if (params?.limit) searchParams.set('limit', params.limit.toString()); - if (params?.offset) searchParams.set('offset', params.offset.toString()); + if (params?.limit !== undefined) searchParams.set('limit', params.limit.toString()); + if (params?.offset !== undefined) searchParams.set('offset', params.offset.toString()); if (params?.type) searchParams.set('type', params.type); if (params?.conversation_key) searchParams.set('conversation_key', params.conversation_key); if (params?.before !== undefined) searchParams.set('before', params.before.toString()); diff --git a/frontend/src/test/api.test.ts b/frontend/src/test/api.test.ts index f59fc5c..9e47917 100644 --- a/frontend/src/test/api.test.ts +++ b/frontend/src/test/api.test.ts @@ -159,7 +159,7 @@ describe('fetchJson (via api methods)', () => { }); describe('Content-Type header', () => { - it('always sends Content-Type: application/json on GET requests', async () => { + it('omits Content-Type on GET requests (no body)', async () => { installMockFetch(); mockFetch.mockResolvedValueOnce({ ok: true, @@ -169,12 +169,10 @@ describe('fetchJson (via api methods)', () => { await api.getHealth(); const [, options] = mockFetch.mock.calls[0]; - expect(options.headers).toEqual( - expect.objectContaining({ 'Content-Type': 'application/json' }) - ); + expect(options.headers).not.toHaveProperty('Content-Type'); }); - it('always sends Content-Type: application/json on POST requests', async () => { + it('sends Content-Type: application/json on POST requests with body', async () => { installMockFetch(); mockFetch.mockResolvedValueOnce({ ok: true,