import test from 'node:test' import assert from 'node:assert/strict' import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const here = path.dirname(fileURLToPath(import.meta.url)) const source = fs.readFileSync(path.join(here, 'finance-extended-fees.mjs'), 'utf8') test('extended fee module is fixed-marker isolated and exports the acceptance entry', () => { assert.match(source, /FIXED_MARKER = 'FIN-EXT-FEE-20260812'/) assert.match(source, /export async function run\(context\)/) assert.match(source, /baseFixture\.marker !== FIXED_MARKER/) assert.match(source, /createdResources\.financeExtendedFees/) }) test('extended fee module covers six orders and both automatic billing bases', () => { assert.match(source, /创建第六张独立订单与入库单/) assert.match(source, /resources\.length >= 6/) assert.match(source, /'WEIGHT_KG', 'VOLUME_CBM'/) assert.match(source, /length >= 2/) }) test('manual status matrix covers receivable, payable, rejection, approval and void', () => { for (const name of ['AR-PENDING', 'AR-REJECTED', 'AR-APPROVED', 'AP-PENDING', 'AP-APPROVED', 'AR-VOID']) { assert.match(source, new RegExp(name)) } assert.match(source, /expectedFinance: 'AVAILABLE'/) assert.match(source, /expectedFinance: 'ABSENT'/) assert.match(source, /作废来源不可选择出账/) }) test('every source is traced through order, inbound, fee, and Finance pool reads', () => { assert.match(source, /readOrderInboundAndFee/) assert.match(source, /financeState/) assert.match(source, /回读订单/) assert.match(source, /回读入库单/) assert.match(source, /回读费用/) assert.match(source, /回读 Finance 池/) }) test('writes carry marker idempotency and include replay and stale-version conflict', () => { assert.match(source, /'Idempotency-Key': key\(action\)/) assert.match(source, /同键同参人工费用创建幂等重放/) assert.match(source, /expectedSourceVersion=999/) assert.match(source, /错误 sourceVersion 调整产生并发版本冲突/) }) test('uses the fee item supplier category to select an existing ACTIVE supplier and never creates one', () => { assert.match(source, /\/api\/platform\/v1\/suppliers\?page=1&size=200&status=ACTIVE\$\{suffix\}/) assert.match(source, /const supplier = await loadActiveSupplier\(context, payableItem\?\.supplierCategory \|\| null\)/) assert.doesNotMatch(source, /\/api\/platform\/v1\/partners/) })