Refactor number parsing and validation
Refactor libphonenumber.validateNumber into libphonenumber.parseNumber, which encapsulates the try-catch pattern used in number parsing and returns an object of info about the input number rather tha throwing since we expect to get some invalid number inputs the user is typing. In the conversation model, * Separate phone number validation from search token updating. * Perform token update before save if the number was valid. * Stop storing unneeded number variants as conversation properties. // FREEBIEpull/749/head
parent
7dd0fb70b5
commit
a258f1a66b
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* vim: ts=4:sw=4:expandtab
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
describe('libphonenumber util', function() {
|
||||
describe('parseNumber', function() {
|
||||
it('numbers with + are valid without providing regionCode', function() {
|
||||
var result = libphonenumber.util.parseNumber('+14155555555');
|
||||
assert.isTrue(result.isValidNumber);
|
||||
assert.strictEqual(result.nationalNumber, '4155555555');
|
||||
assert.strictEqual(result.e164, '+14155555555');
|
||||
assert.strictEqual(result.regionCode, 'US');
|
||||
assert.strictEqual(result.countryCode, '1');
|
||||
});
|
||||
it('variant numbers with the right regionCode are valid', function() {
|
||||
[ '4155555555', '14155555555', '+14155555555', ].forEach(function(number) {
|
||||
var result = libphonenumber.util.parseNumber(number, 'US');
|
||||
assert.isTrue(result.isValidNumber);
|
||||
assert.strictEqual(result.nationalNumber, '4155555555');
|
||||
assert.strictEqual(result.e164, '+14155555555');
|
||||
assert.strictEqual(result.regionCode, 'US');
|
||||
assert.strictEqual(result.countryCode, '1');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
Loading…
Reference in New Issue