common.js
1.42 KB
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
/* global describe it */
const should = require('should');
const common = require('../lib/common');
describe('#common', () => {
describe('#guessSuffix', () => {
it('should handle missing suffix', () => {
should.not.exist(common.guessSuffix('xxx'));
});
it('should return correct suffix', () => {
common.guessSuffix('xxx@yyy').should.equal('@yyy');
common.guessSuffix('xxx@yyy@zzz').should.equal('@zzz');
})
});
describe('#isPhoneNumber', () => {
it('should detect correctly', () => {
common.isPhoneNumber('0818').should.not.be.ok();
common.isPhoneNumber('62818').should.not.be.ok();
common.isPhoneNumber('+62818').should.not.be.ok();
common.isPhoneNumber('081808180').should.be.ok();
common.isPhoneNumber('62818818').should.be.ok();
common.isPhoneNumber('+62818818').should.be.ok();
common.isPhoneNumber('ada').should.not.be.ok();
});
});
describe('#indonesiaIntlNumberToZeroPrefix', () => {
it('should transform correctly', () => {
common.indonesiaIntlNumberToZeroPrefix('+6281812341234').should.equal('081812341234', '+6281812341234');
common.indonesiaIntlNumberToZeroPrefix('081808180').should.equal('081808180', '081808180');
common.indonesiaIntlNumberToZeroPrefix('ada').should.equal('ada');
});
})
});