signal-desktop/ts/test-both/util/libphonenumberUtil_test.ts

31 lines
1.1 KiB
TypeScript
Raw Normal View History

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
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', () => {
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 => {
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');
});
});
2018-04-27 21:25:04 +00:00
});
2018-11-02 18:02:53 +00:00
});