import { beforeEach, describe, expect, it, vi } from 'vitest' import { http } from '@/shared/api/http' import { approveMeasurement, getMeasurementReviewDetail, listMeasurementReviewHistory, } from './api' vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn(), post: vi.fn() }, unwrapApiResponse: (response: { data: T }) => response.data, })) describe('measurement review API', () => { beforeEach(() => { vi.mocked(http.get).mockReset() vi.mocked(http.post).mockReset() }) it('keeps the measurement detail and review history prefixes from the backend controllers', async () => { vi.mocked(http.get) .mockResolvedValueOnce({ code: '200', message: 'success', data: { measurementId: '7' } }) .mockResolvedValueOnce({ code: '200', message: 'success', data: { records: [], page: '1', size: '20', total: '0', pages: '0' } }) await getMeasurementReviewDetail('10001', '90001') await listMeasurementReviewHistory('10001', '90001') expect(http.get).toHaveBeenNthCalledWith(1, '/platform/v1/first-leg/inbounds/90001/measurement', { params: { tenantId: '10001' } }) expect(http.get).toHaveBeenNthCalledWith(2, '/platform/v1/inbounds/90001/measurement-review-history', { params: { tenantId: '10001', page: 1, size: 20 } }) }) it('normalizes string pagination and sends idempotency headers for review writes', async () => { vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: { records: [], page: '2', size: '20', total: '3', pages: '1' } }) vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: null }) await expect(listMeasurementReviewHistory('10001', '90001', 2, 20)).resolves.toMatchObject({ page: 2, total: 3 }) await approveMeasurement('10001', '90001', { measurementId: '7', expectedVersion: 4 }, 'approve-key') expect(http.post).toHaveBeenNthCalledWith(1, '/platform/v1/inbounds/90001/measurements/approve', { measurementId: '7', expectedVersion: 4 }, { params: { tenantId: '10001' }, headers: { 'Idempotency-Key': 'approve-key' } }) expect(http.post).toHaveBeenCalledTimes(1) }) })