main.js
17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/* eslint-disable no-console */
/* global describe it */
//process.env.KOMODO_SDK_DEBUG_RC_FROM_MSG = 'YES';
const should = require('should');
const irs = require('../index');
describe('#irs', function() {
describe('#getRcFromMessage', function() {
it('should return correct rc', function() {
irs.getRcFromMessage('Request IBP25 ke 085736328877 under proses..').should.equal('68');
irs.getRcFromMessage('Transaksi HX5 ke 081809903333 GAGAL. Mohon periksa kembali No tujuan sebelum di ulang. Saldo: Rp 26.857.538').should.equal('40');
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');
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');
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');
irs.getRcFromMessage('Maaf Produk sedang gangguan').should.equal('90');
irs.getRcFromMessage('Trx PLN ke 0001465757368 GAGAL. NOMOR ID YANG ANDA MASUKKAN SALAH, MOHON TELITI KEMBALI 43.156.10').should.equal('14');
});
});
describe('#getPriceFromMessage', function() {
describe('#generic', function() {
it('should return correct price', function() {
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);
});
it('should handle postpaid response', () => {
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');
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');
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);
})
it('should handle missing price', function() {
should.not.exist(irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL, SN: 503133415264594 @5/3/2018 1:34:13 PM'));
});
});
describe('#eflashtron', function() {
it('should return correct price', function() {
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);
});
});
describe('#some suppliers', () => {
it('should return correct price', () => {
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')
.should.equal(5285, 'tajir price');
});
});
describe('#custom', () => {
it('should return correct price', () => {
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';
const rule = {
pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp ([\\d\\.]+)',
match_idx: 1,
}
irs.getPriceFromMessage(msg, rule).should.equal(5525);
should.not.exists(irs.getPriceFromMessage('kosong', rule));
});
})
});
describe('#getBalanceFromMessage', () => {
describe('#some suppliers', () => {
it('should return correct price', () => {
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')
.should.equal(2278726, 'tajir balance');
});
});
describe('#custom', () => {
it('should return correct price', () => {
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';
const rule = {
pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp (?:[\\d\\.]+) = Rp ([\\d\\.]+)',
match_idx: 1,
}
irs.getBalanceFromMessage(msg, rule).should.equal(490105);
should.not.exists(irs.getBalanceFromMessage('kosong', rule));
});
})
});
describe('#getSnFromMessage', () => {
it('should return correct result', () => {
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');
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');
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')
.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');
});
});
describe('#getDetailFromMessage', () => {
it('should return correct result', () => {
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')
.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');
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')
.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');
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')
.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');
});
it('should return correct result with htc postpaid bpjsks response', () => {
const msg = 'CEK BPJSKS BERHASIL,SN:IDPEL:0001465757368,NAMA:BAMBANG PARTODEWO,CABANG:1101-SEMARANG,JML:,TOTALBAYAR:28.000';
const detailPattern = {
pattern: 'SN:(.*)($|(, *SALDO))',
match_idx: 1,
};
const detailReplacements = [
{
pattern: ' *\\.\\.+ *',
replacement: '/',
flags: 'g',
},
{
pattern: ' *, *',
replacement: '/',
flags: 'g',
},
{
pattern: ' *: *',
replacement: ':',
flags: 'g',
},
]
irs.getDetailFromMessage(
msg,
detailPattern,
detailReplacements
).should.equal('IDPEL:0001465757368/NAMA:BAMBANG PARTODEWO/CABANG:1101-SEMARANG/JML:/TOTALBAYAR:28.000', 'HTC BPJSK POSTPAID');
});
it('should return correct result with tajira response', () => {
const detailPattern = {
pattern: '(REFID: .*?)($|(, *SALDO))',
match_idx: 1,
};
const detailReplacements = [
{
pattern: ' *\\.\\.+ *',
replacement: '/',
flags: 'g',
},
{
pattern: ' *, *',
replacement: '/',
flags: 'g',
},
{
pattern: ' *: *',
replacement: ':',
flags: 'g',
},
{
pattern: 'TOTAL TAGIHAN*',
replacement: 'TOTALTAGIHAN',
},
]
irs.getDetailFromMessage(
'Cek Tagihan PLN SUKSES ke 520550410074, REFID: 520550410074/MASJID.. KATEGORI:S2/900 , PERIODE:092020, JUMLAH:1, TOTAL TAGIHAN : 72.010',
detailPattern,
detailReplacements
).should.equal('REFID:520550410074/MASJID/KATEGORI:S2/900/PERIODE:092020/JUMLAH:1/TOTALTAGIHAN:72.010', 'TAJIRA PLN POSTPAID');
// const detailPattern2 = {
// pattern: '(REFID: .*), SALDO',
// match_idx: 1,
// };
irs.getDetailFromMessage(
'CEK TAGIHAN PLNFULL SUKSES KE 520550388323, REFID: 52055038832320700700.. NAMA:MUSHOLA AL AMIN, KATEGORIDAYA:S2/450, PERIODE:092020, TAGIHANASLI:16620, DENDA:3000, ADMIN:2750, TOTALBAYAR:19.370, SALDO:500.000',
detailPattern,
detailReplacements
).should.equal(
'REFID:52055038832320700700/NAMA:MUSHOLA AL AMIN/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:16620/DENDA:3000/ADMIN:2750/TOTALBAYAR:19.370',
'TAJIRA PLN POSTPAID 2',
);
irs.getDetailFromMessage(
'Cek Tagihan BPJSKH2H SUKSES ke 0002058343828, REFID: 20809404.. NAMA:SALWA AZ ZAHRA, CABANG:1012-DEPOK, Periode:1,Admin:2500, TOTALBAYAR:28.000, SALDO:186.856',
detailPattern,
detailReplacements,
).should.equal(
'REFID:20809404/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000',
'TAJIRA BPJS',
)
});
});
describe('#splitPostpaidDetail', () => {
it('should handle invalid input', () => {
irs.splitPostpaidDetail(null).length.should.equal(0);
irs.splitPostpaidDetail('').length.should.equal(0);
});
it('should return correct result - inquiry', () => {
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';
const splitted = irs.splitPostpaidDetail(detail);
splitted.should.ok();
splitted.find((item) => item.keyword === 'NAMA').value.should.equal('MUSHOLLA-NURUL-KHOIR');
splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('14441');
splitted.find((item) => item.keyword === 'DENDA').value.should.equal('3000');
});
it('should return correct result - pay', () => {
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';
const splitted = irs.splitPostpaidDetail(detail);
splitted.should.ok();
splitted.find((item) => item.keyword === 'SN').value.should.equal('0BNS25G5082152526173');
splitted.find((item) => item.keyword === 'NAMA').value.should.equal('DONAR-HARHAP');
splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('131560');
splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000');
});
it('should return correct result - tajira', () => {
const splitted = irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000');
// console.log(splitted);
splitted.find((item) => item.keyword === 'REFID').value.should.equal('20770812');
splitted.find((item) => item.keyword === 'Admin').value.should.equal('2500');
const splitted2 = irs.splitPostpaidDetail('REFID:20809404/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000');
splitted2.find((item) => item.keyword === 'TOTALBAYAR').value.should.equal('28.000', 'TAJIRA BPJS');
});
});
describe('#calculateBaseBillAmount', () => {
it('should return correct value - inquiry', () => {
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';
const splitted = irs.splitPostpaidDetail(detail);
irs.calculateBaseBillAmount(splitted).should.equal(17441);
})
it('should return correct value - payment', () => {
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';
const splitted = irs.splitPostpaidDetail(detail);
// console.log('--- DEBUG');
// console.log(splitted);
// console.log('---');
irs.calculateBaseBillAmount(splitted).should.equal(140560, '#2CBDCEB8');
})
it('should return correct value - inquiry - tajira', () => {
const detail = 'REFID:52055038964420747312/NAMA:MASJID AN NUR/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:7140/DENDA:3000/ADMIN:2750/TOTALBAYAR:12.890';
const splitted = irs.splitPostpaidDetail(detail);
irs.calculateBaseBillAmount(
splitted,
null,
// {
// KEYWORD_TAGASLI: 'TAGIHANASLI,DENDA',
// },
// 1
).should.equal(10140);
irs.calculateBaseBillAmount(
irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'),
null,
{
KEYWORD_TOTALTAG: 'TOTALBAYAR',
KEYWORD_ADMINFEE: 'Admin',
},
1
).should.equal(25500);
const productKeyvalBPJSK = {
KEYWORD_TOTALTAG: 'TOTALBAYAR',
KEYWORD_ADMINFEE: 'Admin',
};
irs.calculateBaseBillAmount(
irs.splitPostpaidDetail('REFID:20809404/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'),
null,
productKeyvalBPJSK,
1
).should.equal(25500, 'TAJIRA BPJS #8A46CFD1');
});
});
describe('#getBillCount', () => {
it('should return correct value', () => {
// 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);
irs.getBillCount({
NAMA: 'SUYATMAN',
DAYA: '900',
TARIF: 'R1M',
JMLBLN: 'BLN',
PERIODE: '201911,201912',
}).should.equal(0);
irs.getBillCount({
NAMA: 'SUYATMAN',
DAYA: '900',
TARIF: 'R1M',
JMLBLN: '2',
PERIODE: '201911,201912',
}).should.equal(2);
irs.getBillCount({
NAMA: 'SUYATMAN',
DAYA: '900',
TARIF: 'R1M',
JMLBLN: '2BLN',
PERIODE: '201911,201912',
}, null).should.equal(2);
irs.getBillCount({
NAMA: 'SUYATMAN',
DAYA: '900',
TARIF: 'R1M',
JML: '2BLN',
PERIODE: '201911,201912',
}, 'JML').should.equal(2);
});
});
});