2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2015 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-06-01 17:48:16 +00:00
|
|
|
import { assert, AssertionError } from 'chai';
|
|
|
|
import { parseNumber } from '../../util/libphonenumberUtil';
|
2018-11-02 18:02:53 +00:00
|
|
|
|
|
|
|
describe('libphonenumber util', () => {
|
|
|
|
describe('parseNumber', () => {
|
|
|
|
it('numbers with + are valid without providing regionCode', () => {
|
2022-06-01 17:48:16 +00:00
|
|
|
const result = parseNumber('+14155555555');
|
|
|
|
if (!result.isValidNumber) {
|
|
|
|
throw new AssertionError('Phone number is not valid');
|
|
|
|
}
|
2018-11-02 18:02:53 +00:00
|
|
|
assert.strictEqual(result.e164, '+14155555555');
|
|
|
|
assert.strictEqual(result.regionCode, 'US');
|
|
|
|
assert.strictEqual(result.countryCode, '1');
|
|
|
|
});
|
|
|
|
it('variant numbers with the right regionCode are valid', () => {
|
|
|
|
['4155555555', '14155555555', '+14155555555'].forEach(number => {
|
2022-06-01 17:48:16 +00:00
|
|
|
const result = parseNumber(number, 'US');
|
|
|
|
if (!result.isValidNumber) {
|
|
|
|
throw new AssertionError('Phone number is not valid');
|
|
|
|
}
|
2018-04-27 21:25:04 +00:00
|
|
|
assert.strictEqual(result.e164, '+14155555555');
|
|
|
|
assert.strictEqual(result.regionCode, 'US');
|
|
|
|
assert.strictEqual(result.countryCode, '1');
|
|
|
|
});
|
2015-12-05 01:38:41 +00:00
|
|
|
});
|
2018-04-27 21:25:04 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|