Files
baiyue-firstleg/scripts/admin-test-env-modules/phase4-overseas-dispatch-contract.test.mjs
T

52 lines
2.7 KiB
JavaScript
Raw Normal View History

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
const moduleUrl = new URL('./phase4-overseas-dispatch.mjs', import.meta.url)
const source = await readFile(fileURLToPath(moduleUrl), 'utf8')
test('phase4 overseas dispatch module freezes only stable platform query and smart pre-arrange paths', () => {
for (const token of [
"const BASE = '/api/platform/v1/last-leg/dispatches'",
"query(BASE, { page: 1, size: 20 })",
'`${BASE}/candidates`', '`${BASE}/drafts`', '`${BASE}/drafts/snapshot`',
'`${BASE}/draft-locks/lock`', '`${BASE}/pre-arrange`', '`${BASE}/draft-locks/release`',
'`${BASE}/${encodeURIComponent(dispatchNo)}`',
]) assert.match(source, new RegExp(token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')))
for (const forbidden of ['/api/pda/', '/outbound', '/delivery', '/depart', '/cancel']) {
assert.equal(source.includes(forbidden), false, `must exclude ${forbidden}`)
}
})
test('module uses marker-owned completed PDA pallets and never borrows historical candidates', () => {
assert.match(source, /fixture\?\.marker !== context\.marker/)
assert.match(source, /fixture\?\.finalStatus !== 'COMPLETED'/)
assert.match(source, /fixture\.palletIds\.has\(id\(value\?\.warehousePalletId\)\)/)
assert.match(source, /id\(value\?\.overseasWarehouseId\) === id\(fixture\.overseasWarehouseId\)/)
assert.doesNotMatch(source, /candidates\[0\]/)
})
test('module proves draft idempotency, lock isolation, stale replay conflict and readback', () => {
assert.match(source, /相同草稿快照重复保存/)
assert.match(source, /同草稿重复锁定托盘幂等成功/)
assert.match(source, /其他草稿锁定同一托盘返回A0409/)
assert.match(source, /已转换正式锁的旧草稿载荷再次预排返回A0409/)
assert.match(source, /重复释放草稿幂等成功/)
assert.match(source, /排车详情按记录自身客户范围加载托盘明细/)
assert.match(source, /response\?\.http === 409.*codeOf\(response\) === 'A0409'/s)
})
test('module does not invent optimistic version or idempotency headers absent from DispatchRequests', () => {
assert.doesNotMatch(source, /expectedVersion|recordVersion|Idempotency-Key/)
assert.match(source, /PENDING_DEPARTURE/)
assert.match(source, /data == null/)
})
test('module records the marker-owned dispatch without attempting excluded cleanup actions', () => {
assert.match(source, /createdResources\.phase4OverseasDispatch/)
assert.match(source, /dispatchNo = dispatchNo/)
assert.match(source, /finalStatus = arranged\.data\?\.status/)
assert.match(source, /PENDING_DEPARTURE dispatch is retained as marker-owned acceptance evidence/)
})