49 lines
2.4 KiB
TypeScript
49 lines
2.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { formatOverseasDateTime, toLastMileOrderListItem } from './lastMilePresentation'
|
|
|
|
describe('last-mile order presentation adapter', () => {
|
|
it('maps backend codes, associations and long ids without inventing data', () => {
|
|
const row = toLastMileOrderListItem({
|
|
id: '190000000000000099', customerId: '190000000000000001', orderNo: 'LL-001', orderType: 'ONE_CLICK_DROPSHIP', currentStatus: 'PENDING_ASSIGNMENT',
|
|
abnormal: true, detained: false, packageCount: 12, deliveryOrderNo: 'DEL-READ-ONLY', outboundOrderNo: 'OUT-READ-ONLY',
|
|
})
|
|
expect(row).toMatchObject({
|
|
id: '190000000000000099', customerId: '190000000000000001', orderType: '一件代发', status: '待分配',
|
|
warning: '异常', abnormal: '是', held: '否', cartons: 12, dispatchOrderNo: 'DEL-READ-ONLY', outboundOrderNo: 'OUT-READ-ONLY',
|
|
})
|
|
expect(row.rejectedAt).toBe('—')
|
|
})
|
|
|
|
it('shows the backend customerName and never guesses the owner from customerId', () => {
|
|
expect(toLastMileOrderListItem({
|
|
id: '1', customerId: '190000000000000001', customerName: '华远贸易', orderNo: 'LMO-260827-0001',
|
|
}).owner).toBe('华远贸易')
|
|
expect(toLastMileOrderListItem({
|
|
id: '2', customerId: '190000000000000002', customerName: null, orderNo: 'LMO-260827-0002',
|
|
}).owner).toBe('—')
|
|
})
|
|
|
|
it('preserves real metrics and distinguishes zero from unknown fields and times', () => {
|
|
const estimatedArrivalAt = '2026-08-27T12:30:00Z'
|
|
const row = toLastMileOrderListItem({
|
|
id: '3', customerId: '190000000000000003', orderNo: 'LMO-260827-0003',
|
|
palletCount: 3, packageCount: 0, volumeCbm: 12.75, productQuantity: null, volumeWeightKg: 88.6,
|
|
estimatedArrivalAt, actualArrivalAt: null, estimatedWarehouseAt: null,
|
|
})
|
|
expect(row).toMatchObject({
|
|
pallets: 3, cartons: 0, volume: 12.75, quantity: '—', volumeWeight: 88.6,
|
|
portEta: formatOverseasDateTime(estimatedArrivalAt), portAta: '—', warehouseEta: '—',
|
|
})
|
|
})
|
|
|
|
it.each([
|
|
['RELABEL_APPLICATION', '换标下单'],
|
|
['WAREHOUSE_TRANSFER', '仓储转运'],
|
|
['RETURN_RELABEL', '退货换标'],
|
|
['LOCAL_LOOSEBOARD', '本土散板'],
|
|
])('maps %s to its Chinese display name', (orderType, expected) => {
|
|
const row = toLastMileOrderListItem({ id: '1', customerId: '100', orderNo: 'LL-1', orderType })
|
|
expect(row.orderType).toBe(expected)
|
|
})
|
|
})
|