-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphone.test.js
190 lines (157 loc) · 5.49 KB
/
phone.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
const assert = require('assert');
const {
isPhone,
isFixed,
isMobile,
isFreeCall,
isLowCost,
isHighCost,
isOther,
statesByCode,
statesByNumber
} = require('./index');
describe('spain-phone', () => {
describe('isPhone', () => {
it('should return true if is a valid phone number', () => {
assert.ok(isPhone('907 11 11 11'));
});
it('should return false if is longer than 9 chars', () => {
assert.ok(!isPhone('907 11 11 11 11 11 11'));
});
it('should validate when the first char is a 9', () => {
assert.ok(isPhone('911 11 11 11'));
});
it('should validate when the first char is a 8', () => {
assert.ok(isPhone('811 11 11 11'));
});
it('should validate when the first char is a 7', () => {
assert.ok(isPhone('711 11 11 11'));
});
it('should validate when the first char is a 6', () => {
assert.ok(isPhone('611 11 11 11'));
});
it('should validate when the first char is a 5', () => {
assert.ok(isPhone('511 11 11 11'));
});
it('should not validate when the first char is a 0', () => {
assert.ok(!isPhone('011 11 11 11'));
});
it('should return true if it is either fixed or mobile phone', () => {
assert.ok(isPhone('511 11 11 11'));
assert.ok(isPhone('611 11 11 11'));
assert.ok(isPhone('711 11 11 11'));
assert.ok(isPhone('811 11 11 11'));
assert.ok(isPhone('911 11 11 11'));
});
it('should return false if it is neither fixed or mobile phone', () => {
assert.ok(!isPhone('011 11 11 11'));
assert.ok(!isPhone('111 11 11 11'));
assert.ok(!isPhone('211 11 11 11'));
assert.ok(!isPhone('311 11 11 11'));
assert.ok(!isPhone('411 11 11 11'));
});
});
describe('isFixed', () => {
it('should return true when it is a fixed phone number', () => {
assert.ok(isFixed('511 11 11 11'));
assert.ok(isFixed('811 11 11 11'));
assert.ok(isFixed('911 11 11 11'));
});
it('should return false if it does not have the correct length', () => {
assert.ok(!isFixed('511'));
assert.ok(!isFixed('811'));
assert.ok(!isFixed('911'));
});
});
describe('isMobile', () => {
it('should return true when it is a mobile phone number', () => {
assert.ok(isMobile('611 11 11 11'));
assert.ok(isMobile('711 11 11 11'));
});
it('should return false if it does not have the correct length', () => {
assert.ok(!isMobile('611'));
assert.ok(!isMobile('711'));
});
});
describe('isFreeCall', () => {
it('should return true if the it is a free call', () => {
assert.ok(isFreeCall('900 11 11 11'));
assert.ok(isFreeCall('800 11 11 11'));
});
it('should return false when it is not a free call', () => {
assert.ok(!isFreeCall('611 11 11 11'));
assert.ok(!isFreeCall('711 11 11 11'));
});
});
describe('isLowCost', () => {
it('should return true if it is a low cost call', () => {
assert.ok(isLowCost('901 11 11 11'));
assert.ok(isLowCost('902 11 11 11'));
});
it('should return false when it is not a low cost call', () => {
assert.ok(!isLowCost('900 11 11 11'));
assert.ok(!isLowCost('903 11 11 11'));
});
});
describe('isHighCost', () => {
it('should return true if it is a high cost call', () => {
assert.ok(isHighCost('905 11 11 11'));
assert.ok(isHighCost('907 11 11 11'));
assert.ok(isHighCost('803 11 11 11'));
assert.ok(isHighCost('806 11 11 11'));
assert.ok(isHighCost('807 11 11 11'));
});
it('should return true if it is not a high cost call', () => {
assert.ok(!isHighCost('901 11 11 11'));
assert.ok(!isHighCost('902 11 11 11'));
});
});
describe('isOther', () => {
it('should return true if it is other type of call', () => {
assert.ok(isOther('908 11 11 11'));
assert.ok(isOther('909 11 11 11'));
assert.ok(isOther('940 11 11 11'));
});
it('should return true if it is not other type of call', () => {
assert.ok(!isOther('901 11 11 11'));
assert.ok(!isOther('902 11 11 11'));
});
});
describe('statesByCode', () => {
it('should return two cities', () => {
assert.deepEqual(statesByCode('956'), ['Cádiz', 'Ceuta']);
});
it('should return Valencia', () => {
assert.deepEqual(statesByCode('960'), ['Valencia']);
});
it('should return Barcelona', () => {
assert.deepEqual(statesByCode('93'), ['Barcelona']);
});
it('should return Madrid', () => {
assert.deepEqual(statesByCode('91'), ['Madrid']);
});
it('should return an empty array when it does not find any match', () => {
assert.deepEqual(statesByCode('33'), []);
});
});
describe('statesByNumber', () => {
it('should return not return cities with partial numbers', () => {
assert.deepEqual(statesByNumber('956'), []);
});
it('should return two cities', () => {
assert.deepEqual(statesByNumber('956 26 26 08'), ['Cádiz', 'Ceuta']);
});
it('should return Valencia', () => {
assert.deepEqual(statesByNumber('960 11 11 11'), ['Valencia']);
});
it('should return Barcelona', () => {
assert.deepEqual(statesByNumber('934 58 78 60'), ['Barcelona']);
});
it('should return Madrid', () => {
assert.deepEqual(statesByNumber('915 91 38 56'), ['Madrid']);
});
it('should return an empty array when it does not find any match', () => {
assert.deepEqual(statesByNumber('333 91 38 56'), []);
});
});
});