Files
admin-web/src/modules/overseas-warehouse/api/lastMileOrders.test.ts
T

37 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-08-20 09:10:36 +08:00
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { overseasHttp } from '@/shared/api/overseasHttp'
2026-08-21 11:20:09 +08:00
import { getLastMileOrder, listLastMileOrders, transferLastMileOrders } from './lastMileOrders'
2026-08-20 09:10:36 +08:00
2026-08-21 11:20:09 +08:00
vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), put: vi.fn() } }))
2026-08-20 09:10:36 +08:00
describe('last-mile order overseas API', () => {
beforeEach(() => vi.mocked(overseasHttp.get).mockReset())
2026-08-21 11:20:09 +08:00
it('loads all platform orders without a customer scope', async () => {
2026-08-20 09:10:36 +08:00
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: { records: [], page: 2, size: 20, total: 0, pages: 0 } })
2026-08-21 11:20:09 +08:00
await expect(listLastMileOrders({ page: 2, size: 20, status: 'PENDING_ASSIGNMENT' })).resolves.toMatchObject({ page: 2 })
2026-08-20 09:10:36 +08:00
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/orders', {
2026-08-21 11:20:09 +08:00
params: { page: 2, size: 20, status: 'PENDING_ASSIGNMENT' },
2026-08-20 09:10:36 +08:00
})
})
it('preserves a long order id as a string in the detail path', async () => {
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: { order: { id: '190000000000000099' }, cargo: [], statusHistory: [] } })
2026-08-21 11:20:09 +08:00
await getLastMileOrder('190000000000000099')
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/orders/190000000000000099')
2026-08-20 09:10:36 +08:00
})
it('does not call outbound or delivery endpoints', () => {
const source = `${listLastMileOrders}${getLastMileOrder}`
expect(source).not.toMatch(/outbound|delivery|dispatch/)
})
2026-08-21 11:20:09 +08:00
it('uses the real destination transfer endpoint and edit contract', async () => {
vi.mocked(overseasHttp.put).mockResolvedValue({ code: '200', message: 'success', data: 1 })
await transferLastMileOrders({
orderIds: ['190000000000000099'], warehouseId: 'WH-1', warehouseCode: 'ONT8', warehouseName: 'Ontario',
})
expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/last-leg/orders/destination', expect.objectContaining({ orderIds: ['190000000000000099'] }))
})
2026-08-20 09:10:36 +08:00
})