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
@@ -168,7 +168,6 @@ async function normalizeFixture(context) {
if (!root || root.marker !== context.marker || !root.customerId
|| !Array.isArray(root.orders) || !Array.isArray(root.feeSources)) return null
const customerId = id(root.customerId)
const orders = new Map(root.orders.map((order) => [id(order.orderId ?? order.id), order]))
const expectedSourceIds = new Set(root.feeSources.map(sourceId).filter(Boolean))
let pool = []
for (let attempt = 0; attempt < 20; attempt += 1) {
@@ -182,15 +181,13 @@ async function normalizeFixture(context) {
}
const poolBySource = new Map(pool.map((item) => [id(item?.sourceId), item]))
const attemptedSources = root.feeSources.map((raw) => {
const order = orders.get(id(raw.orderId))
const financeSource = poolBySource.get(sourceId(raw))
|| pool.find((item) => String(item?.direction || '').toUpperCase() === 'PAYABLE'
&& [raw.containerBookingId, raw.loadingPlanId].map(id).includes(id(item?.containerId)))
return {
raw, feeSourceId: financePoolId(financeSource), sourceFeeId: sourceId(raw), customerId: id(raw.customerId ?? customerId),
raw, feeSourceId: financePoolId(financeSource), sourceFeeId: sourceId(raw), customerId: id(raw.customerId),
direction: String(raw.direction ?? ''), currency: String(raw.currency ?? raw.currencyCode ?? '').toUpperCase(),
businessDate: sourceDate(raw), waybillId: sourceWaybill(raw) || sourceWaybill(order),
marker: raw.marker ?? root.marker,
businessDate: sourceDate(raw), waybillId: sourceWaybill(raw), marker: raw.marker,
supplierId: id(raw.supplierId ?? raw.partnerId ?? root.supplierId ?? root.partnerId),
supplierName: raw.supplierName ?? raw.partnerName ?? root.supplierName ?? root.partnerName ?? null,
}