fix(procurement): normalize integer wire fields before commands
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
updateUsTruckOrder,
|
||||
} from './platformOverseasBusiness'
|
||||
import type { UpdateLocalTransportOrderRequest } from '../types'
|
||||
import { readPendingProcurement } from '../procurementPending'
|
||||
|
||||
const envelope = <T>(data: T) => ({ code: '200', message: 'success', data })
|
||||
const purchaseSummary = {
|
||||
@@ -34,6 +35,29 @@ const looseboardSummary = {
|
||||
describe('platform overseas business API adapter', () => {
|
||||
beforeEach(() => vi.clearAllMocks())
|
||||
|
||||
it('normalizes wire integer strings before building replayable procurement commands', async () => {
|
||||
overseas.get.mockResolvedValue(envelope({
|
||||
customerView: { order: { ...purchaseSummary, version: '0', purchaseQuantity: '1' }, boxes: [{ quantity: '1' }], shipments: [{ quantity: '1' }], fees: [{ version: '2' }] },
|
||||
purchaseFacts: { purchased_quantity: '1' }, physical: { packingVersion: '3', dispositions: [{ id: '901', quantity: '1' }], receipts: [{ id: '902', goodQuantity: '1', damagedQuantity: '0', extraQuantity: '0' }], cartons: [{ id: '903', quantity: '1', sources: [{ receiptId: '902', quantity: '1' }] }] },
|
||||
fees: [{ id: '904', feeVersion: '2' }], controls: { notes: [], remaining: [{ quantity: '1' }], closures: [], closureItems: [{ quantity: '1' }] }, files: [{ id: '905', fileId: '9007199254740995', sizeBytes: '123' }],
|
||||
transport: { overseasCargo: [{ cartonId: '903', quantity: '1', sources: [{ receiptId: '902', quantity: '1' }] }], domesticCargo: [], overseasLabels: { id: '906', manifestId: '907', version: '4', labels: [{ cartonId: '903', fileId: '9007199254740995', page: '1' }] }, domesticLabels: null, shipments: [] },
|
||||
}))
|
||||
const detail = await getOverseasPurchase('OP-1', '10001')
|
||||
const payload = { version: detail.customerView.order.version, idempotencyKey: 'review-wire', decision: 'APPROVE', purchaseWarehouseId: '9007199254740995' }
|
||||
expect(() => readPendingProcurement(JSON.stringify({ command: 'review', payload }))).not.toThrow()
|
||||
expect(detail.customerView.order.purchaseQuantity).toBe(1)
|
||||
expect(detail.physical.receipts[0].goodQuantity + detail.physical.receipts[0].damagedQuantity).toBe(1)
|
||||
expect(detail.physical.packingVersion).toBe(3)
|
||||
expect(detail.physical.cartons[0].sources[0].quantity).toBe(1)
|
||||
expect(detail.transport.overseasCargo[0].quantity).toBe(1)
|
||||
expect(detail.transport.overseasLabels?.version).toBe(4)
|
||||
expect(detail.transport.overseasLabels?.labels[0].page).toBe(1)
|
||||
expect(detail.files[0]).toMatchObject({ fileId: '9007199254740995', sizeBytes: 123 })
|
||||
expect(detail.fees[0].feeVersion).toBe(2)
|
||||
expect(detail.controls.remaining[0].quantity).toBe(1)
|
||||
expect(detail.controls.closureItems[0].quantity).toBe(1)
|
||||
})
|
||||
|
||||
it('loads procurement candidates and normalizes procurement pages', async () => {
|
||||
overseas.get
|
||||
.mockResolvedValueOnce(envelope([{ customerId: '10001', customerName: '客户一' }]))
|
||||
@@ -49,7 +73,7 @@ describe('platform overseas business API adapter', () => {
|
||||
|
||||
it('loads and patches procurement detail with three-state null payloads', async () => {
|
||||
const detail = { summary: purchaseSummary, productUrl: null, histories: [{ operationType: 'UPDATE', fromStatus: 'WAIT_PURCHASE', toStatus: 'WAIT_PURCHASE', operatorId: '7', changeDetail: '{}', remark: null, createdAt: '2026-08-02T00:00:00' }] }
|
||||
overseas.get.mockResolvedValue(envelope({ customerView: { order: purchaseSummary }, reviewHistory: detail.histories, physical: { dispositions: [], receipts: [], cartons: [] }, fees: [], feeCorrections: [], controls: { notes: [], remaining: [], closures: [], closureItems: [] }, files: [], transport: { overseasCargo: [], domesticCargo: [], overseasLabels: null, domesticLabels: null, shipments: [] } }))
|
||||
overseas.get.mockResolvedValue(envelope({ customerView: { order: purchaseSummary, boxes: [], shipments: [], fees: [] }, reviewHistory: detail.histories, physical: { dispositions: [], receipts: [], cartons: [] }, fees: [], feeCorrections: [], controls: { notes: [], remaining: [], closures: [], closureItems: [] }, files: [], transport: { overseasCargo: [], domesticCargo: [], overseasLabels: null, domesticLabels: null, shipments: [] } }))
|
||||
expect((await getOverseasPurchase('OP/1', '10001')).reviewHistory[0]?.operationType).toBe('UPDATE')
|
||||
overseas.patch.mockResolvedValue(envelope(detail))
|
||||
const payload = { version: 4, remark: null }
|
||||
|
||||
Reference in New Issue
Block a user