import { getCurrentJalaliYear, isValidPlateLetter, mergePlateAndNationalPolicies, normalizeSoapCarPolicy, selectBestThirdPartyPolicy, } from '../../src/common/helpers/third-party-car-rules.helper'; describe('third-party car rules', () => { it('rejects invalid plate letters', () => { expect(isValidPlateLetter('')).toBe(false); expect(isValidPlateLetter('ب')).toBe(true); }); it('prefers active newer policy when multiple acceptable policies exist', () => { const older = normalizeSoapCarPolicy( { NtnlId: '4311402422', VhcleGrpCd: '2', PlcyBegnDt: '20260101', PlcyEndDt: '20270101', }, '4311402422', ); const newer = normalizeSoapCarPolicy( { NtnlId: '4311402422', VhcleGrpCd: '3', PlcyBegnDt: '20260701', PlcyEndDt: '20270701', }, '4311402422', ); const selected = selectBestThirdPartyPolicy([older, newer], '4311402422'); expect(selected?.raw.PlcyBegnDt).toBe('20260701'); }); it('keeps plate result when national code points to another vehicle', () => { const plate = normalizeSoapCarPolicy( { NtnlId: '4311402422', ChassisNo: 'CHASSIS-A', Plk1: '12', Plk2: 'ب', Plk3: '345', PlkSrl: '67', }, '4311402422', ); const national = normalizeSoapCarPolicy( { NtnlId: '4311402422', ChassisNo: 'CHASSIS-B', Plk1: '99', Plk2: 'ج', Plk3: '111', PlkSrl: '22', }, '4311402422', ); const merged = mergePlateAndNationalPolicies(plate, national); expect(merged?.chassisNo).toBe('CHASSIS-A'); }); it('returns current jalali year', () => { expect(getCurrentJalaliYear(new Date('2026-03-21T00:00:00Z'))).toBeGreaterThan(1400); }); });