mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 18:48:11 +00:00
feat(warehouses): map GRN numbers to the goods owner
GRN-<DIR>-<DATE>-<REF8> carried no owner, so a note couldn't be identified by who owns the cargo. Add an owner segment sourced from the booking's company at every generation point (import, export, facility, manual receive), keep REF8 for uniqueness, and label the GRN document row Owner's Name.
This commit is contained in:
40
apps/edr-freight-api/src/common/grn.util.spec.ts
Normal file
40
apps/edr-freight-api/src/common/grn.util.spec.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user