26 lines
1.7 KiB
TypeScript
26 lines
1.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|||
|
|
import { http } from '@/shared/api/http'
|
||
|
|
import { changeTruckAppointmentStatus, createTruckAppointment, getTruckAppointment, listTruckAppointments } from './platformTrucking'
|
||
|
|
|
||
|
|
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' } })
|
||
|
|
await expect(listTruckAppointments({ page: 2, size: 20, keyword: ' BY ', status: 'DISPATCHED', containerType: '40HC' })).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', containerType: '40HC' } })
|
||
|
|
})
|
||
|
|
|
||
|
|
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' })
|
||
|
|
vi.mocked(http.patch).mockResolvedValue({ data: null })
|
||
|
|
await expect(getTruckAppointment('9001')).resolves.toMatchObject({ id: '9001' })
|
||
|
|
await expect(createTruckAppointment({ expectedLoadingDate: '2026-08-10' })).resolves.toBe('9001')
|
||
|
|
await expect(changeTruckAppointmentStatus('9001', 'DISPATCHED')).resolves.toBeNull()
|
||
|
|
expect(http.patch).toHaveBeenCalledWith('/platform/v1/truck-appointments/9001/status', { status: 'DISPATCHED' })
|
||
|
|
})
|
||
|
|
})
|