Files
baiyue-firstleg/scripts/admin-test-env-modules/phase3-order-splitting-contract.test.mjs
T

58 lines
3.4 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
const source = readFileSync(new URL('./phase3-order-splitting.mjs', import.meta.url), 'utf8')
test('each remainder uses a simulation explicitly linked to a confirmed booking', () => {
assert.match(source, /POST', CONTAINERS/)
assert.match(source, /POST', '\/api\/platform\/v1\/ocean-bookings'/)
assert.match(source, /ocean-bookings\/\$\{oceanBookingId\}\/submit/)
assert.match(source, /ocean-bookings\/\$\{oceanBookingId\}\/confirm/)
assert.match(source, /ocean-booking-link/)
assert.match(source, /candidates\?bookingId=\$\{encodeURIComponent\(containerId\)\}&warehouseId=\$\{encodeURIComponent\(warehouseId\)\}/)
assert.match(source, /`\$\{SMART\}\/plans`, \{ bookingId: containerId/)
assert.doesNotMatch(source, /candidates\?warehouseId=/)
})
test('PDA opens only after a real container number and uses stable plan identity', () => {
const pushIndex = source.indexOf("`${SMART}/plans/${planId}/push-preload`")
const transportIndex = source.indexOf("`${CONTAINERS}/${encodeURIComponent(containerId)}/transport`")
const taskIndex = source.indexOf("`${PDA}/tasks?loadingPlanId=${encodeURIComponent(planId)}&warehouseId=${encodeURIComponent(warehouseId)}`")
assert.ok(pushIndex >= 0 && transportIndex > pushIndex && taskIndex > transportIndex)
assert.match(source, /containerNo: realContainerNo/)
assert.match(source, /id\(task\?\.loadingPlanId\) === planId/)
assert.match(source, /id\(task\?\.containerBookingId\) === containerId/)
assert.doesNotMatch(source, /\$\{PDA\}\/tasks\?containerNo=/)
})
test('each remainder settles only through inventory snapshot, atomic batch and explicit complete', () => {
const claimIndex = source.indexOf("`${PDA}/tasks/${taskId}/claim`")
const snapshotIndex = source.indexOf('inventory-snapshot?warehouseId=')
const batchIndex = source.indexOf('const batchPath = `${PDA}/tasks/${taskId}/batch`')
const completeIndex = source.indexOf('const completePath = `${PDA}/tasks/${taskId}/complete`')
const treeIndex = source.indexOf('`回查 ${sourceOrderNo} 拆分后的根聚合`')
assert.ok(claimIndex >= 0 && snapshotIndex > claimIndex && batchIndex > snapshotIndex
&& completeIndex > batchIndex && treeIndex > completeIndex)
assert.match(source, /loadingPlanId: planId, containerBookingId: containerId/)
assert.match(source, /expectedVersion: Number\(inventory\.taskVersion\)/)
assert.match(source, /inventorySnapshotToken: inventory\.snapshotToken/)
assert.match(source, /action: 'PICK', pickedPackageCount: 1/)
assert.match(source, /version: Number\(claimedItem\.version\), releaseMode: 'MANUAL', locationIds: \[\]/)
assert.match(source, /'Idempotency-Key': batchKey/)
assert.match(source, /differentReplay/)
assert.match(source, /workflowStatus === 'AWAITING_REVIEW'/)
assert.match(source, /expectedTaskVersion: Number\(picked\?\.version\)/)
assert.match(source, /operationId: `\$\{operationBase\}-complete`/)
assert.match(source, /completeReplay/)
assert.match(source, /workflowStatus === 'COMPLETED'/)
assert.doesNotMatch(source, /\/items\/\$\{[^}]+\}\/pick/)
})
test('booking freezes the source customer channel and warehouse scope', () => {
assert.match(source, /customerId: source\.tenantId/)
assert.match(source, /channelCode: source\.channelCode/)
assert.match(source, /warehouseId: source\.warehouseId/)
assert.match(source, /containerRequirements: \[\{ containerType: '40HQ'/)
})