Files
baiyue-firstleg/scripts/admin-test-env-modules/orders-lifecycle-idempotency-contract.test.mjs
T

49 lines
2.7 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { orderPersistenceFacts, requestedOrderDestinationType } from './orders.mjs'
const source = readFileSync(new URL('orders.mjs', import.meta.url), 'utf8')
test('order demo payload covers multi-box multi-SKU images and both destination families', () => {
for (const boxType of ['SMALL', 'MEDIUM', 'LARGE', 'EXTRA_LARGE']) {
assert.match(source, new RegExp(`boxType: '${boxType}'`))
}
assert.match(source, /cargoes: selectedBoxes\.map/)
assert.match(source, /productImageFileId/)
assert.equal(requestedOrderDestinationType({ context: { orderDestinationType: 'FBA' } }), 'FBA')
assert.equal(requestedOrderDestinationType({ context: { orderDestinationType: 'OVERSEAS' } }), 'OVERSEAS')
})
test('create and submit lifecycle covers replay payload conflict and zero drift', () => {
assert.match(source, /Client 创建订单幂等重放/)
assert.match(source, /Client 创建订单同键异载荷返回A0409/)
assert.match(source, /创建同键异载荷失败后订单全事实零漂移/)
assert.match(source, /Client 提交订单同键同载荷精确重放/)
assert.match(source, /已提交订单使用新键重复提交返回A0409/)
assert.match(source, /重复提交失败后订单状态货物与历史零漂移/)
assert.match(source, /orderPersistenceFacts\(draftAfterConflict\) === orderPersistenceFacts\(draft\)/)
assert.match(source, /orderPersistenceFacts\(submittedAfterFailure\) === orderPersistenceFacts\(submitted\)/)
})
test('persistence fact comparison includes order cargo parties notes and history', () => {
const detail = {
order: { id: '1', status: 'DRAFT' }, cargoes: [{ skuNo: 'SKU-1' }],
parties: [{ role: 'SENDER' }], internalNotes: [{ content: 'note' }],
statusHistory: [{ toStatus: 'DRAFT' }],
}
const baseline = orderPersistenceFacts(detail)
assert.equal(orderPersistenceFacts(structuredClone(detail)), baseline)
assert.notEqual(orderPersistenceFacts({ ...detail, order: { ...detail.order, status: 'SUBMITTED' } }), baseline)
assert.notEqual(orderPersistenceFacts({ ...detail, cargoes: [{ skuNo: 'SKU-2' }] }), baseline)
assert.notEqual(orderPersistenceFacts({ ...detail, statusHistory: [...detail.statusHistory, { toStatus: 'SUBMITTED' }] }), baseline)
})
test('approval convergence is a hard WAIT_MEASURE prerequisite without coverage downgrade', () => {
assert.match(source, /审核后入库单与履约任务异步收敛/)
assert.match(source, /MEASURABLE_STATUSES/)
assert.match(source, /throw new Error\('订单审核后的入库单与履约任务未在30秒内收敛/)
assert.doesNotMatch(source, /审核后入库单与履约任务异步收敛[\s\S]{0,300}addCoverageGap/)
})