diff --git a/index.js b/index.js index 45750a0..ecf2862 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,14 @@ +/* eslint-disable no-console */ "use strict"; const regexLooperReplace = require('tektrans-lib/regex-looper/replace'); const rcFromMsg = require('komodo-sdk/rc-from-msg'); const organicRc = require('./rc'); +if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { + console.log('DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT detected'); +} + function isInquiryResponseMessage(msg) { return (msg || '').indexOf('CEK TAGIHAN') >= 0; } @@ -169,8 +174,11 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, if ( !productKeyval || !productKeyval.KEYWORD_TOTALTAG - || (!productKeyval.KEYWORD_ADMINFEE && !!productKeyval.ADMINFEE) + || (!productKeyval.KEYWORD_ADMINFEE && !productKeyval.ADMINFEE) ) { + if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { + console.log(`=========== 0D299D07 using calculateBaseBillAmountAuto KEYWORD_TOTALTAG=${productKeyval.KEYWORD_TOTALTAG} KEYWORD_KEYWORD_ADMINFEE=${productKeyval.KEYWORD_ADMINFEE} KEYWORD_ADMINFEE=${productKeyval.ADMINFEE}`); + } return calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval, billCount); } @@ -189,7 +197,6 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, if (!totalTagihanValue) { if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { - // eslint-disable-next-line no-console console.log('=========== MISSING totalTagihanValue D7282FA7'); } diff --git a/test/supplier-htc-postpaid.js b/test/supplier-htc-postpaid.js new file mode 100644 index 0000000..c9a2131 --- /dev/null +++ b/test/supplier-htc-postpaid.js @@ -0,0 +1,57 @@ +/* global describe it */ + +require('should'); + +const irs = require('../index'); + +describe('Respon dari HTC postpaid', () => { + describe('#irs', () => { + describe('#calculateBaseBillAmount', () => { + it('should return correct value', () => { + 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', + }, + ] + + const detail = irs.getDetailFromMessage( + msg, + detailPattern, + detailReplacements + ); + + detail.should.equal('IDPEL:0001465757368/NAMA:BAMBANG PARTODEWO/CABANG:1101-SEMARANG/JML:/TOTALBAYAR:28.000', 'HTC BPJSK POSTPAID getDetailFromMessage'); + const detailSplitted = irs.splitPostpaidDetail(detail); + + irs.calculateBaseBillAmount( + detailSplitted, + null, + { + KEYWORD_TOTALTAG: 'TOTALBAYAR', + ADMINFEE: '2500', + }, + 1, + ).should.equal(25500); + }) + }); + }) +}); \ No newline at end of file