import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import test from 'node:test' const entry = new URL('../admin-test-env-acceptance.mjs', import.meta.url) const moduleFile = new URL('./inbound-fees.mjs', import.meta.url) test('admin full acceptance registers inbound fee lifecycle after measurement', async () => { const source = await readFile(entry, 'utf8') assert.match(source, /'inbound-measurement', 'inbound-fees', 'phase3-container-loading'/) assert.match(source, /normalized\.includes\('inbound-fees'\)/) assert.match(source, /\['merchant-qualification-fixture', 'orders', 'inbound-measurement'\]/) }) test('inbound fee lifecycle covers frozen source, version, publication and WAIT_SPLIT contracts', async () => { const source = await readFile(moduleFile, 'utf8') for (const token of [ '/fees/latest', '/fees/calculate', '/fees/published', '/fees/confirm', '/fees/send', '/fee-details', 'FBA_PRICING', 'MANUAL', 'CALCULATED', 'CONFIRMED', 'SENT', 'PUBLISHED', 'sourceFeeVersion', 'reviewStatus', 'publicationStatus', 'WAIT_SPLIT', 'toleranceConfirmed: true', ]) assert.match(source, new RegExp(token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))) assert.match(source, /人工发布头程费用并触发 Finance Outbox/) assert.match(source, /String\(initialResponse\?\.body\?\.code\) === 'A0404'/) assert.match(source, /对客合计仅含已发布头程与已审核其他应收且其他应付单列/) assert.doesNotMatch(source, /settlementIncluded|是否结算|参与结算/) }) test('initial fee preparation is reusable without confirming or publishing the fee', async () => { const source = await readFile(moduleFile, 'utf8') assert.match(source, /export async function ensureInitialCalculated/) const helper = source.slice(source.indexOf('export async function ensureInitialCalculated'), source.indexOf('export async function run')) assert.match(helper, /\/fees\/latest/) assert.match(helper, /\/fees\/calculate/) assert.match(helper, /feeStatus === 'CALCULATED'/) assert.match(helper, /\$\{inboundId\}-inbound-fee-initial-calculate/) assert.doesNotMatch(helper, /\/fees\/confirm|\/fees\/send/) }) test('automatic fee adjustment confirms the ten percent tolerance boundary', async () => { const source = await readFile(moduleFile, 'utf8') assert.match(source, /reason: `\$\{context\.marker\}-自动费用版本调整`, toleranceConfirmed: true/) assert.match(source, /adjustedUnitPrice = Number\(\(Math\.max\(0, money\(initial\.unitPrice\)\) \+ 0\.37\)\.toFixed\(4\)\)/) assert.match(source, /人工对客单价写入最新费用版本/) assert.match(source, /money\(published\?\.unitPrice\) === adjustedUnitPrice/) }) test('customer confirms chargeable quantity and manual unit price in one locked version', async () => { const source = await readFile(moduleFile, 'utf8') assert.match(source, /const orderId = id\(fixture\?\.orderId\)/) assert.match(source, /context\.context\?\.merchantQualificationFixture/) assert.match(source, /merchantFixture\?\.username \|\| MERCHANT_USERNAME/) assert.match(source, /merchantFixture\?\.password \|\| MERCHANT_PASSWORD/) assert.doesNotMatch(source, /const orderId = id\(context\.createdResources\.orders\?\.orderId\)/) assert.match(source, /Client 读取已推送计费量、对客单价和费用合计/) assert.match(source, /Client 一次确认计费量、对客单价和费用/) assert.match(source, /customerConfirmationStatus === 'CONFIRMED'/) assert.match(source, /客户费用确认重放返回同一锁定版本/) assert.match(source, /客户确认后平台不得再次修改计费量或对客单价/) })