import { generateGrnNumber, grnOwnerSlug } from './grn.util'; /** * The GRN is mapped to the goods owner for BOTH directions, so a note is * identifiable by who owns the cargo. The reference slice stays the uniqueness * anchor — one owner can have several bookings received the same day. */ const date = new Date('2026-07-27T09:15:00Z'); const bookingId = '1a2b3c4d-1111-2222-3333-444455556666'; describe('GRN number', () => { it('maps an import GRN to the owner', () => { expect(generateGrnNumber('IMPORT', bookingId, date, 'Shafici Pharmaceutical')).toBe( 'GRN-IMPORT-20260727-SHAFICIPHARM-1A2B3C4D', ); }); it('maps an export GRN to the owner the same way', () => { expect(generateGrnNumber('EXPORT', bookingId, date, 'Tria Trading PLC')).toBe( 'GRN-EXPORT-20260727-TRIATRADINGP-1A2B3C4D', ); }); it('keeps the owner-less format when there is no owner (manual walk-in)', () => { expect(generateGrnNumber('WH', bookingId, date)).toBe('GRN-WH-20260727-1A2B3C4D'); expect(generateGrnNumber('WH', bookingId, date, ' ')).toBe('GRN-WH-20260727-1A2B3C4D'); }); it('stays unique per booking for one owner on one day', () => { const a = generateGrnNumber('IMPORT', bookingId, date, 'Acme'); const b = generateGrnNumber('IMPORT', 'ffffffff-9999-0000-0000-000000000000', date, 'Acme'); expect(a).not.toBe(b); }); it('strips punctuation and caps the owner segment', () => { expect(grnOwnerSlug('Ethio-Djibouti Railway S.C.')).toBe('ETHIODJIBOUT'); expect(grnOwnerSlug('a/b c')).toBe('ABC'); expect(grnOwnerSlug(null)).toBeNull(); }); });