fix: derive growth create input from OpenAPI
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import type { components } from './schema';
|
import type { components, operations } from './schema';
|
||||||
|
|
||||||
export type AuthSession = components['schemas']['AuthSession'];
|
export type AuthSession = components['schemas']['AuthSession'];
|
||||||
export type ReportingPeriod = components['schemas']['ReportingPeriod'];
|
export type ReportingPeriod = components['schemas']['ReportingPeriod'];
|
||||||
@@ -12,6 +12,8 @@ export type DetailView = components['schemas']['DetailView'];
|
|||||||
export type FailureStage = components['schemas']['FailureStage'];
|
export type FailureStage = components['schemas']['FailureStage'];
|
||||||
export type Problem = components['schemas']['Problem'];
|
export type Problem = components['schemas']['Problem'];
|
||||||
export type GrowthReport = components['schemas']['GrowthReport'];
|
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(/\/$/, '');
|
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)}` : '';
|
const query = terminalId ? `?terminalId=${encodeURIComponent(terminalId)}` : '';
|
||||||
return request<GrowthReport>(`/analytics/growth-reports/latest${query}`);
|
return request<GrowthReport>(`/analytics/growth-reports/latest${query}`);
|
||||||
},
|
},
|
||||||
createGrowthReport(csrfToken: string, options: { terminalId?: string; refresh?: boolean } = {}) {
|
createGrowthReport(csrfToken: string, options: CreateGrowthReportRequest = {}) {
|
||||||
return request<GrowthReport>('/analytics/growth-reports', {
|
return request<GrowthReport>('/analytics/growth-reports', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -53,4 +53,19 @@ describe('growth report API client', () => {
|
|||||||
expect(init.headers['Idempotency-Key']).toBe('idempotency-1');
|
expect(init.headers['Idempotency-Key']).toBe('idempotency-1');
|
||||||
expect(JSON.parse(init.body)).toEqual({ terminalId: 'terminal-1', refresh: true });
|
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({});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
4
src/lib/api/schema.d.ts
vendored
4
src/lib/api/schema.d.ts
vendored
@@ -337,8 +337,8 @@ export interface components {
|
|||||||
schemas: {
|
schemas: {
|
||||||
CreateGrowthReportRequest: {
|
CreateGrowthReportRequest: {
|
||||||
terminalId?: string;
|
terminalId?: string;
|
||||||
/** @default false */
|
/** @description When omitted, the request reuses the current matching report. */
|
||||||
refresh: boolean;
|
refresh?: boolean;
|
||||||
};
|
};
|
||||||
GrowthRange: {
|
GrowthRange: {
|
||||||
/** Format: int64 */
|
/** Format: int64 */
|
||||||
|
|||||||
Reference in New Issue
Block a user