diff --git a/index.js b/index.js index 3ce5311..1a88f6c 100644 --- a/index.js +++ b/index.js @@ -245,10 +245,12 @@ function getBillCount(detailSplitted, customKeyword) { if (!detailSplitted) return 0; return Number( - (customKeyword && detailSplitted[customKeyword]) - || detailSplitted['JMLBLN'] - || '0' - ); + ( + (customKeyword && detailSplitted[customKeyword]) + || detailSplitted['JMLBLN'] + || '' + ).replace(/\D+$/g, '') + ) || 0; } exports.getRcFromMessage = getRcFromMessage; diff --git a/test/main.js b/test/main.js index 70b0b25..c04ca99 100644 --- a/test/main.js +++ b/test/main.js @@ -300,10 +300,38 @@ describe('#irs', function() { 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); - 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')); - should.not.exists(irs.getBillCount('')); - should.not.exists(irs.getBillCount()); + // 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); }); }); }); \ No newline at end of file