cie-calculator-flap
Version:
Easily generate CIE References
998 lines (851 loc) • 42.6 kB
JavaScript
'use strict';
var client = require('../../../main.js');
var CIECalculator = require('../../../lib/strategies/cie_calculator.js').CIECalculator;
var Alg00 = require('../../../lib/strategies/alg00.js').Alg00;
var Alg02 = require('../../../lib/strategies/alg02.js').Alg02;
var Alg03 = require('../../../lib/strategies/alg03.js').Alg03;
var Alg04 = require('../../../lib/strategies/alg04.js').Alg04;
var Alg06 = require('../../../lib/strategies/alg06.js').Alg06;
var Alg10 = require('../../../lib/strategies/alg10.js').Alg10;
var Alg11 = require('../../../lib/strategies/alg11.js').Alg11;
var Alg14 = require('../../../lib/strategies/alg14.js').Alg14;
var Alg21 = require('../../../lib/strategies/alg21.js').Alg21;
var Alg27 = require('../../../lib/strategies/alg27.js').Alg27;
var Alg35 = require('../../../lib/strategies/alg35.js').Alg35;
var Alg36 = require('../../../lib/strategies/alg36.js').Alg36;
var Alg37 = require('../../../lib/strategies/alg37.js').Alg37;
var Alg45 = require('../../../lib/strategies/alg45.js').Alg45;
var Alg62 = require('../../../lib/strategies/alg62.js').Alg62;
var Alg72 = require('../../../lib/strategies/alg72.js').Alg72;
var Alg77 = require('../../../lib/strategies/alg77.js').Alg77;
var Alg80 = require('../../../lib/strategies/alg80.js').Alg80;
var Alg81 = require('../../../lib/strategies/alg81.js').Alg81;
var Alg82 = require('../../../lib/strategies/alg82.js').Alg82;
var Alg89 = require('../../../lib/strategies/alg89.js').Alg89;
var Alg91 = require('../../../lib/strategies/alg91.js').Alg91;
var Alg94 = require('../../../lib/strategies/alg94.js').Alg94;
var calculator;
describe('main', function() {
it('should calculate the check digit', function(done) {
client({alg: '00', reference: '18000359700002387'}).should.eql('180003597000023871');
done();
});
});
describe('alg 00', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg00());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: '18000359700002387'}).should.eql('180003597000023871');
calculator.execute({reference: '123456789'}).should.eql('1234567897');
calculator.execute({reference: '0000001'}).should.eql('00000018');
calculator.execute({reference: '999999999999999999'}).should.eql('9999999999999999998');
calculator.execute({reference: '537639480322267'}).should.eql('5376394803222670');
calculator.execute({reference: '14009120311114'}).should.eql('140091203111141');
done();
});
it('should throw an error if length is longer than 19',function(done) {
(function() {
calculator.execute({reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({reference: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 02', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg02());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: '96060576JMG02158'}).should.eql('96060576JMG021582');
calculator.execute({reference: '14082076JM'}).should.eql('14082076JM3');
calculator.execute({reference: '00011772XXYA21'}).should.eql('00011772XXYA219');
calculator.execute({reference: '18081519058'}).should.eql('180815190582');
calculator.execute({reference: '18101415893'}).should.eql('181014158933');
calculator.execute({reference: '1808061764'}).should.eql('18080617642');
calculator.execute({reference: '18061017708'}).should.eql('180610177081');
calculator.execute({reference: '18071913261'}).should.eql('180719132615');
calculator.execute({reference: '18053092721'}).should.eql('180530927219');
calculator.execute({reference: '18112318653'}).should.eql('181123186536');
calculator.execute({reference: '18091814195'}).should.eql('180918141953');
done();
});
it('should accept lower case', function(done) {
calculator.execute({reference: '00011772xxya21'}).should.eql('00011772XXYA219');
done();
});
it('should throw an error if length is longer than 19',function(done) {
(function() {
calculator.execute({reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference length is less than 6',function(done) {
(function() {
calculator.execute({reference: '96060'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 03', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg03());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: '926314223'}).should.eql('9263142233');
calculator.execute({reference: '18000359700002387'}).should.eql('180003597000023873');
calculator.execute({reference: '123456789'}).should.eql('1234567893');
calculator.execute({reference: '001'}).should.eql('0015');
calculator.execute({reference: '999999999999999999'}).should.eql('9999999999999999992');
done();
});
it('should throw an error if length is longer than 19',function(done) {
(function() {
calculator.execute({reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({reference: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 04', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg04());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: '07680500000300070'}).should.eql('0768050000030007014');
calculator.execute({reference: '07680500000300071'}).should.eql('0768050000030007114');
calculator.execute({reference: '1'}).should.eql('140');
calculator.execute({reference: '198231223488'}).should.eql('19823122348856');
calculator.execute({reference: '50000327'}).should.eql('5000032708');
done();
});
it('should throw an error if length is longer than 18',function(done) {
(function() {
calculator.execute({reference: '1234567890123456789'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({reference: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 06', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg06());
});
it('should calculate the check digit', function(done) {
calculator.execute({branch: '870', account: '7654321',reference: '87654321'}).should.eql('8765432179');
done();
});
it('should throw an error if reference length is longer than 18',function(done) {
(function() {
calculator.execute({branch: '870', account: '7654321', reference: '1234567890123456789'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({branch: '870', account: '7654321', reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if branch is zero length',function(done) {
(function() {
calculator.execute({branch: '', account: '7654321', reference: '87654321'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if account is zero length',function(done) {
(function() {
calculator.execute({branch: '870', account: '', reference: '87654321'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 10', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg10());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '19112014', amount: '92832.32',reference: '121341234123'}).should.eql('12134123412303285214');
calculator.execute({date: '23052015', amount: '4256.50',reference: '067591119700'}).should.eql('06759111970005186229');
calculator.execute({date: '01012018', amount: '0.01',reference: '1'}).should.eql('114887233');
calculator.execute({date: '29072015', amount: '60.00',reference: '12010282'}).should.eql('1201028205862203');
done();
});
it('should throw an error if reference length is longer than 12',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '4256.50',reference: '0675911197001'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '4256.50',reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '',reference: '067591119700'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '4256.50',reference: '067591119700'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 11', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg11());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '10012020', amount: '5644.00',reference: '424PBALEON06'}).should.eql('424PBALEON0622415238');
calculator.execute({date: '20122021', amount: '250.00',reference: 'AF4562144029'}).should.eql('AF456214402929641282');
calculator.execute({date: '20102021', amount: '50.00',reference: 'BJ4562144148'}).should.eql('BJ456214414829025275');
calculator.execute({date: '15112021', amount: '100.00',reference: 'CR4562144148'}).should.eql('CR456214414829283219');
calculator.execute({date: '23112021', amount: '200.00',reference: 'DE4562144148'}).should.eql('DE456214414829366208');
calculator.execute({date: '24112021', amount: '300.00',reference: 'MZ4562144148'}).should.eql('MZ456214414829379219');
calculator.execute({date: '24012021', amount: '300.00',reference: 'AD4562144257'}).should.eql('AD456214425726279232');
calculator.execute({date: '15022021', amount: '310.00',reference: 'MG4562144257'}).should.eql('MG456214425726496258');
calculator.execute({date: '15012021', amount: '10.00',reference: 'UL4562144257'}).should.eql('UL456214425726187242');
calculator.execute({date: '20012021', amount: '110.00',reference: 'XO4562144257'}).should.eql('XO456214425726230272');
done();
});
it('should throw an error if reference length is longer than 12',function(done) {
(function() {
calculator.execute({date: '16082021', amount: '100.50',reference: '424PBALEON066'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '16082021', amount: '767.50',reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '16082021', amount: '',reference: '424PBALEON06'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '3434.50',reference: '424PBALEON06'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 14', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg14());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: '000SAR4280'}).should.eql('000SAR428013');
calculator.execute({reference: '11000SAR4280'}).should.eql('11000SAR428037');
calculator.execute({reference: '110AASAR4280'}).should.eql('110AASAR428073');
calculator.execute({reference: 'B100ASA04080'}).should.eql('B100ASA0408020');
calculator.execute({reference: 'B156ASA64080'}).should.eql('B156ASA6408096');
calculator.execute({reference: 'B9867SA64080'}).should.eql('B9867SA6408064');
done();
});
it('should throw an error if length is longer than 18',function(done) {
(function() {
calculator.execute({reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({reference: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 21', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg21());
});
it('should calculate the check digit', function(done) {
//calculator.execute({date: '24082015', amount: '235.00',reference: '000200730804'}).should.eql('00020073080406008486');
//calculator.execute({date: '24082018', amount: '190.00',reference: '11111111111'}).should.eql('1111111111116804243');
//calculator.execute({date: '18062018', amount: '3678.05',reference: '00191768'}).should.eql('0019176816123297');
//calculator.execute({date: '19102018', amount: '1.50',reference: '428972'}).should.eql('42897217283268');
//calculator.execute({date: '25052018', amount: '1.00',reference: '123456'}).should.eql('12345615883710');
calculator.execute({date: '04062018', amount: '248.99',reference: '12345678'}).should.eql('1234567815981141');
calculator.execute({date: '24092018', amount: '1.10',reference: '975163'}).should.eql('97516317115087');
calculator.execute({date: '27082018', amount: '1.40',reference: '138256'}).should.eql('13825616831998');
//calculator.execute({date: '11022020', amount: '1.16',reference: '910468'}).should.eql('91046821991263');
//calculator.execute({date: '08072018', amount: '1.20',reference: '643974'}).should.eql('64397416277357');
calculator.execute({date: '01082018', amount: '1256.89',reference: '123400456891'}).should.eql('12340045689116573297');
done();
});
it('should throw an error if reference length is longer than 20',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '4256.50',reference: '0675911197001128392012'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '4256.50',reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '',reference: '067591119700'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '4256.50',reference: '067591119700'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 27', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg27());
});
// TODO VAlidar resultado Alg 27
it('should calculate the check digit', function(done) {
calculator.execute({branch: '7006', account: '00863367',reference: 'NT001COBRO'}).should.eql('NT001COBRO31');
done();
});
it('should throw an error if reference length is longer than 18',function(done) {
(function() {
calculator.execute({branch: '7006', account: '00863367', reference: 'NT001C0BRO11111111111111111'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({branch: '7006', account: '00863367', reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if branch is zero length',function(done) {
(function() {
calculator.execute({branch: '', account: '00863367', reference: 'NT001C0BRO'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if account is zero length',function(done) {
(function() {
calculator.execute({branch: '7006', account: '', reference: 'NT001C0BRO'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 35', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg35());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: 'ANGELICABA1'}).should.eql('ANGELICABA18');
calculator.execute({reference: 'ALGOSHOT1234'}).should.eql('ALGOSHOT12343');
calculator.execute({reference: 'PUMBA81'}).should.eql('PUMBA819');
calculator.execute({reference: '49CQJA5A0QO8LVU'}).should.eql('49CQJA5A0QO8LVU0');
done();
});
it('should accept lower case', function(done) {
calculator.execute({reference: '00011772xxya21'}).should.eql('00011772XXYA213');
done();
});
it('should throw an error if length is longer than 19',function(done) {
(function() {
calculator.execute({reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference length is less than 1',function(done) {
(function() {
calculator.execute({reference: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 36', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg36());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: 'AZ00035RG00002L87'}).should.eql('AZ00035RG00002L871');
calculator.execute({reference: 'ALGOSHOT1234'}).should.eql('ALGOSHOT12349');
calculator.execute({reference: '123400001AXY'}).should.eql('123400001AXY0');
calculator.execute({reference: '123400001AXG'}).should.eql('123400001AXG0');
done();
});
it('should accept lower case', function(done) {
calculator.execute({reference: 'az00035sg00002l87'}).should.eql('AZ00035SG00002L879');
done();
});
it('should throw an error if length is longer than 19',function(done) {
(function() {
calculator.execute({reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference length is less than 1',function(done) {
(function() {
calculator.execute({reference: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 37', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg37());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: '0GFH0500000U000P0'}).should.eql('0GFH0500000U000P014');
calculator.execute({reference: '0GFH0500000U000P3'}).should.eql('0GFH0500000U000P314');
calculator.execute({reference: 'ALGOSHOT1234'}).should.eql('ALGOSHOT123407');
calculator.execute({reference: 'A001BZ12'}).should.eql('A001BZ1273');
done();
});
it('should accept lower case', function(done) {
calculator.execute({reference: '0gfh0500000u000p0'}).should.eql('0GFH0500000U000P014');
done();
});
it('should throw an error if length is longer than 18',function(done) {
(function() {
calculator.execute({reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference length is less than 1',function(done) {
(function() {
calculator.execute({reference: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 45', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg45());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '04082019', amount: '159.00', reference: 'PRU2345678'}).should.eql('PRU23456780VHV00C9O5');
calculator.execute({date: '20122021', amount: '250.00', reference: '0512345678'}).should.eql('05123456784B9H00JAG6');
calculator.execute({date: '20102021', amount: '50.00', reference: '4512045378'}).should.eql('45120453784B3X003UW0');
calculator.execute({date: '15112021', amount: '100.00', reference: '4512065371'}).should.eql('451206537138LT007PS1');
calculator.execute({date: '23112021', amount: '200.00', reference: '4512065371'}).should.eql('45120653714YC100FFK2');
calculator.execute({date: '24112021', amount: '300.00', reference: '4512065371'}).should.eql('4512065371561T00R080');
//calculator.execute({date: '20122021', amount: '2500.00',reference: '0512345678'}).should.eql('05123456784B9H00JAG6');
//calculator.execute({date: '20102021', amount: '150.00',reference: '4512045378'}).should.eql('45120453784B3X003UW0');
//calculator.execute({date: '15112021', amount: '300.00',reference: '4512065371'}).should.eql('451206537138LT007PS1');
//calculator.execute({date: '23112021', amount: '250.00',reference: '4512065371'}).should.eql('45120653714YC100FFK2');
//calculator.execute({date: '24112021', amount: '350.00',reference: '4512065371'}).should.eql('4512065371561T00R080');
//calculator.execute({date: '24012021', amount: '200.00',reference: '4512065371'}).should.eql('451206537155A100N5C6');
//calculator.execute({date: '15022021', amount: '310.00',reference: '4512065371'}).should.eql('451206537137WT00NX46');*
//calculator.execute({date: '15012021', amount: '10.00',reference: '4512065371'}).should.eql('451206537137U1000RS6');*
//calculator.execute({date: '20012021', amount: '110.00',reference: '4512065371'}).should.eql('45120653714AEX008HK2');*
//calculator.execute({date: '20122021', amount: '250.00',reference: '0512345678'}).should.eql('05123456784B9H00JAG5');
//calculator.execute({date: '20102021', amount: '50.00',reference: '4512045378'}).should.eql('45120453784B3X003UW1');
//calculator.execute({date: '15112021', amount: '100.00',reference: '4512065371'}).should.eql('451206537138LT007PS4');
//calculator.execute({date: '23112021', amount: '200.00',reference: '4512065371'}).should.eql('45120653714YC100FFK8');
//calculator.execute({date: '24112021', amount: '300.00',reference: '4512065371'}).should.eql('4512065371561T00R089');
done();
});
it('should accept lower case', function(done) {
calculator.execute({date: '04082019', amount: '159.00', reference: 'pru2345678'}).should.eql('PRU23456780VHV00C9O5');
done();
});
it('should throw an error if reference length is longer than 10',function(done) {
(function() {
calculator.execute({date: '04082019', amount: '159.00', reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date length is longer than 9',function(done) {
(function() {
calculator.execute({date: '104082019', amount: '159.00', reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount length is less than 1',function(done) {
(function() {
calculator.execute({date: '040820195', amount: '', reference: '12345678901234567890'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 62', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg62());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '23051997', amount: '845.15',reference: '0675911197'}).should.eql('067591119734946552');
done();
});
it('should throw an error if reference length is less than 1',function(done) {
(function() {
calculator.execute({date: '19112014', amount: '601.00',reference: '', digit: '2'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference length is greater than 10',function(done) {
(function() {
calculator.execute({date: '19112014', amount: '601.00',reference: '123456789012', digit: '2'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '4256.50',reference: '', digit: '1'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '',reference: '067591119700', digit: '1'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '4256.50',reference: '067591119700', digit: '1'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if var digit is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '4256.50',reference: '067591119700', digit: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 72', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg72());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '22022019', amount: '100.00', reference: 'DANIELPRUEBAINTELIGENTE40201420550107193'}).should.eql('DANIELPRUEBAINTELIGENTE402014205501071934PX7007PS3');
calculator.execute({date: '20122021', amount: '250.00', reference: '58640201420530107193'}).should.eql('586402014205301071934B9H00JAG5');
calculator.execute({date: '20102021', amount: '50.00', reference: '58640201420530407183'}).should.eql('586402014205304071834B3X003UW4');
calculator.execute({date: '15112021', amount: '100.00', reference: '58640201420530407183'}).should.eql('5864020142053040718338LT007PS0');
calculator.execute({date: '23112021', amount: '200.00', reference: '58640201420530407183'}).should.eql('586402014205304071834YC100FFK1');
calculator.execute({date: '24112021', amount: '300.00', reference: '58640201420530407183'}).should.eql('58640201420530407183561T00N5C3');
done();
});
it('should throw an error if reference length is longer than 40',function(done) {
(function() {
calculator.execute({date: '22022019', amount: '100.00',reference: 'DANIELPRUEBAINTELIGENTE402014205501071931'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '22022019', amount: '100.00',reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '22022019', amount: '',reference: 'DANIELPRUEBAINTELIGENTE40201420550107193'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '100.00',reference: 'DANIELPRUEBAINTELIGENTE40201420550107193'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 77', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg77());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '23052014', amount: '4256.50',reference: '067591119700'}).should.eql('06759111970005186229');
calculator.execute({date: '18082015', amount: '92832.32',reference: '121341234123'}).should.eql('12134123412309785253');
calculator.execute({date: '01012016', amount: '0.01',reference: '1'}).should.eql('111167288');
done();
});
it('should throw an error if reference length is longer than 12',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '4256.50',reference: '0675911197001'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '4256.50',reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '',reference: '067591119700'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '4256.50',reference: '067591119700'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 80', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg80());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: '5125890321479874531234567890123456789012342506928'}).should.eql('51258903214798745312345678901234567890123425069287');
calculator.execute({reference: '111034567890123456789012342506928'}).should.eql('1110345678901234567890123425069286');
calculator.execute({reference: '111034567890107456087012349996928'}).should.eql('1110345678901074560870123499969280');
calculator.execute({reference: '111034567890102426287212349996928'}).should.eql('1110345678901024262872123499969282');
calculator.execute({reference: '111034567890102426287200000000928'}).should.eql('1110345678901024262872000000009289');
calculator.execute({reference: '578034569890102426287200000000928'}).should.eql('5780345698901024262872000000009285');
done();
});
it('should throw an error if length is longer than 49',function(done) {
(function() {
calculator.execute({reference: '51258903214798745312345678901234567890123425069282333'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({reference: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 81', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg81());
});
it('should calculate the check digit', function(done) {
calculator.execute({reference: 'BANCOMERALFANUMERICO56732145921723849632584383921'}).should.eql('BANCOMERALFANUMERICO567321459217238496325843839211');
calculator.execute({reference: 'AAABBBCCC056730001111723849632584383921'}).should.eql('AAABBBCCC0567300011117238496325843839210');
calculator.execute({reference: 'AAABBBCCC056732145921723849632584383921'}).should.eql('AAABBBCCC0567321459217238496325843839215');
calculator.execute({reference: 'ABC000CCC056730001111723849632584383921'}).should.eql('ABC000CCC0567300011117238496325843839213');
calculator.execute({reference: '111000CCC056730001111723849632584383921'}).should.eql('111000CCC0567300011117238496325843839218');
calculator.execute({reference: 'FG1000CCC056730001111723849632584383921'}).should.eql('FG1000CCC0567300011117238496325843839211');
done();
});
it('should throw an error if length is longer than 49',function(done) {
(function() {
calculator.execute({reference: 'BANCOMERALFANUMERICO56732145921723849632584383921111'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({reference: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 82', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg82());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '19112014', amount: '601.00',reference: '123456789012345', digit: '2'}).should.eql('12345678901234503289251');
calculator.execute({date: '19112014', amount: '601.00',reference: 'ABCDE6789012345', digit: '2'}).should.eql('ABCDE678901234503289251');
calculator.execute({date: '10112015', amount: '184956215.69',reference: '111111111111111111111111111111111', digit: '9'}).should.eql('11111111111111111111111111111111106910903');
calculator.execute({date: '30072015', amount: '220.00',reference: '222222222222222222222222222222222', digit: '3'}).should.eql('22222222222222222222222222222222205870359');
calculator.execute({date: '15092015', amount: '1378.60',reference: 'ABC19692014LA278969458', digit: '6'}).should.eql('ABC19692014LA27896945806345673');
done();
});
it('should throw an error if reference length is less than 15',function(done) {
(function() {
calculator.execute({date: '19112014', amount: '601.00',reference: '12345', digit: '2'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference length is greater than 42',function(done) {
(function() {
calculator.execute({date: '19112014', amount: '601.00',reference: '1234567890123456789012345678901234567890123', digit: '2'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '4256.50',reference: '', digit: '1'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '23051997', amount: '',reference: '067591119700', digit: '1'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '4256.50',reference: '067591119700', digit: '1'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if var digit is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '4256.50',reference: '067591119700', digit: ''});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 89', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg89());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '04042016', amount: '250.25',reference: 'ABCDEFGHIJKLMNO123456789'}).should.eql('ABCDEFGHIJKLMNO12345678912122225');
calculator.execute({date: '20122021', amount: '250',reference: 'A521300598765126485667'}).should.eql('A52130059876512648566733361246');
calculator.execute({date: '20102021', amount: '50.00',reference: 'B421300598765126485223'}).should.eql('B42130059876512648522332745205');
calculator.execute({date: '15112021', amount: '100',reference: 'C421300598765126485211'}).should.eql('C42130059876512648521133003249');
calculator.execute({date: '23112021', amount: '200.00',reference: 'D421300598765126485211'}).should.eql('D42130059876512648521133086247');
calculator.execute({date: '24112021', amount: '300',reference: 'E421300598765126485256'}).should.eql('E42130059876512648525633099242');
calculator.execute({date: '24012021', amount: '300',reference: 'A421300598765126485256'}).should.eql('A42130059876512648525629999232');
calculator.execute({date: '15022021', amount: '310.00',reference: 'C421300598765126485256'}).should.eql('C42130059876512648525630216213');
calculator.execute({date: '15012021', amount: '10',reference: 'F421300598765126485259'}).should.eql('F42130059876512648525929907206');
calculator.execute({date: '20012021', amount: '110.00',reference: 'G421300598765126485259'}).should.eql('G42130059876512648525929950217');
done();
});
it('should throw an error if reference length is greater than 42',function(done) {
(function() {
calculator.execute({date: '04042016', amount: '250.25',reference: 'ABCDEFGHIJKLMNO1234567891111111111111111111111111111111111111'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '04042016', amount: '250.25',reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '04042016', amount: '',reference: 'ABCDEFGHIJKLMNO123456789'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '250.25',reference: 'ABCDEFGHIJKLMNO123456789'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 91', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg91());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '11082014', amount: '224.00',reference: 'ESTADODEMEXICOUAEM'}).should.eql('ESTADODEMEXICOUAEM05994284');
calculator.execute({date: '17102021', amount: '200',reference: '1134000EMPRESA00000000111'}).should.eql('1134000EMPRESA0000000011132716291');
calculator.execute({date: '17102021', amount: '100.00',reference: '1134000EMPRESA00000000233'}).should.eql('1134000EMPRESA0000000023332713234');
calculator.execute({date: '20112021', amount: '100',reference: '4524110EMPRESA00000002233'}).should.eql('4524110EMPRESA0000000223333053271');
calculator.execute({date: '20112021', amount: '50.00',reference: '4524110EMPRESA23300002233'}).should.eql('4524110EMPRESA2330000223333055231');
done();
});
it('should throw an error if reference length is greater than 42',function(done) {
(function() {
calculator.execute({date: '11082014', amount: '224',reference: 'ESTADODEMEXICOUAEM4554445454545455545454565464'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '11082014', amount: '224',reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '11082014', amount: '',reference: 'ESTADODEMEXICOUAEM'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '224',reference: 'ESTADODEMEXICOUAEM'});
}).should.throw('Longitud invalida');
done();
});
});
describe('alg 94', function() {
beforeEach(function() {
calculator = new CIECalculator();
calculator.setStrategy(new Alg94());
});
it('should calculate the check digit', function(done) {
calculator.execute({date: '03072019', amount: '25739.00',reference: '888300519788'}).should.eql('88830051978824200264');
calculator.execute({date: '20122021', amount: '250',reference: '888300519788'}).should.eql('88830051978833361289');
calculator.execute({date: '20102021', amount: '50.00',reference: '150246519788'}).should.eql('15024651978832745269');
calculator.execute({date: '15112021', amount: '100',reference: '150246519345'}).should.eql('15024651934533003270');
calculator.execute({date: '23112021', amount: '200.00',reference: '480249519345'}).should.eql('48024951934533086295');
calculator.execute({date: '24112021', amount: '300',reference: '480560519345'}).should.eql('48056051934533099208');
done();
});
it('should throw an error if reference length is greater than 42',function(done) {
(function() {
calculator.execute({date: '03072019', amount: '25739.00',reference: '8883005197885666666666666666666666788888882324'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if reference is zero length',function(done) {
(function() {
calculator.execute({date: '03072019', amount: '25739.00',reference: ''});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if amount is zero length',function(done) {
(function() {
calculator.execute({date: '03072019', amount: '',reference: '888300519788'});
}).should.throw('Longitud invalida');
done();
});
it('should throw an error if date is zero length',function(done) {
(function() {
calculator.execute({date: '', amount: '25739.00',reference: '888300519788'});
}).should.throw('Longitud invalida');
done();
});
});