1 | "use strict";
|
2 |
|
3 | var _metadata = _interopRequireDefault(require("../metadata.full"));
|
4 |
|
5 | var _metadata2 = _interopRequireDefault(require("./metadata"));
|
6 |
|
7 | var _getNumberType2 = _interopRequireDefault(require("./getNumberType"));
|
8 |
|
9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
10 |
|
11 | function _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 |
|
13 | function 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 |
|
22 | describe('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 () {
|
40 | });
|
41 | it('should work in edge cases', function () {
|
42 | var thrower;
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | getNumberType({
|
48 | phone: '8005553535',
|
49 | country: 'RU'
|
50 | }).should.equal('TOLL_FREE');
|
51 |
|
52 | type(getNumberType('123', 'RU')).should.equal('undefined');
|
53 |
|
54 | thrower = function thrower() {
|
55 | return getNumberType({
|
56 | phone: '8005553535',
|
57 | country: 'RUS'
|
58 | });
|
59 | };
|
60 |
|
61 | thrower.should["throw"]('Unknown country');
|
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] }.');
|
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 |
|
78 | function type(something) {
|
79 | return _typeof(something);
|
80 | }
|
81 |
|
\ | No newline at end of file |