import { adHocLabel } from './clearance.util'; /** * The customer's typed document name travels to the API inside the multipart * field code (`custom__`) — the only channel a part has — and comes * back out here for GL's review grid. Mirror of `adHocSlug` in the portal's * useClearanceFlow. */ const adHocSlug = (name: string) => name .trim() .toLowerCase() .replace(/[^a-z0-9]+/g, '-') .replace(/^-+|-+$/g, '') .slice(0, 60); const roundTrip = (typed: string) => adHocLabel(`custom_${adHocSlug(typed)}_17877000000000`); describe('adHocLabel', () => { it('recovers the name the customer typed', () => { expect(roundTrip('Special permit')).toBe('Special permit'); expect(roundTrip('Fumigation Certificate')).toBe('Fumigation certificate'); expect(roundTrip('bank slip #2')).toBe('Bank slip 2'); }); it('returns null when there is no name to show, so callers use the filename', () => { expect(roundTrip('')).toBeNull(); // Legacy uploads keyed `custom__` carry no name — without the // digits guard this would surface "1755780000000" as the document label. expect(adHocLabel('custom_1755780000000_0')).toBeNull(); expect(adHocLabel('commercial_invoice')).toBeNull(); }); });