import { Booking } from './entities/booking.entity'; import { clearanceDocumentsOpen } from './clearance.util'; /** * The customer may attach clearance documents — and GL may review them — right * up to payment, not merely until clearance is finalized. Both the upload and * the review endpoint gate on this one predicate, so a drift here silently * desynchronizes the two sides. */ const booking = (patch: Partial): Booking => ({ status: 'CLEARANCE_READY', paymentStatus: 'PENDING', ...patch }) as Booking; describe('clearanceDocumentsOpen', () => { it('stays open across the whole pre-payment flow', () => { for (const status of [ 'AWAITING_DOCUMENTS', 'DOCUMENTS_UNDER_REVIEW', 'CLEARANCE_READY', 'OPERATION_REQUEST_PENDING', 'SELECTED_FOR_BATCH', 'PNR_GENERATED', 'PAYMENT_VERIFICATION_IN_PROGRESS', ]) { expect(clearanceDocumentsOpen(booking({ status }))).toBe(true); } }); it('closes once the shipment is paid or finished', () => { for (const status of ['PAID', 'IN_TRANSIT', 'ARRIVED', 'COMPLETED']) { expect(clearanceDocumentsOpen(booking({ status }))).toBe(false); } }); it('closes on a dead booking', () => { for (const status of ['REJECTED', 'CANCELLED', 'EXPIRED']) { expect(clearanceDocumentsOpen(booking({ status }))).toBe(false); } }); it('closes when payment settled before the status caught up', () => { expect( clearanceDocumentsOpen( booking({ status: 'PNR_GENERATED', paymentStatus: 'PAID' }), ), ).toBe(false); }); });