feat(platform-web): query raw frames with post body
This commit is contained in:
39
vehicle-data-platform/apps/web/src/api/client.test.ts
Normal file
39
vehicle-data-platform/apps/web/src/api/client.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { afterEach, expect, test, vi } from 'vitest';
|
||||
import { api } from './client';
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
test('rawFramesQuery posts structured JSON instead of URL query strings', async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, 'fetch').mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: { items: [], total: 0, limit: 20, offset: 0 },
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response);
|
||||
|
||||
await api.rawFramesQuery({
|
||||
keyword: '粤AG18312',
|
||||
protocol: 'GB32960',
|
||||
fields: ['gb32960.vehicle.speed_kmh'],
|
||||
includeFields: true,
|
||||
limit: 20,
|
||||
offset: 0
|
||||
});
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/history/raw-frames/query', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
keyword: '粤AG18312',
|
||||
protocol: 'GB32960',
|
||||
fields: ['gb32960.vehicle.speed_kmh'],
|
||||
includeFields: true,
|
||||
limit: 20,
|
||||
offset: 0
|
||||
})
|
||||
});
|
||||
});
|
||||
@@ -16,6 +16,18 @@ import type {
|
||||
VehicleRow
|
||||
} from './types';
|
||||
|
||||
export type RawFrameQuery = {
|
||||
keyword?: string;
|
||||
vin?: string;
|
||||
protocol?: string;
|
||||
dateFrom?: string;
|
||||
dateTo?: string;
|
||||
fields?: string[];
|
||||
includeFields?: boolean;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
};
|
||||
|
||||
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const response = await fetch(path, init);
|
||||
if (!response.ok) {
|
||||
@@ -34,6 +46,11 @@ export const api = {
|
||||
realtimeLocations: (params = new URLSearchParams()) => request<Page<RealtimeLocationRow>>(`/api/realtime/locations?${params.toString()}`),
|
||||
historyLocations: (params = new URLSearchParams()) => request<Page<HistoryLocationRow>>(`/api/history/locations?${params.toString()}`),
|
||||
rawFrames: (params = new URLSearchParams()) => request<Page<RawFrameRow>>(`/api/history/raw-frames?${params.toString()}`),
|
||||
rawFramesQuery: (query: RawFrameQuery) => request<Page<RawFrameRow>>('/api/history/raw-frames/query', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(query)
|
||||
}),
|
||||
mileageSummary: (params = new URLSearchParams()) => request<MileageSummary>(`/api/mileage/summary?${params.toString()}`),
|
||||
dailyMileage: (params = new URLSearchParams()) => request<Page<DailyMileageRow>>(`/api/mileage/daily?${params.toString()}`),
|
||||
qualitySummary: (params = new URLSearchParams()) => request<QualitySummary>(`/api/quality/summary?${params.toString()}`),
|
||||
|
||||
Reference in New Issue
Block a user