import { edrHaulsThisBooking, 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); }); }); /** * Self-haul is closed only once EDR has committed to the leg. Delivery chosen * on the contract is a request the chief still has to approve; collection has * no approval step. */ describe('edrHaulsThisBooking', () => { const booking = (over: Partial[0]> = {}) => ({ tradeDirection: 'IMPORT', firstMile: null, lastMile: null, lastMileCommitted: false, ...over, }); it('an import whose last-mile request is not yet approved may still self-haul', () => { expect(edrHaulsThisBooking(booking({ lastMile: 'Bole, Addis Ababa' }))).toBe(false); }); it('an import whose last-mile request was approved is hauled by EDR', () => { expect( edrHaulsThisBooking(booking({ lastMile: 'Bole, Addis Ababa', lastMileCommitted: true })), ).toBe(true); }); it('an import that chose no delivery self-hauls, whatever the leg tables say', () => { expect(edrHaulsThisBooking(booking({ lastMileCommitted: true }))).toBe(false); }); it('an export that chose collection is hauled by EDR — no approval step on that leg', () => { expect(edrHaulsThisBooking(booking({ tradeDirection: 'EXPORT', firstMile: 'Modjo' }))).toBe( true, ); }); it('a domestic booking is blocked by collection, or by an approved delivery', () => { expect(edrHaulsThisBooking(booking({ tradeDirection: 'DOMESTIC', firstMile: 'Adama' }))).toBe( true, ); expect( edrHaulsThisBooking(booking({ tradeDirection: 'DOMESTIC', lastMile: 'Dire Dawa' })), ).toBe(false); expect( edrHaulsThisBooking( booking({ tradeDirection: 'DOMESTIC', lastMile: 'Dire Dawa', lastMileCommitted: true }), ), ).toBe(true); }); });