1 | "use strict";
|
2 |
|
3 | var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
|
4 |
|
5 | var _metadata = _interopRequireWildcard(require("./metadata"));
|
6 |
|
7 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
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 | describe('metadata', function () {
|
14 | it('should return undefined for non-defined types', function () {
|
15 | var FR = new _metadata["default"](_metadataMin["default"]).country('FR');
|
16 | type(FR.type('FIXED_LINE')).should.equal('undefined');
|
17 | });
|
18 | it('should validate country', function () {
|
19 | var thrower = function thrower() {
|
20 | return new _metadata["default"](_metadataMin["default"]).country('RUS');
|
21 | };
|
22 |
|
23 | thrower.should["throw"]('Unknown country');
|
24 | });
|
25 | it('should tell if a country is supported', function () {
|
26 | (0, _metadata.isSupportedCountry)('RU', _metadataMin["default"]).should.equal(true);
|
27 | (0, _metadata.isSupportedCountry)('XX', _metadataMin["default"]).should.equal(false);
|
28 | });
|
29 | it('should return ext prefix for a country', function () {
|
30 | (0, _metadata.getExtPrefix)('US', _metadataMin["default"]).should.equal(' ext. ');
|
31 | (0, _metadata.getExtPrefix)('CA', _metadataMin["default"]).should.equal(' ext. ');
|
32 | (0, _metadata.getExtPrefix)('GB', _metadataMin["default"]).should.equal(' x');
|
33 |
|
34 | (0, _metadata.getExtPrefix)('XX', _metadataMin["default"]).should.equal(' ext. ');
|
35 | });
|
36 | it('should cover non-occuring edge cases', function () {
|
37 | new _metadata["default"](_metadataMin["default"]).getNumberingPlanMetadata('999');
|
38 | });
|
39 | it('should support deprecated methods', function () {
|
40 | new _metadata["default"](_metadataMin["default"]).country('US').nationalPrefixForParsing().should.equal('1');
|
41 | new _metadata["default"](_metadataMin["default"]).chooseCountryByCountryCallingCode('1').nationalPrefixForParsing().should.equal('1');
|
42 | });
|
43 | it('should tell if a national prefix is mandatory when formatting a national number', function () {
|
44 | var meta = new _metadata["default"](_metadataMin["default"]);
|
45 |
|
46 |
|
47 | meta.country('US');
|
48 | meta.numberingPlan.formats()[0].nationalPrefixIsMandatoryWhenFormattingInNationalFormat().should.equal(false);
|
49 |
|
50 |
|
51 | meta.country('RU');
|
52 | meta.numberingPlan.formats()[0].nationalPrefixIsMandatoryWhenFormattingInNationalFormat().should.equal(false);
|
53 |
|
54 |
|
55 | meta.country('FR');
|
56 | meta.numberingPlan.formats()[0].nationalPrefixIsMandatoryWhenFormattingInNationalFormat().should.equal(true);
|
57 | });
|
58 | it('should validate metadata', function () {
|
59 | var thrower = function thrower() {
|
60 | return (0, _metadata.validateMetadata)();
|
61 | };
|
62 |
|
63 | thrower.should["throw"]('`metadata` argument not passed');
|
64 |
|
65 | thrower = function thrower() {
|
66 | return (0, _metadata.validateMetadata)(123);
|
67 | };
|
68 |
|
69 | thrower.should["throw"]('Got a number: 123.');
|
70 |
|
71 | thrower = function thrower() {
|
72 | return (0, _metadata.validateMetadata)('abc');
|
73 | };
|
74 |
|
75 | thrower.should["throw"]('Got a string: abc.');
|
76 |
|
77 | thrower = function thrower() {
|
78 | return (0, _metadata.validateMetadata)({
|
79 | a: true,
|
80 | b: 2
|
81 | });
|
82 | };
|
83 |
|
84 | thrower.should["throw"]('Got an object of shape: { a, b }.');
|
85 |
|
86 | thrower = function thrower() {
|
87 | return (0, _metadata.validateMetadata)({
|
88 | a: true,
|
89 | countries: 2
|
90 | });
|
91 | };
|
92 |
|
93 | thrower.should["throw"]('Got an object of shape: { a, countries }.');
|
94 |
|
95 | thrower = function thrower() {
|
96 | return (0, _metadata.validateMetadata)({
|
97 | country_calling_codes: true,
|
98 | countries: 2
|
99 | });
|
100 | };
|
101 |
|
102 | thrower.should["throw"]('Got an object of shape');
|
103 |
|
104 | thrower = function thrower() {
|
105 | return (0, _metadata.validateMetadata)({
|
106 | country_calling_codes: {},
|
107 | countries: 2
|
108 | });
|
109 | };
|
110 |
|
111 | thrower.should["throw"]('Got an object of shape');
|
112 | (0, _metadata.validateMetadata)({
|
113 | country_calling_codes: {},
|
114 | countries: {},
|
115 | b: 3
|
116 | });
|
117 | });
|
118 | });
|
119 |
|
120 | function type(something) {
|
121 | return _typeof(something);
|
122 | }
|
123 |
|
\ | No newline at end of file |