import { ApiPropertyPhoneNumber } from "../src"; import { plainToClass } from "class-transformer"; import { validate } from "class-validator"; describe('ApiPropertyPhoneNumber', () => { it('should disallow counties not from allow list', async () => { class Test { @ApiPropertyPhoneNumber({ allowedCountries: ['GB'] }) phone!: string; } const obj = plainToClass(Test, { phone: '+12121231234' }); const errors = await validate(obj); expect(errors.length).toBeGreaterThan(0); expect(errors[0].property === 'phone'); expect(errors[0].constraints?.['IsValidPhoneNumber'] === 'INVALID_PHONE_NUMBER'); }); it('should allow counties from allow list', async () => { class Test { @ApiPropertyPhoneNumber({ allowedCountries: ['GB'] }) phone!: string; } const obj = plainToClass(Test, { phone: '+44 20 7123 4567' }); const errors = await validate(obj); expect(errors.length).toBe(0); }); });