Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix example phone numbers #32

Merged
merged 1 commit into from
Jan 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 13 additions & 19 deletions test/asserts/phone-assert_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import Phone from '../../src/asserts/phone-assert';
import should from 'should';
import { Assert as BaseAssert, Violation } from 'validator.js';
import { PhoneNumberFormat as PNF, PhoneNumberUtil } from 'google-libphonenumber';

/**
* Extend Assert with `PhoneAssert`.
*/

const Assert = BaseAssert.extend({ Phone });
const phoneUtil = PhoneNumberUtil.getInstance();

/**
* Test `PhoneAssert`.
Expand Down Expand Up @@ -68,47 +70,39 @@ describe('PhoneAssert', () => {
[{
countryOrCallingCode: 'AU',
expectedCountryCode: 'US',
phone: '0011 1 408-550-3542'
phone: `0011 1 ${phoneUtil.format(phoneUtil.getExampleNumber('US'), PNF.NATIONAL)}`
}, {
countryOrCallingCode: 'PT',
expectedCountryCode: 'MX',
phone: '+5215555123123'
}, {
countryOrCallingCode: 'ES',
expectedCountryCode: 'IT',
phone: '00 39 312 123 1234'
phone: phoneUtil.format(phoneUtil.getExampleNumber('MX'), PNF.E164)
}, {
countryOrCallingCode: 'ES',
expectedCountryCode: 'IT',
phone: '+39 0187 1234(12)'
phone: phoneUtil.format(phoneUtil.getExampleNumber('IT'), PNF.E164).replace('+', '00')
}, {
countryOrCallingCode: 'CH',
expectedCountryCode: 'US',
phone: '00 1 809 555 5555'
phone: `00 1 ${phoneUtil.format(phoneUtil.getExampleNumber('US'), PNF.NATIONAL)}`
}, {
countryOrCallingCode: 'PT',
expectedCountryCode: 'DO',
phone: '+1 809 555 5555'
phone: phoneUtil.format(phoneUtil.getExampleNumber('DO'), PNF.E164)
}, {
countryOrCallingCode: 'GB',
expectedCountryCode: 'IM',
phone: '07624123456'
phone: phoneUtil.format(phoneUtil.getExampleNumber('IM'), PNF.NATIONAL)
}, {
countryOrCallingCode: '1',
expectedCountryCode: '351',
phone: '+351 912 345 679'
phone: phoneUtil.format(phoneUtil.getExampleNumber('PT'), PNF.E164)
}, {
countryOrCallingCode: '41',
countryOrCallingCode: '39',
expectedCountryCode: '41',
phone: '+1 408-550-3542'
phone: phoneUtil.format(phoneUtil.getExampleNumber('CH'), PNF.E164)
}, {
countryOrCallingCode: '61',
countryOrCallingCode: '41',
expectedCountryCode: '1',
phone: '00 1 408-550-3542'
}, {
countryOrCallingCode: '882',
expectedCountryCode: '882',
phone: '+88313300655'
phone: `00 1 ${phoneUtil.format(phoneUtil.getExampleNumber('US'), PNF.NATIONAL)}`
}].forEach(({ countryOrCallingCode, phone, expectedCountryCode }) => {
try {
new Assert().Phone(countryOrCallingCode).validate(phone);
Expand Down