Commit 0d8d270d722f822c012d4c47e7c275a4850d5f3e
1 parent
e196a2f5ba
Exists in
master
mocha test
Showing 2 changed files with 32 additions and 0 deletions Side-by-side Diff
partner-datacell.js
... | ... | @@ -268,6 +268,19 @@ function balanceFromMessage(message) { |
268 | 268 | return matches[1]; |
269 | 269 | } |
270 | 270 | |
271 | +function priceFromMessage(message) { | |
272 | + var matches = message.match(/Harga: (\d+)/); | |
273 | + | |
274 | + if (!matches) { | |
275 | + return null; | |
276 | + } | |
277 | + if (matches.length < 2) { | |
278 | + return null; | |
279 | + } | |
280 | + | |
281 | + return matches[1]; | |
282 | +} | |
283 | + | |
271 | 284 | function start(_config, _callbackReport) { |
272 | 285 | config = _config; |
273 | 286 | callbackReport = _callbackReport |
... | ... | @@ -278,3 +291,4 @@ function start(_config, _callbackReport) { |
278 | 291 | exports.start = start; |
279 | 292 | exports.topupRequest = topupRequest; |
280 | 293 | exports.balanceFromMessage = balanceFromMessage; |
294 | +exports.priceFromMessage = priceFromMessage; |
test.js
... | ... | @@ -21,8 +21,26 @@ describe('partner-datacell', function() { |
21 | 21 | it('should return null', function() { |
22 | 22 | assert.equal(null, partner.balanceFromMessage('XL25 No: 08174945541 SUKSES SN Operator: 970729963933 SN Kami: 243591297.')); |
23 | 23 | }); |
24 | + }); | |
25 | + | |
26 | + describe('#priceFromMessage', function() { | |
27 | + var message; | |
28 | + | |
29 | + it('should return 24750', function() { | |
30 | + assert.equal(8306874, partner.balanceFromMessage('IR25 No: 085697273881 sudah diterima dan sdg diproses. SN Kami :243588112. Harga: 24750. Saldo: Rp 8306874.')); | |
31 | + }); | |
32 | + | |
33 | + it('should return 19950', function() { | |
34 | + assert.equal(8351574, partner.balanceFromMessage('TEL20 No: 085372113774 sudah diterima dan sdg diproses. SN Kami :243586975. Harga: 19950. Saldo: Rp 8351574.')); | |
35 | + }); | |
24 | 36 | |
37 | + it('should return 0', function() { | |
38 | + assert.equal(0, partner.balanceFromMessage('TEL20 No: 085372113774 sudah diterima dan sdg diproses. SN Kami :243586975. Harga: 0. Saldo: Rp 8351574.')); | |
39 | + }); | |
25 | 40 | |
41 | + it('should return null', function() { | |
42 | + assert.equal(null, partner.balanceFromMessage('XL25 No: 08174945541 SUKSES SN Operator: 970729963933 SN Kami: 243591297.')); | |
43 | + }); | |
26 | 44 | }); |
27 | 45 | |
28 | 46 |