Commit 6e06b9261fd486fe042a35bd49c807e27cd48353

Authored by Adhidarma Hadiwinoto
1 parent afd80f70b8
Exists in master

ESLINT: global describe and it

Showing 1 changed file with 2 additions and 0 deletions Inline Diff

1 "use strict"; 1 "use strict";
2 2
3 /* global describe it */
4
3 const should = require('should'); 5 const should = require('should');
4 6
5 const st24 = require('./lib/st24'); 7 const st24 = require('./lib/st24');
6 8
7 describe('#st24', function() { 9 describe('#st24', function() {
8 10
9 describe('#extractSnFromMessage', function() { 11 describe('#extractSnFromMessage', function() {
10 12
11 describe('#using default st24 rule', function() { 13 describe('#using default st24 rule', function() {
12 it('should return correct sn from topUpRequest response', function() { 14 it('should return correct sn from topUpRequest response', function() {
13 st24.extractSnFromMessage('SN=0419165234155980102;19/04/18 16:52 ISI TR5 KE 0895621829255, SUKSES.SAL=1.323.934,HRG=5.250,ID=46398092,SN=0419165234155980102; ..trx lancar').should.equal('0419165234155980102'); 15 st24.extractSnFromMessage('SN=0419165234155980102;19/04/18 16:52 ISI TR5 KE 0895621829255, SUKSES.SAL=1.323.934,HRG=5.250,ID=46398092,SN=0419165234155980102; ..trx lancar').should.equal('0419165234155980102');
14 }) 16 })
15 17
16 it('should return correct sn from topUpInquiry response', function() { 18 it('should return correct sn from topUpInquiry response', function() {
17 st24.extractSnFromMessage('19/07/18 20:53 ISI SPT20 KE 081264858057, SUKSES.SAL=828.425,HRG=19.700,ID=48761021,SN=0041002635369521;').should.equal('0041002635369521'); 19 st24.extractSnFromMessage('19/07/18 20:53 ISI SPT20 KE 081264858057, SUKSES.SAL=828.425,HRG=19.700,ID=48761021,SN=0041002635369521;').should.equal('0041002635369521');
18 }) 20 })
19 }) 21 })
20 22
21 describe('#using custom rule', function() { 23 describe('#using custom rule', function() {
22 const custom_rule = { 24 const custom_rule = {
23 pattern: 'SN=(.*?)\\.', 25 pattern: 'SN=(.*?)\\.',
24 match_idx: 1 26 match_idx: 1
25 } 27 }
26 28
27 it('should return correct sn', function() { 29 it('should return correct sn', function() {
28 st24.extractSnFromMessage('ISI Telkomsel 10 ke 085261208081 BERHASIL.SN=0041002310111470.HRG=10035.SALDO=54489150', custom_rule).should.equal('0041002310111470'); 30 st24.extractSnFromMessage('ISI Telkomsel 10 ke 085261208081 BERHASIL.SN=0041002310111470.HRG=10035.SALDO=54489150', custom_rule).should.equal('0041002310111470');
29 31
30 }) 32 })
31 33
32 it('should return null on message not containing sn', function() { 34 it('should return null on message not containing sn', function() {
33 should.not.exists(st24.extractSnFromMessage('ISI Ke 081311084419 GAGAL.TRXID=20180403123020042979', custom_rule)); 35 should.not.exists(st24.extractSnFromMessage('ISI Ke 081311084419 GAGAL.TRXID=20180403123020042979', custom_rule));
34 }) 36 })
35 37
36 it('should return null on message empty sn', function() { 38 it('should return null on message empty sn', function() {
37 should.not.exists(st24.extractSnFromMessage('ISI Telkomsel 10 ke 085261208081 BERHASIL.SN=.HRG=10035.SALDO=54489150', custom_rule)); 39 should.not.exists(st24.extractSnFromMessage('ISI Telkomsel 10 ke 085261208081 BERHASIL.SN=.HRG=10035.SALDO=54489150', custom_rule));
38 }) 40 })
39 }) 41 })
40 }) 42 })
41 43
42 describe('#extractBalanceFromMsg', function() { 44 describe('#extractBalanceFromMsg', function() {
43 describe('using native ST24 response', function() { 45 describe('using native ST24 response', function() {
44 it('should return correct balance', function() { 46 it('should return correct balance', function() {
45 st24.extractBalanceFromMsg('SN=0516150344145563101; 16/05/18 15:03 ISI TR5 KE 0895350249796, SUKSES.SAL=426.078,HRG=5.250,ID=47285513,SN=0516150344145563101; ..trx lancar').should.equal(426078); 47 st24.extractBalanceFromMsg('SN=0516150344145563101; 16/05/18 15:03 ISI TR5 KE 0895350249796, SUKSES.SAL=426.078,HRG=5.250,ID=47285513,SN=0516150344145563101; ..trx lancar').should.equal(426078);
46 st24.extractBalanceFromMsg('15/05/18 17:19 ISI SAN10 KE 08535686667, NOMOR YANG ANDA MASUKKAN SALAH, MOHON TELITI KEMBALI..SAL=1.144.578,ID=47250459, ..trx lancar').should.equal(1144578) 48 st24.extractBalanceFromMsg('15/05/18 17:19 ISI SAN10 KE 08535686667, NOMOR YANG ANDA MASUKKAN SALAH, MOHON TELITI KEMBALI..SAL=1.144.578,ID=47250459, ..trx lancar').should.equal(1144578)
47 }) 49 })
48 50
49 it('should return null if there is no balance info', function() { 51 it('should return null if there is no balance info', function() {
50 should.not.exists(st24.extractBalanceFromMsg('PENGECEKAN GAGAL')); 52 should.not.exists(st24.extractBalanceFromMsg('PENGECEKAN GAGAL'));
51 }) 53 })
52 }) 54 })
53 55
54 describe('using custom rule', function() { 56 describe('using custom rule', function() {
55 const custom_rule = { 57 const custom_rule = {
56 pattern: "SALDO=(\\d+)", 58 pattern: "SALDO=(\\d+)",
57 match_idx: 1 59 match_idx: 1
58 } 60 }
59 61
60 it('should return correct balance', function() { 62 it('should return correct balance', function() {
61 st24.extractBalanceFromMsg('ISI Telkomsel 10 ke 082139822309 BERHASIL.SN=0041002442595407.HRG=10400.SALDO=104911920', custom_rule).should.equal(104911920); 63 st24.extractBalanceFromMsg('ISI Telkomsel 10 ke 082139822309 BERHASIL.SN=0041002442595407.HRG=10400.SALDO=104911920', custom_rule).should.equal(104911920);
62 }) 64 })
63 65
64 it('should return null if there is no balance info', function() { 66 it('should return null if there is no balance info', function() {
65 should.not.exists(st24.extractBalanceFromMsg('ISI Ke 08523548915 GAGAL.TRXID=20180516123010017371', custom_rule)) 67 should.not.exists(st24.extractBalanceFromMsg('ISI Ke 08523548915 GAGAL.TRXID=20180516123010017371', custom_rule))
66 }) 68 })
67 }) 69 })
68 }) 70 })
69 71
70 describe('#extractPriceFromMsg', function() { 72 describe('#extractPriceFromMsg', function() {
71 describe('using native ST24 topUpRequest direct response', function() { 73 describe('using native ST24 topUpRequest direct response', function() {
72 it('should return correct price', function() { 74 it('should return correct price', function() {
73 st24.extractPriceFromMsg('SN=0041002635395450;;19/07/18 21:01 ISI SPT20 KE 08125100091, SUKSES. SAL=798.500,HRG=19.700,ID=48761075,SN=0041002635395450;; ..trx lancar').should.equal(19700); 75 st24.extractPriceFromMsg('SN=0041002635395450;;19/07/18 21:01 ISI SPT20 KE 08125100091, SUKSES. SAL=798.500,HRG=19.700,ID=48761075,SN=0041002635395450;; ..trx lancar').should.equal(19700);
74 st24.extractPriceFromMsg('SN=0516150344145563101; 16/05/18 15:03 ISI TR5 KE 0895350249796, SUKSES.SAL=426.078,HRG=5.250,ID=47285513,SN=0516150344145563101; ..trx lancar').should.equal(5250); 76 st24.extractPriceFromMsg('SN=0516150344145563101; 16/05/18 15:03 ISI TR5 KE 0895350249796, SUKSES.SAL=426.078,HRG=5.250,ID=47285513,SN=0516150344145563101; ..trx lancar').should.equal(5250);
75 }); 77 });
76 }) 78 })
77 79
78 describe('using native ST24 topUpInquiry response', function() { 80 describe('using native ST24 topUpInquiry response', function() {
79 it('should return correct price', function() { 81 it('should return correct price', function() {
80 st24.extractPriceFromMsg('19/07/18 20:53 ISI SPT20 KE 081264858057, SUKSES.SAL=828.425,HRG=19.700,ID=48761021,SN=0041002635369521;').should.equal(19700); 82 st24.extractPriceFromMsg('19/07/18 20:53 ISI SPT20 KE 081264858057, SUKSES.SAL=828.425,HRG=19.700,ID=48761021,SN=0041002635369521;').should.equal(19700);
81 }) 83 })
82 }) 84 })
83 }) 85 })
84 86
85 }) 87 })
86 88