2026-08-08 13:32:27 +08:00
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import { http } from '@/shared/api/http'
|
2026-08-08 13:46:21 +08:00
|
|
|
import { createTruckAppointment, getTruckAppointment, listTruckAppointments, performTruckAppointmentAction } from './platformTrucking'
|
2026-08-08 13:32:27 +08:00
|
|
|
|
|
|
|
|
vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn() }, unwrapApiResponse: (response: { data: unknown }) => response.data }))
|
|
|
|
|
|
|
|
|
|
describe('truck appointment API', () => {
|
|
|
|
|
beforeEach(() => { vi.clearAllMocks() })
|
|
|
|
|
|
|
|
|
|
it('normalizes page values and maps filters', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({ data: { records: [], page: '2', size: '20', total: '21', pages: '2' } })
|
2026-08-08 13:46:21 +08:00
|
|
|
await expect(listTruckAppointments({ page: 2, size: 20, keyword: ' BY ', status: 'DISPATCHED', containerBookingId: '77' })).resolves.toMatchObject({ page: 2, total: 21, pages: 2 })
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/truck-appointments', { params: { page: 2, size: 20, keyword: 'BY', status: 'DISPATCHED', containerBookingId: '77' } })
|
2026-08-08 13:32:27 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('uses detail, create, and status contracts', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({ data: { id: '9001', status: 'DRAFT' } })
|
|
|
|
|
vi.mocked(http.post).mockResolvedValue({ data: '9001' })
|
2026-08-08 13:46:21 +08:00
|
|
|
vi.mocked(http.post).mockResolvedValue({ data: { id: '9001', status: 'DISPATCHED' } })
|
2026-08-08 13:32:27 +08:00
|
|
|
await expect(getTruckAppointment('9001')).resolves.toMatchObject({ id: '9001' })
|
2026-08-08 13:46:21 +08:00
|
|
|
await expect(createTruckAppointment({ plannedLoadingAt: '2026-08-10T10:00:00', expectedVersion: 0 })).resolves.toMatchObject({ id: '9001' })
|
|
|
|
|
await expect(performTruckAppointmentAction('9001', 'DISPATCH', 2)).resolves.toMatchObject({ status: 'DISPATCHED' })
|
|
|
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/truck-appointments/9001/dispatch', { expectedVersion: 2, reason: null }, { headers: {} })
|
2026-08-08 13:32:27 +08:00
|
|
|
})
|
|
|
|
|
})
|