18 lines
1.4 KiB
TypeScript
18 lines
1.4 KiB
TypeScript
import { beforeEach, expect, it, vi } from 'vitest'
|
|
import { http } from '@/shared/api/http'
|
|
import { listVehicleDeliveries, listVehicleAssignmentChanges } from './vehicleFulfillment'
|
|
vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn() }, unwrapApiResponse: (value: {data: unknown}) => value.data }))
|
|
beforeEach(() => { vi.clearAllMocks() })
|
|
it('encodes the stable vehicle key and adapts serialized pagination without a plate or customer override', async () => {
|
|
vi.mocked(http.get).mockResolvedValue({ data: { records: [{ deliveryNo: 'DL-1' }], page: '1', size: '10', total: '1', pages: '1' } })
|
|
const result=await listVehicleDeliveries('900719925474099301')
|
|
expect(http.get).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/fleet/vehicles/900719925474099301/deliveries', { params: { page: 1, size: 10 } })
|
|
expect(result.total).toBe(1)
|
|
})
|
|
it('history preserves large serialized versions and rejects invalid pagination', async () => {
|
|
vi.mocked(http.get).mockResolvedValue({ data: { records: [{ tripNo:'TR-1', recordVersion:'900719925474099301' }], page:'1',size:'10',total:'1',pages:'1' } })
|
|
expect((await listVehicleAssignmentChanges('8')).records[0]?.recordVersion).toBe('900719925474099301')
|
|
vi.mocked(http.get).mockResolvedValue({ data: { records: [], page:'1',size:'10',total:'not-a-number',pages:'1' } })
|
|
await expect(listVehicleAssignmentChanges('8')).rejects.toThrow('分页数值')
|
|
})
|