2026-08-20 09:10:36 +08:00
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import { overseasHttp } from '@/shared/api/overseasHttp'
|
2026-09-01 10:18:48 +08:00
|
|
|
import { convertLastMileContainerToInboundPlans, convertLastMileOrderToInboundPlan, downloadLastMileOrders, getContainerPlanProgress, getLastMileOrder, listContainerPlanProgress, listLastMileOrders, transferLastMileOrders } from './lastMileOrders'
|
2026-08-20 09:10:36 +08:00
|
|
|
|
2026-08-21 17:20:40 +08:00
|
|
|
vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), put: vi.fn(), post: vi.fn() } }))
|
2026-08-20 09:10:36 +08:00
|
|
|
|
|
|
|
|
describe('last-mile order overseas API', () => {
|
2026-08-27 17:16:38 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.mocked(overseasHttp.get).mockReset()
|
|
|
|
|
vi.mocked(overseasHttp.put).mockReset()
|
|
|
|
|
vi.mocked(overseasHttp.post).mockReset()
|
|
|
|
|
})
|
2026-08-20 09:10:36 +08:00
|
|
|
|
2026-08-21 11:20:09 +08:00
|
|
|
it('loads all platform orders without a customer scope', async () => {
|
2026-08-27 16:34:32 +08:00
|
|
|
const record = { id: '190000000000000099', customerId: '190000000000000001', sourceContainerBookingId: '190000000000000088', customerName: '华远贸易', orderNo: 'LMO-260827-0001' }
|
2026-08-27 15:56:13 +08:00
|
|
|
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: { records: [record], page: '2', size: '20', total: '1', pages: '1' } })
|
|
|
|
|
await expect(listLastMileOrders({ page: 2, size: 20, orderType: 'FIRST_LEG', currentStatus: 'PENDING_ASSIGNMENT', warehouse: 'LAX' })).resolves.toEqual({ records: [record], page: 2, size: 20, total: 1, pages: 1 })
|
2026-08-20 09:10:36 +08:00
|
|
|
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/orders', {
|
2026-08-21 17:20:40 +08:00
|
|
|
params: { page: 2, size: 20, orderType: 'FIRST_LEG', currentStatus: 'PENDING_ASSIGNMENT', warehouse: 'LAX' },
|
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
|
|
|
|
2026-08-21 17:20:40 +08:00
|
|
|
it('passes all supported list filters and pagination without customerId', async () => {
|
|
|
|
|
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: { records: [], page: 2, size: 50, total: 0, pages: 0 } })
|
|
|
|
|
await listLastMileOrders({
|
|
|
|
|
page: 2, size: 50, orderNo: 'LM-1', inboundCode: 'IN-1', sourceOrderNo: 'SRC-1',
|
|
|
|
|
containerNo: 'CONT-1', status: 'PENDING_DELIVERY', transferWarehouseCode: 'ONT8',
|
|
|
|
|
abnormal: true, detained: false, createdFrom: '2026-08-01T00:00:00', createdTo: '2026-08-31T23:59:59',
|
|
|
|
|
})
|
|
|
|
|
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/orders', {
|
|
|
|
|
params: expect.objectContaining({ page: 2, size: 50, sourceOrderNo: 'SRC-1', transferWarehouseCode: 'ONT8', abnormal: true, detained: false }),
|
|
|
|
|
})
|
|
|
|
|
expect(JSON.stringify(vi.mocked(overseasHttp.get).mock.calls[0]?.[1])).not.toContain('customerId')
|
|
|
|
|
})
|
|
|
|
|
|
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-21 17:20:40 +08:00
|
|
|
|
2026-08-31 14:42:28 +08:00
|
|
|
it('returns the exported CSV blob without reading data twice', async () => {
|
|
|
|
|
const blob = new Blob(['orders'], { type: 'text/csv' })
|
|
|
|
|
vi.mocked(overseasHttp.get).mockResolvedValue(blob)
|
|
|
|
|
|
|
|
|
|
await expect(downloadLastMileOrders({ orderNo: 'LM-1' })).resolves.toBe(blob)
|
|
|
|
|
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/orders/export', {
|
|
|
|
|
params: { orderNo: 'LM-1' }, responseType: 'blob',
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('exports all authorized orders without pagination or empty filters', async () => {
|
|
|
|
|
const blob = new Blob(['orders'], { type: 'text/csv' })
|
|
|
|
|
vi.mocked(overseasHttp.get).mockResolvedValue(blob)
|
|
|
|
|
|
|
|
|
|
await downloadLastMileOrders({ page: 1, size: 10, orderNo: '', createdFrom: undefined })
|
|
|
|
|
|
|
|
|
|
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/orders/export', {
|
|
|
|
|
params: {}, responseType: 'blob',
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('rejects a JSON business error instead of saving it as CSV', async () => {
|
|
|
|
|
const blob = new Blob([JSON.stringify({
|
|
|
|
|
code: 'S0500', message: '系统内部错误', data: null, requestId: 'req-1', traceId: 'trace-1',
|
|
|
|
|
})], { type: 'application/json' })
|
|
|
|
|
vi.mocked(overseasHttp.get).mockResolvedValue(blob)
|
|
|
|
|
|
|
|
|
|
await expect(downloadLastMileOrders({})).rejects.toMatchObject({
|
|
|
|
|
code: 'S0500', message: '系统内部错误', requestId: 'req-1', traceId: 'trace-1',
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-27 15:56:13 +08:00
|
|
|
it('uses the inbound-plan conversion endpoint with the exact selected customer scope', async () => {
|
2026-08-21 17:20:40 +08:00
|
|
|
vi.mocked(overseasHttp.post).mockResolvedValue({ code: '200', message: 'success', data: {} })
|
2026-08-27 15:56:13 +08:00
|
|
|
await convertLastMileOrderToInboundPlan({ orderId: '190000000000000099', customerId: '190000000000000001' })
|
|
|
|
|
expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/last-leg/inbound-plans/convert', {
|
|
|
|
|
orderId: '190000000000000099', customerId: '190000000000000001',
|
|
|
|
|
})
|
2026-08-21 17:20:40 +08:00
|
|
|
})
|
2026-08-27 16:34:32 +08:00
|
|
|
|
|
|
|
|
it('uses one atomic container request without looping individual conversions', async () => {
|
|
|
|
|
vi.mocked(overseasHttp.post).mockResolvedValue({ code: '200', message: 'success', data: [] })
|
|
|
|
|
await expect(convertLastMileContainerToInboundPlans({ sourceContainerBookingId: '2092873463568597001' })).resolves.toEqual([])
|
|
|
|
|
expect(overseasHttp.post).toHaveBeenCalledTimes(1)
|
|
|
|
|
expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/last-leg/inbound-plans/convert-container', {
|
|
|
|
|
sourceContainerBookingId: '2092873463568597001',
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-08-27 17:16:38 +08:00
|
|
|
|
2026-08-28 13:54:44 +08:00
|
|
|
it('loads server-side container progress with pagination and filters', async () => {
|
2026-08-27 17:16:38 +08:00
|
|
|
const record = {
|
2026-08-28 13:54:44 +08:00
|
|
|
sourceContainerBookingId: '2092873463568597001', containerNo: 'CONT-15', totalOrderCount: 15,
|
|
|
|
|
inboundCodeCount: 13, missingInboundCodeCount: 2, planCount: 10, plannedInboundCodeCount: 10,
|
|
|
|
|
pendingPlanCount: 5, plannedArrivalAt: '2026-09-01T08:00:00', allPlansReady: false, blockingReason: '存在2票缺少入仓码',
|
2026-08-27 17:16:38 +08:00
|
|
|
}
|
|
|
|
|
vi.mocked(overseasHttp.get).mockResolvedValue({
|
|
|
|
|
code: '200', message: 'success', data: { records: [record], page: '2', size: '10', total: '21', pages: '3' },
|
|
|
|
|
})
|
2026-08-28 13:54:44 +08:00
|
|
|
await expect(listContainerPlanProgress({
|
2026-08-27 17:16:38 +08:00
|
|
|
page: 2, size: 10, containerNo: 'CONT-15',
|
|
|
|
|
createdFrom: '2026-08-01T00:00:00', createdTo: '2026-08-31T23:59:59',
|
|
|
|
|
})).resolves.toEqual({ records: [record], page: 2, size: 10, total: 21, pages: 3 })
|
|
|
|
|
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/orders/container-summaries', {
|
|
|
|
|
params: {
|
|
|
|
|
page: 2, size: 10, containerNo: 'CONT-15',
|
|
|
|
|
createdFrom: '2026-08-01T00:00:00', createdTo: '2026-08-31T23:59:59',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-08-28 13:54:44 +08:00
|
|
|
|
|
|
|
|
it('loads one container detail with the encoded stable long id', async () => {
|
|
|
|
|
const detail = { summary: { sourceContainerBookingId: '2092873463568597001' }, orders: [] }
|
|
|
|
|
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: detail })
|
|
|
|
|
await expect(getContainerPlanProgress('2092873463568597001/unsafe')).resolves.toEqual(detail)
|
|
|
|
|
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/orders/container-summaries/2092873463568597001%2Funsafe')
|
2026-08-21 17:20:40 +08:00
|
|
|
})
|
2026-08-20 09:10:36 +08:00
|
|
|
})
|