import { expect, it, vi } from 'vitest' import { http } from '@/shared/api/http' import { listPlanningCargo, listPlanningDestinations, listPlanningContainers, resolvePlanningOrder } from './planningApi' vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn() }, unwrapApiResponse: (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('uses authoritative destination options and sends the selected destination to server pagination', async () => { vi.mocked(http.get).mockClear() vi.mocked(http.get).mockResolvedValueOnce({data:['ABE4','ONT8']}) expect(await listPlanningDestinations()).toEqual(['ABE4','ONT8']) expect(http.get).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/appointment-planning/cargo/destinations',{signal:undefined}) vi.mocked(http.get).mockResolvedValueOnce({data:{records:[],page:2,size:20,total:0,pages:0}}) await listPlanningCargo({page:2,size:20,keyword:'IN-A',destination:'ONT8'}) expect(http.get).toHaveBeenLastCalledWith('/platform/v1/last-leg/appointment-planning/cargo',{params:{page:2,size:20,keyword:'IN-A',destination:'ONT8'},signal:undefined}) }) 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}) })