import { isValidIoss, normaliseIoss } from '../features/order-ship/booking/ioss-section'; describe( 'normaliseIoss', () => { it( 'strips spaces and capitalises', () => { expect( normaliseIoss( ' im 123 456 7890 ' ) ).toBe( 'IM1234567890' ); } ); it( 'returns null for a blank value', () => { expect( normaliseIoss( ' ' ) ).toBeNull(); } ); } ); describe( 'isValidIoss', () => { it( 'accepts "IM" and 10 digits, the API default', () => { expect( isValidIoss( 'IM1234567890' ) ).toBe( true ); } ); it( 'rejects a bare 12-digit number, which the API would refuse', () => { expect( isValidIoss( '123456789012' ) ).toBe( false ); } ); it( 'rejects the wrong length', () => { expect( isValidIoss( 'IM123' ) ).toBe( false ); expect( isValidIoss( 'IM12345678901' ) ).toBe( false ); } ); it( 'accepts a blank value, which clears the number', () => { expect( isValidIoss( null ) ).toBe( true ); } ); it( 'uses the pattern the API sends', () => { expect( isValidIoss( 'IM1234567890', '^IM[0-9]{10}$' ) ).toBe( true ); expect( isValidIoss( 'XX1234567890', '^IM[0-9]{10}$' ) ).toBe( false ); } ); it( 'falls back to the default when the API pattern is not a valid regex', () => { expect( isValidIoss( 'IM1234567890', '([' ) ).toBe( true ); } ); } );