Files
baiyue-firstleg/scripts/admin-test-env-modules/inbound-hold-contract.test.mjs
T

63 lines
3.5 KiB
JavaScript
Raw Normal View History

2026-09-07 11:20:10 +08:00
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { test } from 'node:test'
const entry = readFileSync(new URL('../admin-test-env-acceptance.mjs', import.meta.url), 'utf8')
const source = readFileSync(new URL('./inbound-hold.mjs', import.meta.url), 'utf8')
test('入库扣货真实 HTTP 模块进入默认全量并依赖订单造数', () => {
assert.match(entry, /CONFIGURED_MODULES\s*=\s*\[[^\n]*['"]orders['"][^\n]*['"]inbound-hold['"]/)
assert.match(entry, /\[['"]inbound-hold['"],\s*\[['"]orders['"]\]\]/)
})
test('入库扣货模块覆盖隔离、幂等、冲突、候选门禁和统一订单投影', () => {
2026-09-07 11:22:57 +08:00
assert.match(source, /context\.createdResources\.orders/)
assert.match(source, /fixture\.orderNo/)
assert.match(source, /初始入库单允许扣货/)
2026-09-07 11:20:10 +08:00
assert.match(source, /错误客户不能读取扣货快照/)
assert.match(source, /扣货请求同键同载荷重放/)
assert.match(source, /扣货同键异载荷返回A0409/)
assert.match(source, /扣货入库单从智能装柜候选排除/)
assert.match(source, /解除后入库单恢复智能装柜候选/)
2026-09-07 11:22:57 +08:00
assert.match(source, /统一订单列表同步展示扣货字段/)
assert.match(source, /统一订单列表同步恢复扣货字段/)
2026-09-07 12:10:11 +08:00
assert.match(source, /扣货缺少幂等键返回A0400/)
assert.match(source, /扣货空白原因返回A0422/)
assert.match(source, /扣货超长原因返回A0422/)
assert.match(source, /扣货负版本返回A0422/)
assert.match(source, /扣货无效凭证ID返回A0422/)
assert.match(source, /错误客户不能执行扣货/)
assert.match(source, /已扣货时使用新键再次扣货返回A0409/)
assert.match(source, /未扣货时使用新键再次解除返回A0409/)
assert.match(source, /上传本轮扣货关联凭证/)
assert.match(source, /尚未进入不可变历史的凭证禁止下载/)
assert.match(source, /进入不可变历史后的扣货凭证可下载且内容一致/)
2026-09-07 12:16:19 +08:00
assert.match(source, /同版本并发扣货恰好一个成功一个冲突/)
assert.match(source, /并发验收最终恢复未扣货且历史完整/)
2026-09-07 11:20:10 +08:00
assert.match(source, /summary\?\.holdFlag/)
assert.match(source, /summary\?\.currentHoldReason/)
assert.doesNotMatch(source, /\.holdCargo\b|\.holdReason\b|\bholdCargo\s*:|\bholdReason\s*:/)
})
2026-09-07 11:22:57 +08:00
test('入库扣货冲突和重放均回查版本及不可变历史零漂移', () => {
assert.match(source, /historyFacts\(replayed\) === heldHistoryFacts/)
assert.match(source, /扣货冲突后版本、原因和历史零漂移/)
assert.match(source, /解除后既有扣货历史身份和内容保持不可变/)
assert.match(source, /historyFactsFrom\(historyRows\(released\)\.slice\(1\)\) === heldHistoryFacts/)
assert.match(source, /historyFacts\(releaseReplay\) === releasedHistoryFacts/)
assert.match(source, /过期版本冲突后解除快照和不可变历史零漂移/)
})
2026-09-07 11:20:10 +08:00
test('入库扣货写操作统一使用请求头 Idempotency-Key 和 expectedVersion', () => {
assert.match(source, /context\.request\('POST', path, body, context\.token, \{ 'Idempotency-Key': key \}\)/)
assert.match(source, /expectedVersion: initialVersion/)
assert.match(source, /expectedVersion: heldVersion/)
2026-09-07 11:22:57 +08:00
assert.match(source, /inbound-hold-stale/)
})
test('入库扣货模块只消费本轮 marker 造数且不读取历史资源或环境凭据', () => {
assert.match(source, /context\.marker/)
assert.match(source, /inboundCode=\$\{encodeURIComponent\(inboundCode\)\}/)
assert.doesNotMatch(source, /process\.env|ADMIN_TEST_|MERCHANT_TEST_|history fixture|historical/i)
2026-09-07 11:20:10 +08:00
})