Files
admin-web/src/modules/appointment-calendar/planningApi.test.ts
T

30 lines
2.1 KiB
TypeScript

import { expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import { listPlanningCargo, listPlanningContainers, resolvePlanningOrder } from './planningApi'
vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn() }, unwrapApiResponse: <T>(value: { data: T }) => value.data }))
it('uses the gateway planning route and preserves stable source IDs and null predictions', async () => {
vi.mocked(http.get).mockResolvedValue({ data: { records: [{ sourceKey: 'ORDER:9007199254740993', orderId: '9007199254740993', estimatedArrivalAt: null }], page: '2', size: '20', total: '21', pages: '2' } })
const controller = new AbortController()
const result = await listPlanningCargo({ page: 2, size: 20, keyword: 'IN-A' }, controller.signal)
expect(http.get).toHaveBeenCalledWith('/platform/v1/last-leg/appointment-planning/cargo', { params: { page: 2, size: 20, keyword: 'IN-A' }, signal: controller.signal })
expect(result.records[0]!.orderId).toBe('9007199254740993')
expect(result.records[0]!.estimatedArrivalAt).toBeNull()
expect(result.total).toBe(21)
})
it('keeps basic container listing on its own endpoint rather than requiring impact persistence', async () => {
vi.mocked(http.get).mockClear()
vi.mocked(http.get).mockResolvedValue({ data: { records: [], total: '0' } })
const result = await listPlanningContainers({ page: 1, size: 20 })
expect(http.get).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/appointment-planning/containers', { params: { page: 1, size: 20 }, signal: undefined })
expect(result.total).toBe(0)
})
it('resolves an order through the real canonical-source endpoint without fabricating an ORDER alias', async () => {
vi.mocked(http.get).mockClear()
vi.mocked(http.get).mockResolvedValue({data:{source:{sourceKey:'BOOKING:B-1'},coverage:{appointments:[]}}})
const query = {orderId:'9007199254740993',customerId:'customer-a',destinationKey:'FBA:ONT8'}
expect((await resolvePlanningOrder(query)).source.sourceKey).toBe('BOOKING:B-1')
expect(http.get).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/appointment-planning/sources/resolve-order',{params:query})
})