Commit 8a677923a6462567787a05b6898e1d9985fc0493
1 parent
afc1f8f3e2
Exists in
master
Perbaikan parsing harga menjadi number
Showing 2 changed files with 18 additions and 1 deletions Side-by-side Diff
lib/st24.js
... | ... | @@ -41,7 +41,9 @@ function extractPriceFromMsg(msg, custom_rule) { |
41 | 41 | const default_pattern = "\\d,HRG=(.*?),ID="; |
42 | 42 | const default_match_idx = 1; |
43 | 43 | |
44 | - return extractFromMessage(msg, default_pattern, default_match_idx, custom_rule); | |
44 | + let price = extractFromMessage(msg, default_pattern, default_match_idx, custom_rule); | |
45 | + price = (typeof price === 'string') ? Number(price.replace(/\./g, '')) : null; | |
46 | + return price; | |
45 | 47 | } |
46 | 48 | |
47 | 49 | function extractBalanceFromMsg(msg, custom_rule) { |
test.js
... | ... | @@ -63,4 +63,19 @@ describe('#st24', function() { |
63 | 63 | }) |
64 | 64 | }) |
65 | 65 | |
66 | + describe('#extractPriceFromMsg', function() { | |
67 | + describe('using native ST24 topUpRequest direct response', function() { | |
68 | + it('should return correct price', function() { | |
69 | + st24.extractPriceFromMsg('SN=0041002635395450;;19/07/18 21:01 ISI SPT20 KE 08125100091, SUKSES. SAL=798.500,HRG=19.700,ID=48761075,SN=0041002635395450;; ..trx lancar').should.equal(19700); | |
70 | + st24.extractPriceFromMsg('SN=0516150344145563101; 16/05/18 15:03 ISI TR5 KE 0895350249796, SUKSES.SAL=426.078,HRG=5.250,ID=47285513,SN=0516150344145563101; ..trx lancar').should.equal(5250); | |
71 | + }); | |
72 | + }) | |
73 | + | |
74 | + describe('using native ST24 topUpInquiry response', function() { | |
75 | + it('should return correct price', function() { | |
76 | + st24.extractPriceFromMsg('19/07/18 20:53 ISI SPT20 KE 081264858057, SUKSES.SAL=828.425,HRG=19.700,ID=48761021,SN=0041002635369521;').should.equal(19700); | |
77 | + }) | |
78 | + }) | |
79 | + }) | |
80 | + | |
66 | 81 | }) |