-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathphone-test.js
79 lines (78 loc) · 3.62 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
const { Phone } = require('../index');
const { describe, it } = require('mocha');
const { expect } = require('chai');
describe('Phone Tools', () => {
describe('checkType', () => {
it('should be type of LANDLINE', () => {
expect(Phone.checkType('02188758709')).to.equal('LANDLINE');
expect(Phone.checkType('+985380001231')).to.equal('LANDLINE');
expect(Phone.checkType('00982545622298')).to.equal('LANDLINE');
expect(Phone.checkType('5489882332')).to.equal('LANDLINE');
expect(Phone.checkType('05332210998')).to.equal('LANDLINE');
});
it('should be type of MOBILE', () => {
expect(Phone.checkType('09128335993')).to.equal('MOBILE');
expect(Phone.checkType('+989128335993')).to.equal('MOBILE');
expect(Phone.checkType('00989128335993')).to.equal('MOBILE');
expect(Phone.checkType('9128335993')).to.equal('MOBILE');
expect(Phone.checkType('+989198920200')).to.equal('MOBILE');
});
it('should return false due to invalidity of numbers', () => {
expect(Phone.checkType('0912833599')).to.equal(false);
});
});
describe('isMobile', () => {
it('should be verified as mobile number', () => {
expect(Phone.isMobile('09128335993')).to.equal(true);
expect(Phone.isMobile('+989128335993')).to.equal(true);
expect(Phone.isMobile('00989128335993')).to.equal(true);
expect(Phone.isMobile('9128335993')).to.equal(true);
expect(Phone.isMobile('+989198920200')).to.equal(true);
});
it('should be not verified as mobile number', () => {
expect(Phone.isMobile('8128335993')).to.not.equal(true);
expect(Phone.isMobile('+98912833599')).to.not.equal(true);
expect(Phone.isMobile('009891283355')).to.not.equal(true);
expect(Phone.isMobile('+988128335993')).to.not.equal(true);
});
});
describe('isLandline', () => {
it('should be verified as landline number', () => {
expect(Phone.isLandline('02188758709')).to.equal(true);
expect(Phone.isLandline('+985380001231')).to.equal(true);
expect(Phone.isLandline('00982545622298')).to.equal(true);
expect(Phone.isLandline('5489882332')).to.equal(true);
expect(Phone.isLandline('05332210998')).to.equal(true);
});
});
describe('normalizeMobile', () => {
it('should be normalized', () => {
expect(Phone.normalizeMobile('+989128335993')).to.equal('9128335993');
expect(Phone.normalizeMobile('00989128335993')).to.equal('9128335993');
expect(Phone.normalizeMobile('09128335993')).to.equal('9128335993');
expect(Phone.normalizeMobile('9128335993')).to.equal('9128335993');
});
});
describe('normalizeLandline', () => {
it('should be normalized', () => {
expect(Phone.normalizeLandline('+982191001848')).to.equal('2191001848');
expect(Phone.normalizeLandline('982191001848')).to.equal('2191001848');
expect(Phone.normalizeLandline('00982191001848')).to.equal('2191001848');
expect(Phone.normalizeLandline('2191001848')).to.equal('2191001848');
expect(Phone.normalizeLandline('02191001848')).to.equal('2191001848');
});
});
describe('getProvinceData', () => {
it('should be Tehran', () => {
expect(Phone.getProvinceData(21).name).to.equal('Tehran');
expect(Phone.getProvinceData('TE').areaCode).to.equal(21);
});
});
describe('getProvincesFromLandline', () => {
it('should be Tehran', () => {
expect(Phone.getProvincesFromLandline('+982191001848').name).to.equal('Tehran');
expect(Phone.getProvincesFromLandline('982191001848').name).to.equal('Tehran');
expect(Phone.getProvincesFromLandline('00982191001848').name).to.equal('Tehran');
});
});
});