import { usesEdrMileService } from './mile-haulage.util'; /** * The road legs are chosen on the contract and copied onto the booking. EDR * haulage and a customer's own truck are alternatives, so this one answer gates * both sides — the customer-truck guard and the mile-queue guard. */ describe('usesEdrMileService', () => { const booking = (over: Partial[0]> = {}) => ({ tradeDirection: 'IMPORT', firstMile: null, lastMile: null, ...over, }); it('an import that chose delivery uses EDR haulage', () => { expect(usesEdrMileService(booking({ lastMile: 'Bole, Addis Ababa' }))).toBe(true); }); it('an import that chose nothing does not', () => { expect(usesEdrMileService(booking())).toBe(false); }); it('ignores the pickup address on an import — collection is the export leg', () => { expect(usesEdrMileService(booking({ firstMile: 'Modjo' }))).toBe(false); }); it('an export that chose collection uses EDR haulage', () => { expect( usesEdrMileService(booking({ tradeDirection: 'EXPORT', firstMile: 'Modjo' })), ).toBe(true); }); it('ignores the delivery address on an export — delivery is the import leg', () => { expect( usesEdrMileService(booking({ tradeDirection: 'EXPORT', lastMile: 'Djibouti' })), ).toBe(false); }); it('a domestic booking counts either leg', () => { expect( usesEdrMileService(booking({ tradeDirection: 'DOMESTIC', firstMile: 'Adama' })), ).toBe(true); expect( usesEdrMileService(booking({ tradeDirection: 'DOMESTIC', lastMile: 'Dire Dawa' })), ).toBe(true); }); it('treats a whitespace-only address as no choice', () => { expect(usesEdrMileService(booking({ lastMile: ' ' }))).toBe(false); }); });