This commit is contained in:
Marshal
2026-07-23 14:18:24 +00:00
parent 15a6bab5d0
commit 127676055b
15 changed files with 362 additions and 160 deletions

View File

@@ -379,6 +379,25 @@ describe('BookingPricingService — customs clearance fee billed on the booking
expect(line!.amount).toBe(600);
});
it('the fee scoped to the booking commodity wins over the catch-all', async () => {
const service = makeService({
liveRates: [
{ ...bulkFeePerTon, id: 'rate-cc-catchall', rateValue: 5 } as Rate,
{
...bulkFeePerTon,
id: 'rate-cc-sugar',
rateValue: 9,
cargoTypeId: 'cargo-1',
} as Rate,
],
});
const result = await service.computePriceForBooking(bulkBooking());
const line = result.lineItems.find((l) => l.code === 'CUSTOMS_CLEARANCE');
expect(line!.unitAmount).toBe(9); // commodity rate, not the 5 USD catch-all
expect(line!.amount).toBe(1080);
});
it('bills a PER_WAGON bulk fee on ceil(tons ÷ wagon capacity)', async () => {
const service = makeService({
liveRates: [{ ...bulkFeePerTon, rateUnit: 'PER_WAGON', rateValue: 50 } as Rate],

View File

@@ -1028,8 +1028,15 @@ export class BookingPricingService {
// Bulk — one fee for the whole booking. The bulk snapshot and the legacy
// flat snapshot share the CUSTOMS_CLEARANCE code; both are the agreed fee.
// Live lookup: the rate scoped to the booking's commodity wins; a
// commodity-less rate (legacy) is the catch-all fallback.
const frozen = this.frozenRateByCode(frozenRates, 'CUSTOMS_CLEARANCE', currency);
const live = onLeg.find((r) => !r.containerTypeId);
const live =
(booking.cargoTypeId
? onLeg.find(
(r) => !r.containerTypeId && r.cargoTypeId === booking.cargoTypeId,
)
: undefined) ?? onLeg.find((r) => !r.containerTypeId && !r.cargoTypeId);
if (!frozen && !live) {
blocked.push(missingRateMessage('bulk cargo'));
return { lineItems, usedRates, blocked };