test: normalize finance container allocation sources

This commit is contained in:
2026-08-15 17:45:51 +08:00
parent 28daf15082
commit 5e1e49085d
4 changed files with 73 additions and 15 deletions
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { buildContainerCostBody, run } from './finance-full-fixtures.mjs'
import { buildContainerCostBody, normalizeFinanceFixtureSources, run } from './finance-full-fixtures.mjs'
const here = path.dirname(fileURLToPath(import.meta.url))
const source = fs.readFileSync(path.join(here, 'finance-full-fixtures.mjs'), 'utf8')
@@ -52,6 +52,28 @@ test('shared fixture source names the finance full acceptance contract', () => {
}
})
test('fixture source normalization uses only marker-owned orders and real allocation order links', () => {
const sources = [
{ feeSourceId: 'F-ORDER', orderId: 'O-1', businessDate: '2026-08-10' },
{ feeSourceId: 'F-CONTAINER', billingBasis: 'CONTAINER_SHARED', businessDate: '2026-08-11' },
]
const orders = [
{ orderId: 'O-1', orderNo: 'ORDER-1', waybillId: 'WB-1' },
{ orderId: 'O-2', orderNo: 'ORDER-2', shipmentId: 'SHIP-2' },
]
const normalized = normalizeFinanceFixtureSources(sources, orders, [{ orderId: 'O-2', allocatedAmount: 30 }],
'701', 'FIN-MARKER')
assert.deepEqual(normalized.map((source) => ({ feeSourceId: source.feeSourceId, customerId: source.customerId,
marker: source.marker, orderId: source.orderId, waybill: source.waybillId || source.shipmentId || source.orderNo })), [
{ feeSourceId: 'F-ORDER', customerId: '701', marker: 'FIN-MARKER', orderId: 'O-1', waybill: 'WB-1' },
{ feeSourceId: 'F-CONTAINER', customerId: '701', marker: 'FIN-MARKER', orderId: 'O-2', waybill: 'SHIP-2' },
])
const unbound = normalizeFinanceFixtureSources([sources[1]], orders, [], '701', 'FIN-MARKER')[0]
assert.equal(unbound.orderId, null)
assert.equal(unbound.waybillId || unbound.shipmentId || unbound.orderNo, null)
})
function fakeContext(overrides = {}) {
const steps = []
const context = {
@@ -116,6 +138,8 @@ test('run behavior emits consumer shape, both billing bases, distinct dates, sup
assert.ok(Array.isArray(fixture.allocations))
assert.ok(fixture.feeSources.filter((item) => item.direction === 'RECEIVABLE').length >= 4)
assert.ok(new Set(fixture.feeSources.filter((item) => item.direction === 'RECEIVABLE').map((item) => item.businessDate)).size >= 2)
assert.equal(fixture.feeSources.every((item) => item.feeSourceId && item.customerId === fixture.customerId
&& item.businessDate && (item.waybillId || item.shipmentId || item.orderNo) && item.marker === context.marker), true)
})
test('run preserves real price-row profiles when creating automatic orders', async () => {