import { ETHIOPIAN_REGIONS, normalizeRegion } from '@edr/types'; /** * normalizeRegion lives in @edr/types (no jest there), but it exists to keep * eTrade autofill from feeding UpdateProfileDto a region its @IsIn will reject. * That contract is an API concern, so it is guarded here. */ describe('normalizeRegion', () => { it('passes through every canonical region unchanged', () => { for (const region of ETHIOPIAN_REGIONS) { expect(normalizeRegion(region)).toBe(region); } }); it.each([ ['ADDIS ABABA', 'Addis Ababa'], ['Addis ababa', 'Addis Ababa'], [' addis ababa ', 'Addis Ababa'], ['oromoia', 'Oromia'], ['OROMIYA', 'Oromia'], ['gambella', 'Gambela'], ['TIGRAI', 'Tigray'], ['benishangul gumuz', 'Benishangul-Gumuz'], ])('resolves the variant %s', (input, expected) => { expect(normalizeRegion(input)).toBe(expected); }); it('maps a zone name in the region slot back to its parent region', () => { // eTrade's own placeholder data does this — "EASTERN TIGRAY" is a zone. expect(normalizeRegion('EASTERN TIGRAY')).toBe('Tigray'); expect(normalizeRegion('North Wollo')).toBe('Amhara'); }); it.each([ ['a city, not a region', 'Arba Minch'], ['unknown text', 'Nowhere Land'], ['empty', ''], ['whitespace only', ' '], ['null', null], ['undefined', undefined], ])('returns null for %s rather than guessing', (_label, input) => { expect(normalizeRegion(input as string | null | undefined)).toBeNull(); }); it('never returns a value outside the canonical set', () => { const samples = ['ADDIS ABABA', 'oromoia', 'EASTERN TIGRAY', 'garbage', '']; for (const s of samples) { const out = normalizeRegion(s); if (out !== null) { expect(ETHIOPIAN_REGIONS).toContain(out); } } }); });