Files
baiyue-firstleg/scripts/admin-test-env-modules/orders-approval-convergence-contract.test.mjs
T

45 lines
2.0 KiB
JavaScript
Raw Normal View History

2026-08-13 18:34:44 +08:00
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { approvedInboundReady } from './orders.mjs'
const tenantId = '10001'
const orderId = '20001'
const taskResponse = {
http: 200,
body: { code: '200', data: { id: '30001', tenantId, orderId } },
}
test('draft inbound id alone does not mean approval outbox has converged', () => {
assert.equal(approvedInboundReady({
summary: { inboundId: '40001', mainStatus: 'PREPARING' },
}, taskResponse, tenantId, orderId), false)
})
test('measurable inbound without fulfillment task remains pending', () => {
assert.equal(approvedInboundReady({
summary: { inboundId: '40001', mainStatus: 'WAIT_MEASURE' },
}, { http: 200, body: { code: 'A0404' } }, tenantId, orderId), false)
})
test('approval convergence requires matching inbound state, order and customer task identity', () => {
const detail = { summary: { inboundId: '40001', mainStatus: 'WAIT_MEASURE' } }
assert.equal(approvedInboundReady(detail, taskResponse, tenantId, orderId), true)
assert.equal(approvedInboundReady(detail, {
http: 200, body: { code: '200', data: { id: '30001', tenantId, orderId: '20002' } },
}, tenantId, orderId), false)
assert.equal(approvedInboundReady(detail, {
http: 200, body: { code: '200', data: { id: '30001', tenantId: '10002', orderId } },
}, tenantId, orderId), false)
})
test('orders acceptance polls approval convergence instead of only inbound id visibility', () => {
const source = readFileSync(new URL('orders.mjs', import.meta.url), 'utf8')
assert.match(source, /审核后入库单与履约任务异步收敛/)
assert.match(source, /approvedInboundReady\(candidate, taskResponse, tenantId, orderId\)/)
assert.match(source, /MEASURABLE_STATUSES\.has\(summary\?\.mainStatus\)/)
assert.doesNotMatch(source, /MEASURABLE_STATUSES\.has\(summary\?\.processStatus\)/)
assert.doesNotMatch(source, /if \(success\(response\) && response\.body\?\.data\?\.summary\?\.inboundId\)/)
})