Files
baiyue-firstleg/scripts/admin-test-env-modules/dropship-mixed-palletization-contract.test.mjs
2026-10-22 11:56:47 +08:00

39 lines
2.2 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { run } from './dropship-mixed-palletization.mjs'
test('single fixed customer blocks before first order or measurement', async () => {
await assert.rejects(run({ options: { fixedCustomerId: '123' } }), /停止下单和测量造数/)
})
const source = readFileSync(new URL('./dropship-mixed-palletization.mjs', import.meta.url), 'utf8')
const orders = readFileSync(new URL('./orders.mjs', import.meta.url), 'utf8')
test('mixed pallet acceptance uses formal producers and fails on any failed preparation assertion', () => {
assert.match(source, /await createOrder\(context\)/)
assert.match(source, /await measure\(context\)/)
assert.match(source, /!context.steps.slice\(start\).some\(\(step\) => !step.passed\)/)
assert.match(source, /if \(!passed\) throw new Error/)
assert.match(source, /context.context.allowAnyExistingPallet = true/)
})
test('retained manual fixtures cover same and different customers and remain visible and unclaimed', () => {
assert.match(source, /\[2, 1, 2, 3\].entries\(\)/)
assert.match(source, /index < 3 \? savedContext.merchantQualificationFixture : secondCustomer/)
assert.match(source, /index < 2 \? 'SAME_CUSTOMER' : 'CROSS_CUSTOMER'/)
assert.match(source, /mainStatus=WAIT_PALLETIZE&inboundCode=/)
assert.match(source, /task.taskStatus === 'PENDING' && task.countedCartons === 0 && task.boundCartons === 0/)
assert.match(source, /result.manualStage = 'WAIT_PALLETIZE_VISIBLE'/)
})
test('explicit order producer scope preserves approval convergence and default declaration acceptance', () => {
const branch = orders.indexOf('if (context.context.orderFixtureOnly === true)')
assert.ok(branch > orders.indexOf('const inboundResult = await waitForInbound'))
assert.ok(branch > orders.indexOf('await verifyOrderApprovalReplay(context'))
assert.ok(branch < orders.indexOf('const editableDetailResponse'))
assert.match(orders.slice(branch, orders.indexOf('const editableDetailResponse')), /await finishOrderLifecycle\(context/)
assert.match(orders, /申报修改保持订单号入仓码和渠道且版本递增/)
assert.match(orders, /申报修改异步同步到Firstleg入库事实/)
})