common.js 1.42 KB
/* 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');
        });
    })
});