2026-08-06 13:56:04 +08:00
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import { http } from '@/shared/api/http'
|
2026-08-06 18:02:04 +08:00
|
|
|
import {
|
|
|
|
|
approvePlatformUnifiedOrder,
|
|
|
|
|
assignPlatformUnifiedOrderCarrier,
|
|
|
|
|
getPlatformUnifiedOrder,
|
|
|
|
|
listPlatformUnifiedOrders,
|
|
|
|
|
} from './unifiedOrders'
|
2026-08-06 13:56:04 +08:00
|
|
|
|
|
|
|
|
vi.mock('@/shared/api/http', () => ({
|
2026-08-06 18:02:04 +08:00
|
|
|
http: { get: vi.fn(), post: vi.fn(), put: vi.fn() },
|
2026-08-06 13:56:04 +08:00
|
|
|
unwrapApiResponse: <T>(response: { data: T }) => response.data,
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
describe('unified orders API contract', () => {
|
2026-08-06 18:02:04 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.mocked(http.get).mockReset()
|
|
|
|
|
vi.mocked(http.post).mockReset()
|
|
|
|
|
vi.mocked(http.put).mockReset()
|
|
|
|
|
})
|
2026-08-06 13:56:04 +08:00
|
|
|
|
|
|
|
|
it('uses the C02 platform orders endpoint and contract filters', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({ data: { records: [], page: '2', size: '20', total: '0', pages: '0' } })
|
|
|
|
|
await expect(listPlatformUnifiedOrders({
|
|
|
|
|
keyword: 'CC', orderNo: 'CC-1', mainStatus: 'WAIT_SPLIT', customerId: '30001',
|
2026-08-06 15:32:02 +08:00
|
|
|
receivingWarehouseId: '11', destinationWarehouseId: '22', inboundCode: 'RK-1', internalOrderStatus: 'ACCEPTED',
|
|
|
|
|
expectedArrivalDate: '2026-08-10', feeReviewStatus: 'APPROVED', channelName: '海运', containerNo: 'CONT-1',
|
|
|
|
|
cabinetNo: 'CAB-1', sailingDate: '2026-08-12', loaded: true, fullContainer: false,
|
|
|
|
|
measurementReviewStatus: 'PENDING', fbaCode: 'FBA-1', createdFrom: '2026-08-01T00:00:00',
|
|
|
|
|
createdTo: '2026-08-31T23:59:59', page: 2, size: 20,
|
2026-08-06 13:56:04 +08:00
|
|
|
})).resolves.toMatchObject({ page: 2, size: 20, total: 0, pages: 0 })
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/orders', {
|
|
|
|
|
params: {
|
|
|
|
|
keyword: 'CC', orderNo: 'CC-1', mainStatus: 'WAIT_SPLIT', customerId: '30001',
|
2026-08-06 15:32:02 +08:00
|
|
|
receivingWarehouseId: '11', destinationWarehouseId: '22', inboundCode: 'RK-1', internalOrderStatus: 'ACCEPTED',
|
|
|
|
|
expectedArrivalDate: '2026-08-10', feeReviewStatus: 'APPROVED', channelName: '海运', containerNo: 'CONT-1',
|
|
|
|
|
cabinetNo: 'CAB-1', sailingDate: '2026-08-12', loaded: true, fullContainer: false,
|
|
|
|
|
measurementReviewStatus: 'PENDING', fbaCode: 'FBA-1', createdFrom: '2026-08-01T00:00:00',
|
|
|
|
|
createdTo: '2026-08-31T23:59:59', page: 2, size: 20,
|
2026-08-06 13:56:04 +08:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-06 15:32:02 +08:00
|
|
|
it('omits empty optional filters while preserving false boolean values', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({ data: { records: [], page: 1, size: 20, total: 0, pages: 0 } })
|
|
|
|
|
await listPlatformUnifiedOrders({ keyword: '', loaded: false, fullContainer: false, page: 1, size: 20 })
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/orders', {
|
|
|
|
|
params: { loaded: false, fullContainer: false, page: 1, size: 20 },
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-06 13:56:04 +08:00
|
|
|
it('normalizes C02 row IDs and keeps inboundId for measurement routing', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({ data: {
|
|
|
|
|
records: [{ orderId: '90001', tenantId: '208', inboundId: '77', inboundVersion: 3, mainStatus: 'WAIT_MEASURE', measurement: null, preload: null, loading: null, delivery: null, transport: null }],
|
|
|
|
|
page: 1, size: 20, total: 1, pages: 1,
|
|
|
|
|
} })
|
|
|
|
|
await expect(listPlatformUnifiedOrders({ page: 1, size: 20 })).resolves.toMatchObject({
|
|
|
|
|
records: [{ orderId: '90001', tenantId: '208', inboundId: '77', inboundVersion: 3 }],
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('loads the C02 detail shape and passes tenantId only on the detail boundary', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({ data: {
|
|
|
|
|
summary: { orderId: '90001', tenantId: '208', mainStatus: 'WAIT_SPLIT' },
|
|
|
|
|
order: { order: {}, cargoes: [], parties: [], internalNotes: [], statusHistory: [] },
|
|
|
|
|
timeline: [],
|
|
|
|
|
} })
|
|
|
|
|
await expect(getPlatformUnifiedOrder('208', '90001')).resolves.toMatchObject({
|
|
|
|
|
summary: { orderId: '90001' }, order: { internalNotes: [] }, timeline: [],
|
|
|
|
|
})
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/orders/90001', { params: { tenantId: '208' } })
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-06 18:02:04 +08:00
|
|
|
it('uses the explicit first-leg carrier and approval boundaries for pending review', async () => {
|
|
|
|
|
vi.mocked(http.put).mockResolvedValue({ data: null })
|
|
|
|
|
vi.mocked(http.post).mockResolvedValue({ data: null })
|
|
|
|
|
|
|
|
|
|
await assignPlatformUnifiedOrderCarrier('208', '90001', '30001')
|
|
|
|
|
await approvePlatformUnifiedOrder('208', '90001')
|
|
|
|
|
|
|
|
|
|
expect(http.put).toHaveBeenCalledWith('/platform/v1/orders/first-leg/90001/carrier', { carrierId: '30001' }, { params: { tenantId: '208' } })
|
|
|
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/orders/first-leg/90001/approve', undefined, { params: { tenantId: '208' } })
|
2026-08-06 13:56:04 +08:00
|
|
|
})
|
|
|
|
|
})
|