mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { adHocLabel } from './clearance.util';
|
|
|
|
/**
|
|
* The customer's typed document name travels to the API inside the multipart
|
|
* field code (`custom_<slug>_<n>`) — 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_<timestamp>_<n>` 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();
|
|
});
|
|
});
|