import { faToEn } from './digits'; /** * Digit normalisation, ported from the reference's Utility::faTOen(), which * every mobile number and every submitted OTP code passes through before it is * compared (henza_server ApiMobileController.php:42,56). * * Without it a user typing ۱۲۳۴ on a Persian keypad could never match a stored * 1234, and the phone lookup would miss a registered customer entirely. */ describe('faToEn', () => { it('converts Persian (Extended Arabic-Indic) digits', () => { expect(faToEn('۰۹۱۲۸۰۸۱۳۹۲')).toBe('09128081392'); }); it('converts Arabic-Indic digits', () => { expect(faToEn('٠٩١٢٨٠٨١٣٩٢')).toBe('09128081392'); }); it('leaves ASCII digits untouched', () => { expect(faToEn('09128081392')).toBe('09128081392'); }); it('handles a mixed-script number', () => { expect(faToEn('۰۹12۸0۸1۳۹۲')).toBe('09128081392'); }); it('trims surrounding whitespace, as a pasted number often carries', () => { expect(faToEn(' ۰۹۱۲۳۴۵۶۷۸۹ ')).toBe('09123456789'); }); it('normalises a 4-digit OTP code the same way', () => { expect(faToEn('۷۳۵۷')).toBe('7357'); }); it('is a no-op on an empty string', () => { expect(faToEn('')).toBe(''); }); });