This commit is contained in:
2026-10-08 17:07:57 +08:00
parent 16d2d9111a
commit c1ddb658bd
111 changed files with 2914 additions and 941 deletions
@@ -3,7 +3,92 @@ import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { createCompletedOrder, transition } from './order-inbound-status-fixtures.mjs'
import { createCompletedOrder, transition, retainFeeConfirmingFixture, retainWaitPricingFixture } from './order-inbound-status-fixtures.mjs'
test('待计费样本通过同维度真实渠道变更生成且退出独立会话', async () => {
const execute = async (override = {}) => {
const calls = []
let detailReads = 0
const order = { id: '9', version: 2, status: 'APPROVED', receivingWarehouseId: '10',
destinationWarehouseId: '11', amazonWarehouseCode: 'ABE4', destinationWarehouseName: 'ABE4',
destinationType: 'FBA', pricingTaxMode: 'TAX_INCLUDED', channelCode: 'OLD', customerRemark: 'current-run' }
const context = { marker: 'current-run', context: { merchantQualificationFixture: { username: 'fixture', password: 'fixture' } },
async request(method, url, body, token) {
calls.push({ method, url, body, token })
let data
if (url === '/api/platform/inbounds/8?tenantId=7') {
detailReads += 1
data = { summary: { id: '8', tenantId: '7', orderId: '9', inboundCode: 'IN-8',
processStatus: detailReads === 1 ? 'FEE_CONFIRMING' : 'WAIT_PRICING',
channelCode: 'NEW', feeStatus: 'UNPRICED', ...(detailReads === 1 ? override.before : override.after) } }
} else if (url.includes('/orders/first-leg/9')) data = { order: { ...order, ...override.order }, cargoes: [{ itemNo: 1 }] }
else if (url === '/api/auth/login') data = { accessToken: 'test-session', refreshToken: 'test-refresh' }
else if (url.includes('/tenant/profile')) data = { id: override.customerId || '7' }
else if (url.includes('/pricing/channels')) data = override.channels ?? [
{ channelCode: 'OLD', pricingTaxModes: ['TAX_INCLUDED'], priceBookVersionId: '12' },
{ channelCode: 'NEW', channelName: '真实新渠道', pricingTaxModes: ['TAX_INCLUDED'], priceBookVersionId: '13' } ]
else if (url.includes('/pricing/estimate')) data = { channelCode: 'NEW', pricingTaxMode: 'TAX_INCLUDED', priceBookVersionId: '13' }
else if (url.includes('/declaration')) data = { version: 3, channelChanged: true, ...override.changed }
else if (url.includes('processStatus=WAIT_PRICING')) data = { records: override.rows ?? [{ id: '8', processStatus: 'WAIT_PRICING' }] }
return { http: 200, body: { code: '200', data } }
}, apiSuccess: (_m, _n, r) => r.body.data, assert() {} }
try { await retainWaitPricingFixture(context, { inboundId: '8', tenantId: '7', orderId: '9' }) }
finally {
if (calls.some(row => row.url === '/api/auth/login')) assert.equal(calls.at(-1).url, '/api/auth/logout')
}
return calls
}
const calls = await execute()
const mutation = calls.find(row => row.method === 'PUT')
assert.equal(mutation.body.expectedVersion, 2)
assert.equal(mutation.body.channelCode, 'NEW')
assert.equal(calls.filter(row => row.method === 'PUT').length, 1)
assert.equal(calls.find(row => row.url.includes('/pricing/estimate')).body.originWarehouseId, '10')
for (const override of [{ before: { orderId: 'other' } }, { order: { status: 'PROCESSING' } },
{ customerId: 'other' }, { channels: [] }, { changed: { version: 9 } },
{ after: { tenantId: 'other' } }, { rows: [] }]) {
await assert.rejects(execute(override), /WAIT_PRICING/)
}
})
test('待费用确认样本必须经真实试算并独立回查费用、详情和筛选', async () => {
const execute = async (override = {}) => {
const calls = []
let reads = 0
const fee = { feeId: '90', feeVersion: 1, feeStatus: 'CALCULATED', nextProcessStatus: 'FEE_CONFIRMING' }
const context = { marker: 'current-run',
async request(method, url, body, token, headers) {
calls.push({ method, url, body, headers })
let data
if (url === '/api/platform/inbounds/8?tenantId=7') {
reads += 1
data = { summary: { id: '8', tenantId: '7', inboundCode: 'IN-TEST-8',
processStatus: reads === 1 ? 'MEASURE_PENDING' : 'FEE_CONFIRMING',
measureReviewStatus: 'PENDING', ...(reads === 1 ? override.before : override.after) } }
} else if (url.includes('/fees/calculate')) data = { ...fee, ...override.calculated }
else if (url.includes('/fees/latest')) data = { ...fee, ...override.latest }
else data = { records: override.rows ?? [{ id: '8', processStatus: 'FEE_CONFIRMING' }] }
return { http: 200, body: { code: '200', data } }
}, apiSuccess: (_m, _n, response) => response.body.data,
assert() {} }
const result = await retainFeeConfirmingFixture(context, { inboundId: '8', tenantId: '7' })
return { calls, result }
}
const { calls, result } = await execute()
assert.deepEqual(result, { feeId: '90', feeVersion: 1 })
assert.equal(calls.length, 5)
const writes = calls.filter(row => row.method !== 'GET')
assert.equal(writes.length, 1)
assert.deepEqual(writes[0].body, { weightSource: 'ACTUAL', volumeSource: 'ACTUAL' })
assert.ok(writes[0].headers['Idempotency-Key'].startsWith('current-run-'))
assert.match(calls.at(-1).url, /inboundCode=IN-TEST-8&processStatus=FEE_CONFIRMING/)
for (const override of [
{ before: { tenantId: 'other' } }, { before: { processStatus: 'WAIT_SPLIT' } },
{ calculated: { nextProcessStatus: 'WAIT_SPLIT' } },
{ after: { processStatus: 'MEASURE_PENDING' } }, { after: { measureReviewStatus: 'APPROVED' } },
{ latest: { feeId: '91' } }, { latest: { feeStatus: 'SENT' } }, { rows: [] },
]) await assert.rejects(execute(override), /FEE_CONFIRMING/)
})
test('dynamic Platform cancellation freezes version and key while reject body stays unchanged',async()=>{
const calls=[]
@@ -91,7 +176,7 @@ test('测量状态截停发生在正确的 HTTP 边界', () => {
assert.match(source, /await weightOcr\.run\(context\)/)
assert.match(source, /target !== 'MEASURING'/)
assert.doesNotMatch(source, /target === 'MEASURING' && ok\(response\)/)
assert.match(source, /target === 'MEASURE_PENDING' && isSubmit/)
assert.match(source, /\['MEASURE_PENDING', 'FEE_CONFIRMING', 'WAIT_PRICING'\]\.includes\(target\) && isSubmit/)
assert.doesNotMatch(source, /target === 'MEASURE_REJECTED' && isSubmit/)
})
@@ -99,8 +184,8 @@ test('入库模块只声明状态全集且不在后续专项生成前预写失
for (const status of ['WAIT_PRICING', 'FEE_CONFIRMING', 'INBOUNDING', 'VOIDED']) {
assert.match(source, new RegExp(`'${status}'`))
}
assert.match(source, /processStatus=WAIT_SPLIT/)
assert.match(source, /查询存量 WAIT_SPLIT 样本/)
assert.match(source, /本轮 WAIT_SPLIT 独立样本缺失/)
assert.doesNotMatch(source, /查询存量 WAIT_SPLIT 样本|legacyInbound|legacyPage/)
assert.doesNotMatch(source, /覆盖阻断|fixture-unavailable|recordCoverageGap|addCoverageGap/)
})