import { deriveRateType } from './rate-type.util';

describe('deriveRateType — surcharge triggers', () => {
  // Every surcharge trigger must land on its own rateType. A trigger with no
  // mapping falls through to the base-freight branch and is silently stored as
  // CANCELLATION_FEE, which both mislabels the booking's rate snapshot and
  // hides the rate from contract pricing (which looks rateTypes up by name).
  it.each([
    ['HAZARDOUS', 'HAZARD_SURCHARGE'],
    ['REEFER', 'REEFER_SURCHARGE'],
    ['WITH_RETURN', 'RETURN_SURCHARGE'],
    ['OVERWEIGHT', 'OVERWEIGHT_PER_TON'],
    ['SHIPPING_LINE', 'DOUBLE_HANDLING'],
    ['CONSOLIDATION', 'LASHING'],
    ['CANCELLATION', 'CANCELLATION_FEE'],
    ['DEMURRAGE', 'DEMURRAGE'],
    ['PIL_EXTRA_FEE', 'PIL_EXTRA_FEE'],
    ['CUSTOMS_CLEARANCE', 'CUSTOMS_CLEARANCE'],
  ] as const)('maps trigger %s to %s', (trigger, expected) => {
    expect(deriveRateType({ appliesTo: 'OTHER', trigger })).toBe(expected);
  });

  it('does not fall back to CANCELLATION_FEE for the empty-return service', () => {
    expect(deriveRateType({ appliesTo: 'OTHER', trigger: 'WITH_RETURN' })).not.toBe(
      'CANCELLATION_FEE',
    );
  });
});
