Commit 3ed9073bae6376db180dbeab0ade73b566d7fc70
1 parent
f13b4c271d
Exists in
master
getBillCount
Showing 2 changed files with 18 additions and 3 deletions Side-by-side Diff
index.js
... | ... | @@ -141,14 +141,14 @@ function splitPostpaidDetail(str) { |
141 | 141 | return retval; |
142 | 142 | } |
143 | 143 | |
144 | -function calculateBaseBillAmount(detailSpitted) { | |
144 | +function calculateBaseBillAmount(detailSplitted) { | |
145 | 145 | const keywords = ['TAGIHAN', 'DENDA', 'RPPREMI']; |
146 | 146 | |
147 | 147 | let retval = 0; |
148 | - let detailCount = (detailSpitted || []).length; | |
148 | + let detailCount = (detailSplitted || []).length; | |
149 | 149 | |
150 | 150 | for (let i = 0; i < detailCount; i += 1) { |
151 | - const item = detailSpitted[i]; | |
151 | + const item = detailSplitted[i]; | |
152 | 152 | if (keywords.indexOf(item.keyword.toUpperCase()) >= 0) { |
153 | 153 | retval += Number(item.value) || 0; |
154 | 154 | } |
... | ... | @@ -157,6 +157,11 @@ function calculateBaseBillAmount(detailSpitted) { |
157 | 157 | return retval; |
158 | 158 | } |
159 | 159 | |
160 | +function getBillCount(msg) { | |
161 | + const matches = (msg || '').match(/JMLBLN:(\d+)BLN/); | |
162 | + return (matches && Number(matches[1])) || null; | |
163 | +} | |
164 | + | |
160 | 165 | exports.getRcFromMessage = getRcFromMessage; |
161 | 166 | exports.getPriceFromMessage = getPriceFromMessage; |
162 | 167 | exports.getSnFromMessage = getSnFromMessage; |
... | ... | @@ -167,3 +172,4 @@ exports.isPostpaidResponseMessage = isPostpaidResponseMessage; |
167 | 172 | exports.getDetailFromMessage = getDetailFromMessage; |
168 | 173 | exports.splitPostpaidDetail = splitPostpaidDetail; |
169 | 174 | exports.calculateBaseBillAmount = calculateBaseBillAmount; |
175 | +exports.getBillCount = getBillCount; |
test/main.js
... | ... | @@ -130,5 +130,14 @@ describe('#irs', function() { |
130 | 130 | irs.calculateBaseBillAmount(splitted).should.equal(140560); |
131 | 131 | |
132 | 132 | }) |
133 | + }); | |
134 | + | |
135 | + describe('#getBillCount', () => { | |
136 | + 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); | |
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')); | |
139 | + should.not.exists(irs.getBillCount('')); | |
140 | + should.not.exists(irs.getBillCount()); | |
141 | + }); | |
133 | 142 | }); |
134 | 143 | }); |
135 | 144 | \ No newline at end of file |