UNPKG

3.25 kBJavaScriptView Raw
1"use strict";
2
3var _metadata = _interopRequireDefault(require("../metadata.full"));
4
5var _metadata2 = _interopRequireDefault(require("./metadata"));
6
7var _getNumberType2 = _interopRequireDefault(require("./getNumberType"));
8
9function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
11function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
12
13function getNumberType() {
14 for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
15 parameters[_key] = arguments[_key];
16 }
17
18 parameters.push(_metadata["default"]);
19 return _getNumberType2["default"].apply(this, parameters);
20}
21
22describe('getNumberType', function () {
23 it('should infer phone number type MOBILE', function () {
24 getNumberType('9150000000', 'RU').should.equal('MOBILE');
25 getNumberType('7912345678', 'GB').should.equal('MOBILE');
26 getNumberType('51234567', 'EE').should.equal('MOBILE');
27 });
28 it('should infer phone number types', function () {
29 getNumberType('88005553535', 'RU').should.equal('TOLL_FREE');
30 getNumberType('8005553535', 'RU').should.equal('TOLL_FREE');
31 getNumberType('4957777777', 'RU').should.equal('FIXED_LINE');
32 getNumberType('8030000000', 'RU').should.equal('PREMIUM_RATE');
33 getNumberType('2133734253', 'US').should.equal('FIXED_LINE_OR_MOBILE');
34 getNumberType('5002345678', 'US').should.equal('PERSONAL_NUMBER');
35 });
36 it('should work when no country is passed', function () {
37 getNumberType('+79150000000').should.equal('MOBILE');
38 });
39 it('should return FIXED_LINE_OR_MOBILE when there is ambiguity', function () {// (no such country in the metadata, therefore no unit test for this `if`)
40 });
41 it('should work in edge cases', function () {
42 var thrower; // // No metadata
43 // thrower = () => _getNumberType({ phone: '+78005553535' })
44 // thrower.should.throw('`metadata` argument not passed')
45 // Parsed phone number
46
47 getNumberType({
48 phone: '8005553535',
49 country: 'RU'
50 }).should.equal('TOLL_FREE'); // Invalid phone number
51
52 type(getNumberType('123', 'RU')).should.equal('undefined'); // Invalid country
53
54 thrower = function thrower() {
55 return getNumberType({
56 phone: '8005553535',
57 country: 'RUS'
58 });
59 };
60
61 thrower.should["throw"]('Unknown country'); // Numerical `value`
62
63 thrower = function thrower() {
64 return getNumberType(89150000000, 'RU');
65 };
66
67 thrower.should["throw"]('A phone number must either be a string or an object of shape { phone, [country] }.'); // When `options` argument is passed.
68
69 getNumberType('8005553535', 'RU', {}).should.equal('TOLL_FREE');
70 getNumberType('+78005553535', {}).should.equal('TOLL_FREE');
71 getNumberType({
72 phone: '8005553535',
73 country: 'RU'
74 }, {}).should.equal('TOLL_FREE');
75 });
76});
77
78function type(something) {
79 return _typeof(something);
80}
81//# sourceMappingURL=getNumberType.test.js.map
\No newline at end of file