diff --git a/src/lib/api/client.ts b/src/lib/api/client.ts index 11aa0b5..76b982e 100644 --- a/src/lib/api/client.ts +++ b/src/lib/api/client.ts @@ -1,4 +1,4 @@ -import type { components } from './schema'; +import type { components, operations } from './schema'; export type AuthSession = components['schemas']['AuthSession']; export type ReportingPeriod = components['schemas']['ReportingPeriod']; @@ -12,6 +12,8 @@ export type DetailView = components['schemas']['DetailView']; export type FailureStage = components['schemas']['FailureStage']; export type Problem = components['schemas']['Problem']; export type GrowthReport = components['schemas']['GrowthReport']; +export type CreateGrowthReportRequest = + operations['createGrowthReport']['requestBody']['content']['application/json']; const apiBase = (import.meta.env.PUBLIC_API_BASE_URL || '/api/v1').replace(/\/$/, ''); @@ -124,7 +126,7 @@ export const api = { const query = terminalId ? `?terminalId=${encodeURIComponent(terminalId)}` : ''; return request(`/analytics/growth-reports/latest${query}`); }, - createGrowthReport(csrfToken: string, options: { terminalId?: string; refresh?: boolean } = {}) { + createGrowthReport(csrfToken: string, options: CreateGrowthReportRequest = {}) { return request('/analytics/growth-reports', { method: 'POST', headers: { diff --git a/src/lib/api/growth-client.test.ts b/src/lib/api/growth-client.test.ts index 06a33e6..fb19833 100644 --- a/src/lib/api/growth-client.test.ts +++ b/src/lib/api/growth-client.test.ts @@ -53,4 +53,19 @@ describe('growth report API client', () => { expect(init.headers['Idempotency-Key']).toBe('idempotency-1'); expect(JSON.parse(init.body)).toEqual({ terminalId: 'terminal-1', refresh: true }); }); + + it('creates a report with an empty request when optional fields are omitted', async () => { + const fetchMock = vi.fn().mockResolvedValue( + new Response(JSON.stringify(report), { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }), + ); + vi.stubGlobal('fetch', fetchMock); + vi.stubGlobal('crypto', { randomUUID: () => 'idempotency-2' }); + + await api.createGrowthReport('csrf-2'); + + expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({}); + }); }); diff --git a/src/lib/api/schema.d.ts b/src/lib/api/schema.d.ts index 0713585..04502de 100644 --- a/src/lib/api/schema.d.ts +++ b/src/lib/api/schema.d.ts @@ -337,8 +337,8 @@ export interface components { schemas: { CreateGrowthReportRequest: { terminalId?: string; - /** @default false */ - refresh: boolean; + /** @description When omitted, the request reuses the current matching report. */ + refresh?: boolean; }; GrowthRange: { /** Format: int64 */