import { beforeEach, describe, expect, it, vi } from 'vitest' import { overseasHttp } from '@/shared/api/overseasHttp' import { listDispatchCandidates, listDispatches, lockDispatchDraftPallet, preArrangeDispatch, releaseDispatchDraft, unlockDispatchDraftPallet } from './dispatches' vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), post: vi.fn() } })) describe('dispatch overseas API', () => { beforeEach(() => { vi.mocked(overseasHttp.get).mockReset() vi.mocked(overseasHttp.post).mockReset() }) it('uses the platform dispatch page without customer scope', async () => { vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: { records: [], page: 2, size: 50, total: 0, pages: 0 }, }) await listDispatches({ page: 2, size: 50, dispatchNo: 'PC-1', vehiclePlate: 'CA-100', status: 'PENDING_DEPARTURE', fbaAppointmentNo: 'FBA-1', }) expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/dispatches', { params: { page: 2, size: 50, dispatchNo: 'PC-1', vehiclePlate: 'CA-100', status: 'PENDING_DEPARTURE', fbaAppointmentNo: 'FBA-1', }, }) }) it('loads candidates and creates a pre-arrange dispatch in an explicit customer scope', async () => { vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: [] }) vi.mocked(overseasHttp.post).mockResolvedValue({ code: '200', message: 'success', data: { id: '1', dispatchNo: 'PC-1' } }) await listDispatchCandidates({ planIds: '101,102', fbaWarehouseCode: 'ONT8', sourceStage: 'PLAN' }) await preArrangeDispatch({ planPalletIds: ['190000000000000099'], route: 'LAX -> ONT8' }) expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/dispatches/candidates', { params: { planIds: '101,102', fbaWarehouseCode: 'ONT8', sourceStage: 'PLAN' } }) expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/last-leg/dispatches/pre-arrange', { planPalletIds: ['190000000000000099'], route: 'LAX -> ONT8' }) }) it('loads platform candidates without selected inbound plans', async () => { vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: [] }) await listDispatchCandidates({ sourceStage: 'RECEIVED' }) expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/dispatches/candidates', { params: { sourceStage: 'RECEIVED' }, }) }) it('locks, unlocks, and releases intelligent dispatch drafts through dedicated endpoints', async () => { vi.mocked(overseasHttp.post).mockResolvedValue({ code: '200', message: 'success', data: null }) await lockDispatchDraftPallet('99', 'draft-1') await unlockDispatchDraftPallet('99', 'draft-1') await releaseDispatchDraft('draft-1') expect(overseasHttp.post).toHaveBeenNthCalledWith(1, '/platform/v1/last-leg/dispatches/draft-locks/lock', { planPalletId: '99', draftToken: 'draft-1' }) expect(overseasHttp.post).toHaveBeenNthCalledWith(2, '/platform/v1/last-leg/dispatches/draft-locks/unlock', { planPalletId: '99', draftToken: 'draft-1' }) expect(overseasHttp.post).toHaveBeenNthCalledWith(3, '/platform/v1/last-leg/dispatches/draft-locks/release', { draftToken: 'draft-1' }) }) })