58 lines
2.4 KiB
JavaScript
58 lines
2.4 KiB
JavaScript
|
/**
|
||
|
* Unit testing file for anon
|
||
|
*/
|
||
|
'use strict';
|
||
|
/* eslint max-nested-callbacks: ["error", 7] */
|
||
|
// eslint-disable-next-line no-unused-vars
|
||
|
const testGlobals = require('../../tools/test/testGlobals.js');
|
||
|
const chai = require('chai');
|
||
|
const sinonChai = require('sinon-chai');
|
||
|
const rewire = require('rewire');
|
||
|
|
||
|
/**
|
||
|
* Use `rewire` instead of require so that we can access private functions for test
|
||
|
*/
|
||
|
const anon = rewire('../anon.js');
|
||
|
|
||
|
const expect = chai.expect;
|
||
|
chai.use(sinonChai);
|
||
|
|
||
|
describe('anon functions', () => {
|
||
|
describe('call anonymiseWorldpayService', () => {
|
||
|
it('anonymises a standard serviceKey', () => {
|
||
|
const result = anon.anonymiseWorldpayServiceKey('T_S_713d2a60-a20b-4047-bc3a-3e863a11e414');
|
||
|
|
||
|
return expect(result).to.deep.equal('T_S_********-****-****-****-********e414');
|
||
|
});
|
||
|
it('throws when service key is not set', () => {
|
||
|
return expect(() => anon.anonymiseWorldpayServiceKey(undefined)).to.throw('service key not set');
|
||
|
});
|
||
|
it('throws when service key is not a valid worldpay service key (invalid patttern)', () => {
|
||
|
return expect(() => anon.anonymiseWorldpayServiceKey('T_A_713d2a60-a20b-4047-bc3a-3e863a11e414')).to.throw('service key not consistent with a Worldpay service key');
|
||
|
});
|
||
|
it('throws when service key is not a valid worldpay service key (to short)', () => {
|
||
|
return expect(() => anon.anonymiseWorldpayServiceKey('T_S_713d2a60-a20b-4047-bc3a')).to.throw('service key not consistent with a Worldpay service key');
|
||
|
});
|
||
|
});
|
||
|
describe('call anonymiseCardPAN', () => {
|
||
|
it('anonymises a standard cardPAN', () => {
|
||
|
const result = anon.anonymiseCardPAN('0000111122223333');
|
||
|
|
||
|
return expect(result).to.deep.equal('0*** **** **** *333');
|
||
|
});
|
||
|
it('anonymises a standard cardPAN with spaces', () => {
|
||
|
const result = anon.anonymiseCardPAN('0000 1111 2222 3333');
|
||
|
|
||
|
return expect(result).to.deep.equal('0*** **** **** *333');
|
||
|
});
|
||
|
it('anonymises a short cardPAN', () => {
|
||
|
const result = anon.anonymiseCardPAN('0000');
|
||
|
|
||
|
return expect(result).to.deep.equal('0000');
|
||
|
});
|
||
|
it('throws when card PAN is not set', () => {
|
||
|
return expect(() => anon.anonymiseCardPAN(undefined)).to.throw('cardPAN not set');
|
||
|
});
|
||
|
});
|
||
|
});
|