Commit 893354b2d9d50045352a38c1130fc62f94f759cc
1 parent
68717b5ed7
Exists in
master
calculateBaseBillAmount fix tested
Showing 2 changed files with 66 additions and 2 deletions Side-by-side Diff
index.js
1 | +/* eslint-disable no-console */ | |
1 | 2 | "use strict"; |
2 | 3 | |
3 | 4 | const regexLooperReplace = require('tektrans-lib/regex-looper/replace'); |
4 | 5 | const rcFromMsg = require('komodo-sdk/rc-from-msg'); |
5 | 6 | const organicRc = require('./rc'); |
6 | 7 | |
8 | +if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | |
9 | + console.log('DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT detected'); | |
10 | +} | |
11 | + | |
7 | 12 | function isInquiryResponseMessage(msg) { |
8 | 13 | return (msg || '').indexOf('CEK TAGIHAN') >= 0; |
9 | 14 | } |
... | ... | @@ -169,8 +174,11 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, |
169 | 174 | if ( |
170 | 175 | !productKeyval |
171 | 176 | || !productKeyval.KEYWORD_TOTALTAG |
172 | - || (!productKeyval.KEYWORD_ADMINFEE && !!productKeyval.ADMINFEE) | |
177 | + || (!productKeyval.KEYWORD_ADMINFEE && !productKeyval.ADMINFEE) | |
173 | 178 | ) { |
179 | + if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | |
180 | + console.log(`=========== 0D299D07 using calculateBaseBillAmountAuto KEYWORD_TOTALTAG=${productKeyval.KEYWORD_TOTALTAG} KEYWORD_KEYWORD_ADMINFEE=${productKeyval.KEYWORD_ADMINFEE} KEYWORD_ADMINFEE=${productKeyval.ADMINFEE}`); | |
181 | + } | |
174 | 182 | return calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval, billCount); |
175 | 183 | } |
176 | 184 | |
... | ... | @@ -189,7 +197,6 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, |
189 | 197 | |
190 | 198 | if (!totalTagihanValue) { |
191 | 199 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { |
192 | - // eslint-disable-next-line no-console | |
193 | 200 | console.log('=========== MISSING totalTagihanValue D7282FA7'); |
194 | 201 | } |
195 | 202 |
test/supplier-htc-postpaid.js
... | ... | @@ -0,0 +1,57 @@ |
1 | +/* global describe it */ | |
2 | + | |
3 | +require('should'); | |
4 | + | |
5 | +const irs = require('../index'); | |
6 | + | |
7 | +describe('Respon dari HTC postpaid', () => { | |
8 | + describe('#irs', () => { | |
9 | + describe('#calculateBaseBillAmount', () => { | |
10 | + it('should return correct value', () => { | |
11 | + const msg = 'CEK BPJSKS BERHASIL,SN:IDPEL:0001465757368,NAMA:BAMBANG PARTODEWO,CABANG:1101-SEMARANG,JML:,TOTALBAYAR:28.000'; | |
12 | + | |
13 | + const detailPattern = { | |
14 | + pattern: 'SN:(.*)($|(, *SALDO))', | |
15 | + match_idx: 1, | |
16 | + }; | |
17 | + | |
18 | + const detailReplacements = [ | |
19 | + { | |
20 | + pattern: ' *\\.\\.+ *', | |
21 | + replacement: '/', | |
22 | + flags: 'g', | |
23 | + }, | |
24 | + { | |
25 | + pattern: ' *, *', | |
26 | + replacement: '/', | |
27 | + flags: 'g', | |
28 | + }, | |
29 | + { | |
30 | + pattern: ' *: *', | |
31 | + replacement: ':', | |
32 | + flags: 'g', | |
33 | + }, | |
34 | + ] | |
35 | + | |
36 | + const detail = irs.getDetailFromMessage( | |
37 | + msg, | |
38 | + detailPattern, | |
39 | + detailReplacements | |
40 | + ); | |
41 | + | |
42 | + detail.should.equal('IDPEL:0001465757368/NAMA:BAMBANG PARTODEWO/CABANG:1101-SEMARANG/JML:/TOTALBAYAR:28.000', 'HTC BPJSK POSTPAID getDetailFromMessage'); | |
43 | + const detailSplitted = irs.splitPostpaidDetail(detail); | |
44 | + | |
45 | + irs.calculateBaseBillAmount( | |
46 | + detailSplitted, | |
47 | + null, | |
48 | + { | |
49 | + KEYWORD_TOTALTAG: 'TOTALBAYAR', | |
50 | + ADMINFEE: '2500', | |
51 | + }, | |
52 | + 1, | |
53 | + ).should.equal(25500); | |
54 | + }) | |
55 | + }); | |
56 | + }) | |
57 | +}); | |
0 | 58 | \ No newline at end of file |