Commit 1c28ac0424506cff01f74c3d47471f2711b41e1a

Authored by Adhidarma Hadiwinoto
1 parent 31176ea6bc
Exists in master

Update parsing untuk tajir reload

Showing 2 changed files with 17 additions and 1 deletions Inline Diff

1 "use strict"; 1 "use strict";
2 2
3 const rcFromMsg = require('komodo-sdk/rc-from-msg'); 3 const rcFromMsg = require('komodo-sdk/rc-from-msg');
4 const organicRc = require('./rc'); 4 const organicRc = require('./rc');
5 5
6 function isInquiryResponseMessage(msg) { 6 function isInquiryResponseMessage(msg) {
7 return (msg || '').indexOf('CEK TAGIHAN') >= 0; 7 return (msg || '').indexOf('CEK TAGIHAN') >= 0;
8 } 8 }
9 9
10 function isPaymentResponseMessage(msg) { 10 function isPaymentResponseMessage(msg) {
11 return (msg || '').indexOf('BAYAR TAGIHAN') >= 0; 11 return (msg || '').indexOf('BAYAR TAGIHAN') >= 0;
12 } 12 }
13 13
14 function isPostpaidResponseMessage(msg) { 14 function isPostpaidResponseMessage(msg) {
15 return isInquiryResponseMessage(msg) || isPaymentResponseMessage(msg); 15 return isInquiryResponseMessage(msg) || isPaymentResponseMessage(msg);
16 } 16 }
17 17
18 function getRcFromMessage(msg, customRc) { 18 function getRcFromMessage(msg, customRc) {
19 let rc; 19 let rc;
20 if (customRc && Array.isArray(customRc) && customRc.length) { 20 if (customRc && Array.isArray(customRc) && customRc.length) {
21 rc = rcFromMsg(msg, customRc); 21 rc = rcFromMsg(msg, customRc);
22 } 22 }
23 23
24 if (!rc) { 24 if (!rc) {
25 rc = rcFromMsg(msg, organicRc); 25 rc = rcFromMsg(msg, organicRc);
26 } 26 }
27 27
28 return rc; 28 return rc;
29 } 29 }
30 30
31 function getPriceFromMessage(msg, rule) { 31 function getPriceFromMessage(msg, rule) {
32 if (typeof msg !== 'string') { 32 if (typeof msg !== 'string') {
33 return; 33 return;
34 } 34 }
35 35
36 if (process.env.DEBUG_IRS && !rule) { 36 if (process.env.DEBUG_IRS && !rule) {
37 console.log('** IRS.getPriceFromMessage no rule'); // eslint-disable-line no-console 37 console.log('** IRS.getPriceFromMessage no rule'); // eslint-disable-line no-console
38 } 38 }
39 39
40 if (process.env.DEBUG_IRS && rule) { 40 if (process.env.DEBUG_IRS && rule) {
41 console.log('** IRS.getPriceFromMessage rule: ' + JSON.stringify(rule, null, 2)); // eslint-disable-line no-console 41 console.log('** IRS.getPriceFromMessage rule: ' + JSON.stringify(rule, null, 2)); // eslint-disable-line no-console
42 } 42 }
43 43
44 //const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "Harga: ([\\d\\.]+?) "; 44 //const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "Harga: ([\\d\\.]+?) ";
45 const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "\\d+\\s+-\\s+([\\d,\\.]+)\\s+="; 45 const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "\\d+\\s+-\\s+([\\d,\\.]+)\\s+=";
46 const match_idx = (rule && typeof rule.match_idx === 'number') ? rule.match_idx : 1; 46 const match_idx = (rule && typeof rule.match_idx === 'number') ? rule.match_idx : 1;
47 47
48 const re = new RegExp(pattern); 48 const re = new RegExp(pattern);
49 const matches = msg.match(re); 49 const matches = msg.match(re);
50 if (process.env.DEBUG_IRS) { 50 if (process.env.DEBUG_IRS) {
51 console.log('** IRS.getPriceFromMessage msg: "' + msg + '" active_pattern: "' + pattern + '" active_match_idx: ' + match_idx); // eslint-disable-line no-console 51 console.log('** IRS.getPriceFromMessage msg: "' + msg + '" active_pattern: "' + pattern + '" active_match_idx: ' + match_idx); // eslint-disable-line no-console
52 console.log('** IRS.getPriceFromMessage matches:\n' + JSON.stringify(matches)); // eslint-disable-line no-console 52 console.log('** IRS.getPriceFromMessage matches:\n' + JSON.stringify(matches)); // eslint-disable-line no-console
53 } 53 }
54 54
55 if (matches && matches[match_idx]) { 55 if (matches && matches[match_idx]) {
56 const result = Number(matches[match_idx].replace(/\./g, '')); 56 const result = Number(matches[match_idx].replace(/\./g, ''));
57 if (process.env.DEBUG_IRS) { 57 if (process.env.DEBUG_IRS) {
58 console.log('** IRS.getPriceFromMessage SUPPLIER-PRICE: ' + result); // eslint-disable-line no-console 58 console.log('** IRS.getPriceFromMessage SUPPLIER-PRICE: ' + result); // eslint-disable-line no-console
59 } 59 }
60 return result; 60 return result;
61 } 61 }
62 } 62 }
63 63
64 function extractFromMessage(msg, rule) { 64 function extractFromMessage(msg, rule) {
65 if (typeof msg !== 'string') { return; } 65 if (typeof msg !== 'string') { return; }
66 66
67 if (!rule) { return; } 67 if (!rule) { return; }
68 68
69 if (typeof rule !== 'object') { 69 if (typeof rule !== 'object') {
70 return; 70 return;
71 } 71 }
72 72
73 rule.match_idx = Number(rule.match_idx); 73 rule.match_idx = Number(rule.match_idx);
74 74
75 if (!rule.match_idx) { 75 if (!rule.match_idx) {
76 rule.match_idx = 1; 76 rule.match_idx = 1;
77 } 77 }
78 78
79 const re = new RegExp(rule.pattern); 79 const re = new RegExp(rule.pattern);
80 const matches = msg.match(re); 80 const matches = msg.match(re);
81 if (matches && matches[rule.match_idx] && typeof matches[rule.match_idx] === 'string') { 81 if (matches && matches[rule.match_idx] && typeof matches[rule.match_idx] === 'string') {
82 return matches[rule.match_idx]; 82 return matches[rule.match_idx];
83 } 83 }
84 } 84 }
85 85
86 function getSnFromMessage(msg, rule) { 86 function getSnFromMessage(msg, rule) {
87 if (!rule) { 87 if (!rule) {
88 rule = { 88 rule = {
89 pattern: "[: ]S/*N:\\s*(.+?)\\s", 89 pattern: "[: ]S/*N:\\s*(.+?)\\s",
90 match_idx: 1 90 match_idx: 1
91 } 91 }
92 } 92 }
93 93
94 let sn = extractFromMessage(msg, rule); 94 let sn = extractFromMessage(msg, rule);
95 if (!sn || typeof sn !== 'string') { return; } 95 if (!sn || typeof sn !== 'string') { return; }
96 96
97 return sn.toUpperCase().replace(/[^a-zA-Z0-9:,/]/g, '-').replace(/-+/g, '-').replace(/-*\/-*/g, '/').replace(/^-+/, '').replace(/-+$/, ''); 97 return sn.toUpperCase().replace(/[^a-zA-Z0-9:,/]/g, '-').replace(/-+/g, '-').replace(/-*\/-*/g, '/').replace(/^-+/, '').replace(/-+$/, '');
98 } 98 }
99 99
100 function getBalanceFromMessage(msg, rule) { 100 function getBalanceFromMessage(msg, rule) {
101 if (!rule) { 101 if (!rule) {
102 rule = { 102 rule = {
103 pattern: "Sisa Saldo: .+? = ([\\d\\.]+) ", 103 pattern: "Saldo: .+? = ([\\d\\.]+) ",
104 match_idx: 1 104 match_idx: 1
105 } 105 }
106 } 106 }
107 107
108 let result = extractFromMessage(msg, rule); 108 let result = extractFromMessage(msg, rule);
109 if (!result || typeof result !== 'string') { return; } 109 if (!result || typeof result !== 'string') { return; }
110 110
111 return Number(result.replace(/\./g, '')); 111 return Number(result.replace(/\./g, ''));
112 } 112 }
113 113
114 function getDetailFromMessage(msg, rule) { 114 function getDetailFromMessage(msg, rule) {
115 if (!rule) { 115 if (!rule) {
116 rule = { 116 rule = {
117 pattern: " Detail:\\s*(.+?)\\s+Sisa [Ss]aldo", 117 pattern: " Detail:\\s*(.+?)\\s+Sisa [Ss]aldo",
118 match_idx: 1, 118 match_idx: 1,
119 } 119 }
120 } 120 }
121 121
122 let result = extractFromMessage(msg, rule); 122 let result = extractFromMessage(msg, rule);
123 return (result || '').trim(); 123 return (result || '').trim();
124 } 124 }
125 125
126 function splitPostpaidDetail(str) { 126 function splitPostpaidDetail(str) {
127 const retval = (str || '') 127 const retval = (str || '')
128 .split('/') 128 .split('/')
129 .map((item) => { 129 .map((item) => {
130 let [keyword, value] = item.split(':'); 130 let [keyword, value] = item.split(':');
131 keyword = (keyword || '').trim() 131 keyword = (keyword || '').trim()
132 132
133 if (keyword === 'N') keyword = 'SN'; 133 if (keyword === 'N') keyword = 'SN';
134 134
135 return { 135 return {
136 keyword, 136 keyword,
137 value: (value || '').trim(), 137 value: (value || '').trim(),
138 }; 138 };
139 }) 139 })
140 .filter((item) => item.keyword.length && item.value.length); 140 .filter((item) => item.keyword.length && item.value.length);
141 return retval; 141 return retval;
142 } 142 }
143 143
144 function calculateBaseBillAmount(detailSplitted, customKeywords) { 144 function calculateBaseBillAmount(detailSplitted, customKeywords) {
145 const keywords = customKeywords || ['TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA']; 145 const keywords = customKeywords || ['TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA'];
146 146
147 let retval = 0; 147 let retval = 0;
148 let detailCount = (detailSplitted || []).length; 148 let detailCount = (detailSplitted || []).length;
149 149
150 for (let i = 0; i < detailCount; i += 1) { 150 for (let i = 0; i < detailCount; i += 1) {
151 const item = detailSplitted[i]; 151 const item = detailSplitted[i];
152 if (keywords.indexOf(item.keyword.toUpperCase()) >= 0) { 152 if (keywords.indexOf(item.keyword.toUpperCase()) >= 0) {
153 const value = (item.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''); 153 const value = (item.value || '').trim().replace(/^rp */i, '').replace(/\./g, '');
154 retval += Number(value) || 0; 154 retval += Number(value) || 0;
155 } 155 }
156 } 156 }
157 157
158 return retval; 158 return retval;
159 } 159 }
160 160
161 function getBillCount(msg) { 161 function getBillCount(msg) {
162 const matches = (msg || '').match(/JMLBLN:(\d+)BLN/); 162 const matches = (msg || '').match(/JMLBLN:(\d+)BLN/);
163 return (matches && Number(matches[1])) || null; 163 return (matches && Number(matches[1])) || null;
164 } 164 }
165 165
166 exports.getRcFromMessage = getRcFromMessage; 166 exports.getRcFromMessage = getRcFromMessage;
167 exports.getPriceFromMessage = getPriceFromMessage; 167 exports.getPriceFromMessage = getPriceFromMessage;
168 exports.getSnFromMessage = getSnFromMessage; 168 exports.getSnFromMessage = getSnFromMessage;
169 exports.getBalanceFromMessage = getBalanceFromMessage; 169 exports.getBalanceFromMessage = getBalanceFromMessage;
170 exports.isInquiryResponseMessage = isInquiryResponseMessage; 170 exports.isInquiryResponseMessage = isInquiryResponseMessage;
171 exports.isPaymentResponseMessage = isPaymentResponseMessage; 171 exports.isPaymentResponseMessage = isPaymentResponseMessage;
172 exports.isPostpaidResponseMessage = isPostpaidResponseMessage; 172 exports.isPostpaidResponseMessage = isPostpaidResponseMessage;
173 exports.getDetailFromMessage = getDetailFromMessage; 173 exports.getDetailFromMessage = getDetailFromMessage;
174 exports.splitPostpaidDetail = splitPostpaidDetail; 174 exports.splitPostpaidDetail = splitPostpaidDetail;
175 exports.calculateBaseBillAmount = calculateBaseBillAmount; 175 exports.calculateBaseBillAmount = calculateBaseBillAmount;
176 exports.getBillCount = getBillCount; 176 exports.getBillCount = getBillCount;
177 177
1 /* global describe it */ 1 /* global describe it */
2 2
3 //process.env.KOMODO_SDK_DEBUG_RC_FROM_MSG = 'YES'; 3 //process.env.KOMODO_SDK_DEBUG_RC_FROM_MSG = 'YES';
4 4
5 const should = require('should'); 5 const should = require('should');
6 const irs = require('../index'); 6 const irs = require('../index');
7 7
8 describe('#irs', function() { 8 describe('#irs', function() {
9 describe('#getRcFromMessage', function() { 9 describe('#getRcFromMessage', function() {
10 it('should return correct rc', function() { 10 it('should return correct rc', function() {
11 irs.getRcFromMessage('Request IBP25 ke 085736328877 under proses..').should.equal('68'); 11 irs.getRcFromMessage('Request IBP25 ke 085736328877 under proses..').should.equal('68');
12 irs.getRcFromMessage('Transaksi HX5 ke 081809903333 GAGAL. Mohon periksa kembali No tujuan sebelum di ulang. Saldo: Rp 26.857.538').should.equal('40'); 12 irs.getRcFromMessage('Transaksi HX5 ke 081809903333 GAGAL. Mohon periksa kembali No tujuan sebelum di ulang. Saldo: Rp 26.857.538').should.equal('40');
13 irs.getRcFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal('00'); 13 irs.getRcFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal('00');
14 14
15 irs.getRcFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal('00', 'postpaid inquiry success'); 15 irs.getRcFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal('00', 'postpaid inquiry success');
16 irs.getRcFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal('00', 'postpaid payment success'); 16 irs.getRcFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal('00', 'postpaid payment success');
17 17
18 irs.getRcFromMessage('Maaf Produk sedang gangguan').should.equal('90'); 18 irs.getRcFromMessage('Maaf Produk sedang gangguan').should.equal('90');
19 }); 19 });
20 }); 20 });
21 21
22 describe('#getPriceFromMessage', function() { 22 describe('#getPriceFromMessage', function() {
23 describe('#generic', function() { 23 describe('#generic', function() {
24 it('should return correct price', function() { 24 it('should return correct price', function() {
25 irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal(24475); 25 irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal(24475);
26 }); 26 });
27 27
28 it('should handle postpaid response', () => { 28 it('should handle postpaid response', () => {
29 irs.getPriceFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal(0, 'postpaid inquiry succces'); 29 irs.getPriceFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal(0, 'postpaid inquiry succces');
30 irs.getPriceFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal(17741, 'postpaid payment success'); 30 irs.getPriceFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal(17741, 'postpaid payment success');
31 irs.getPriceFromMessage('REFF#562126 BAYAR TAGIHAN PLN25 SUKSES IDPEL:172000147469 Detail:S/N: 0BNS25G5008509025529/NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALBAYAR:81840 Sisa Saldo: 1.000.000 - 79.540 = 920.460 @2019/12/20 19:49:21').should.equal(79540); 31 irs.getPriceFromMessage('REFF#562126 BAYAR TAGIHAN PLN25 SUKSES IDPEL:172000147469 Detail:S/N: 0BNS25G5008509025529/NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALBAYAR:81840 Sisa Saldo: 1.000.000 - 79.540 = 920.460 @2019/12/20 19:49:21').should.equal(79540);
32 }) 32 })
33 33
34 it('should handle missing price', function() { 34 it('should handle missing price', function() {
35 should.not.exist(irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL, SN: 503133415264594 @5/3/2018 1:34:13 PM')); 35 should.not.exist(irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL, SN: 503133415264594 @5/3/2018 1:34:13 PM'));
36 }); 36 });
37 }); 37 });
38 38
39 describe('#eflashtron', function() { 39 describe('#eflashtron', function() {
40 it('should return correct price', function() { 40 it('should return correct price', function() {
41 irs.getPriceFromMessage('Trx HT5.08989355280 BERHASIL. SN: 0608211002164754102. Sisa Saldo: 536.581 - 5.265 = 531.316 @08/06/2019 21:10:03 Komplen max. H+7').should.equal(5265); 41 irs.getPriceFromMessage('Trx HT5.08989355280 BERHASIL. SN: 0608211002164754102. Sisa Saldo: 536.581 - 5.265 = 531.316 @08/06/2019 21:10:03 Komplen max. H+7').should.equal(5265);
42 }); 42 });
43 }); 43 });
44 44
45 describe('#some suppliers', () => {
46 it('should return correct price', () => {
47 irs.getPriceFromMessage('Trx S10 085212341234 BERHASIL, Harga: 5.285 SN: 41002553325946 Saldo: 2.284.011 - 5.285 = 2.278.726 @24/06/2018 18:38:06')
48 .should.equal(5285, 'tajir price');
49 });
50 });
51
45 describe('#custom', () => { 52 describe('#custom', () => {
46 it('should return correct price', () => { 53 it('should return correct price', () => {
47 const msg = 'HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105'; 54 const msg = 'HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105';
48 const rule = { 55 const rule = {
49 pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp ([\\d\\.]+)', 56 pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp ([\\d\\.]+)',
50 match_idx: 1, 57 match_idx: 1,
51 } 58 }
52 irs.getPriceFromMessage(msg, rule).should.equal(5525); 59 irs.getPriceFromMessage(msg, rule).should.equal(5525);
53 should.not.exists(irs.getPriceFromMessage('kosong', rule)); 60 should.not.exists(irs.getPriceFromMessage('kosong', rule));
54 }); 61 });
55 }) 62 })
56 }); 63 });
57 64
58 describe('#getBalanceFromMessage', () => { 65 describe('#getBalanceFromMessage', () => {
66
67 describe('#some suppliers', () => {
68 it('should return correct price', () => {
69 irs.getBalanceFromMessage('Trx S10 085212341234 BERHASIL, Harga: 5.285 SN: 41002553325946 Saldo: 2.284.011 - 5.285 = 2.278.726 @24/06/2018 18:38:06')
70 .should.equal(2278726, 'tajir balance');
71 });
72 });
73
74
59 describe('#custom', () => { 75 describe('#custom', () => {
60 it('should return correct price', () => { 76 it('should return correct price', () => {
61 const msg = 'HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105'; 77 const msg = 'HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105';
62 const rule = { 78 const rule = {
63 pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp (?:[\\d\\.]+) = Rp ([\\d\\.]+)', 79 pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp (?:[\\d\\.]+) = Rp ([\\d\\.]+)',
64 match_idx: 1, 80 match_idx: 1,
65 } 81 }
66 irs.getBalanceFromMessage(msg, rule).should.equal(490105); 82 irs.getBalanceFromMessage(msg, rule).should.equal(490105);
67 should.not.exists(irs.getBalanceFromMessage('kosong', rule)); 83 should.not.exists(irs.getBalanceFromMessage('kosong', rule));
68 }); 84 });
69 }) 85 })
70 }); 86 });
71 87
72 describe('#getSnFromMessage', () => { 88 describe('#getSnFromMessage', () => {
73 it('should return correct result', () => { 89 it('should return correct result', () => {
74 irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN: 99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN: 99971113094584'); 90 irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN: 99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN: 99971113094584');
75 irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN:99971113094584'); 91 irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN:99971113094584');
76 irs.getSnFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36') 92 irs.getSnFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36')
77 .should.equal('0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment'); 93 .should.equal('0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment');
78 }); 94 });
79 }); 95 });
80 96
81 describe('#getDetailFromMessage', () => { 97 describe('#getDetailFromMessage', () => {
82 it('should return correct result', () => { 98 it('should return correct result', () => {
83 irs.getDetailFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16') 99 irs.getDetailFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16')
84 .should.equal('NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041', 'postpaid inquiry success'); 100 .should.equal('NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041', 'postpaid inquiry success');
85 101
86 irs.getDetailFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36') 102 irs.getDetailFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36')
87 .should.equal('S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment'); 103 .should.equal('S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment');
88 104
89 irs.getDetailFromMessage('REFF#561744 CEK TAGIHAN PLN25 SUKSES IDPEL:172000147469 Detail: NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALTAGIHAN:81840 Sisa Saldo: 1.000.000 - 0 = 1.000.000 @2019/12/20 19:41:21') 105 irs.getDetailFromMessage('REFF#561744 CEK TAGIHAN PLN25 SUKSES IDPEL:172000147469 Detail: NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALTAGIHAN:81840 Sisa Saldo: 1.000.000 - 0 = 1.000.000 @2019/12/20 19:41:21')
90 .should.equal('NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALTAGIHAN:81840'); 106 .should.equal('NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALTAGIHAN:81840');
91 }); 107 });
92 }); 108 });
93 109
94 describe('#splitPostpaidDetail', () => { 110 describe('#splitPostpaidDetail', () => {
95 it('should return correct result - inquiry', () => { 111 it('should return correct result - inquiry', () => {
96 const detail = 'NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041'; 112 const detail = 'NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041';
97 const splitted = irs.splitPostpaidDetail(detail); 113 const splitted = irs.splitPostpaidDetail(detail);
98 114
99 splitted.should.ok(); 115 splitted.should.ok();
100 splitted.find((item) => item.keyword === 'NAMA').value.should.equal('MUSHOLLA-NURUL-KHOIR'); 116 splitted.find((item) => item.keyword === 'NAMA').value.should.equal('MUSHOLLA-NURUL-KHOIR');
101 splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('14441'); 117 splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('14441');
102 splitted.find((item) => item.keyword === 'DENDA').value.should.equal('3000'); 118 splitted.find((item) => item.keyword === 'DENDA').value.should.equal('3000');
103 }); 119 });
104 120
105 it('should return correct result - pay', () => { 121 it('should return correct result - pay', () => {
106 const detail = 'S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560'; 122 const detail = 'S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560';
107 const splitted = irs.splitPostpaidDetail(detail); 123 const splitted = irs.splitPostpaidDetail(detail);
108 124
109 splitted.should.ok(); 125 splitted.should.ok();
110 splitted.find((item) => item.keyword === 'SN').value.should.equal('0BNS25G5082152526173'); 126 splitted.find((item) => item.keyword === 'SN').value.should.equal('0BNS25G5082152526173');
111 splitted.find((item) => item.keyword === 'NAMA').value.should.equal('DONAR-HARHAP'); 127 splitted.find((item) => item.keyword === 'NAMA').value.should.equal('DONAR-HARHAP');
112 splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('131560'); 128 splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('131560');
113 splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000'); 129 splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000');
114 }); 130 });
115 }); 131 });
116 132
117 describe('#calculateBaseBillAmount', () => { 133 describe('#calculateBaseBillAmount', () => {
118 it('should return correct value - inquiry', () => { 134 it('should return correct value - inquiry', () => {
119 const detail = 'NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041'; 135 const detail = 'NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041';
120 const splitted = irs.splitPostpaidDetail(detail); 136 const splitted = irs.splitPostpaidDetail(detail);
121 137
122 irs.calculateBaseBillAmount(splitted).should.equal(17441); 138 irs.calculateBaseBillAmount(splitted).should.equal(17441);
123 139
124 }) 140 })
125 141
126 it('should return correct value - payment', () => { 142 it('should return correct value - payment', () => {
127 const detail = 'S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560'; 143 const detail = 'S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560';
128 const splitted = irs.splitPostpaidDetail(detail); 144 const splitted = irs.splitPostpaidDetail(detail);
129 145
130 irs.calculateBaseBillAmount(splitted).should.equal(140560); 146 irs.calculateBaseBillAmount(splitted).should.equal(140560);
131 147
132 }) 148 })
133 }); 149 });
134 150
135 describe('#getBillCount', () => { 151 describe('#getBillCount', () => {
136 it('should return correct value', () => { 152 it('should return correct value', () => {
137 irs.getBillCount('0BNS25G5087744307740/NAMA:SUYATMAN/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201911,201912/METERKINI:3606/METERLALU:3564/TAGIHAN:117260/ADM:5000/DENDA:9000/TOTALBAYAR:131260').should.equal(2); 153 irs.getBillCount('0BNS25G5087744307740/NAMA:SUYATMAN/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201911,201912/METERKINI:3606/METERLALU:3564/TAGIHAN:117260/ADM:5000/DENDA:9000/TOTALBAYAR:131260').should.equal(2);
138 should.not.exists(irs.getBillCount('0BNS25G5087744307740/NAMA:SUYATMAN/DAYA:900/TARIF:R1M/JMLBLN:BLN/PERIODE:201911,201912/METERKINI:3606/METERLALU:3564/TAGIHAN:117260/ADM:5000/DENDA:9000/TOTALBAYAR:131260')); 154 should.not.exists(irs.getBillCount('0BNS25G5087744307740/NAMA:SUYATMAN/DAYA:900/TARIF:R1M/JMLBLN:BLN/PERIODE:201911,201912/METERKINI:3606/METERLALU:3564/TAGIHAN:117260/ADM:5000/DENDA:9000/TOTALBAYAR:131260'));
139 should.not.exists(irs.getBillCount('')); 155 should.not.exists(irs.getBillCount(''));
140 should.not.exists(irs.getBillCount()); 156 should.not.exists(irs.getBillCount());
141 }); 157 });
142 }); 158 });
143 }); 159 });