Commit 7ec4016657837ae777abb3c05de7038be30fb306
1 parent
f0303f53a1
Exists in
master
perbaikan parsesn
Showing 2 changed files with 19 additions and 32 deletions Side-by-side Diff
httppulsakita.js
... | ... | @@ -11,8 +11,13 @@ var sleep_before_retry = 3000; |
11 | 11 | |
12 | 12 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; |
13 | 13 | |
14 | -function parseSN(message) { | |
15 | - var sn_regex = new RegExp(config.h2h_out.sn_pattern); | |
14 | +function parseSN(message, _config) { | |
15 | + | |
16 | + if (!_config) { | |
17 | + _config = config; | |
18 | + } | |
19 | + | |
20 | + var sn_regex = new RegExp(_config.h2h_out.sn_pattern); | |
16 | 21 | var sn_match = message.match(sn_regex); |
17 | 22 | |
18 | 23 | if (sn_match <= 0) { |
... | ... | @@ -21,7 +26,7 @@ function parseSN(message) { |
21 | 26 | } |
22 | 27 | |
23 | 28 | var sn = sn_match[0]; |
24 | - var sn_remove_patterns = config.h2h_out.sn_remove_patterns.split(config.h2h_out.sn_remove_patterns_separator); | |
29 | + var sn_remove_patterns = _config.h2h_out.sn_remove_patterns.split(_config.h2h_out.sn_remove_patterns_separator); | |
25 | 30 | |
26 | 31 | var count = sn_remove_patterns.length; |
27 | 32 | |
... | ... | @@ -152,32 +157,6 @@ function start(_config, _callbackReport) { |
152 | 157 | callbackReport = _callbackReport |
153 | 158 | } |
154 | 159 | |
155 | -function parseSN(message) { | |
156 | - var sn_regex = new RegExp(config.h2h_out.sn_pattern); | |
157 | - var sn_match = message.match(sn_regex); | |
158 | - | |
159 | - //console.log('SN MATCH:'); | |
160 | - //console.log(sn_match); | |
161 | - | |
162 | - if (sn_match <= 0) { | |
163 | - console.log('SN Not found: ' + message); | |
164 | - return ''; | |
165 | - } | |
166 | - | |
167 | - var sn = sn_match[0]; | |
168 | - var sn_remove_patterns = config.h2h_out.sn_remove_patterns.split(config.h2h_out.sn_remove_patterns_separator); | |
169 | - //console.log('SN REMOVE PATTERNS:'); | |
170 | - //console.log (sn_remove_patterns); | |
171 | - | |
172 | - var count = sn_remove_patterns.length; | |
173 | - | |
174 | - for(var i = 0; i < count; i++) { | |
175 | - sn = sn.replace(sn_remove_patterns[i], ''); | |
176 | - } | |
177 | - | |
178 | - return sn.trim(); | |
179 | -} | |
180 | - | |
181 | 160 | function parseResult(message) { |
182 | 161 | var data; |
183 | 162 | xml(message, function(err, result) { |
test.js
... | ... | @@ -47,15 +47,23 @@ Sisa saldo Rp. 5,000,000 - Rp. 18,700 = Rp. 4,981,300</pesan></respon>'; |
47 | 47 | }); |
48 | 48 | }); |
49 | 49 | |
50 | - /* | |
50 | + | |
51 | 51 | describe("parseSN()", function() { |
52 | + config = { | |
53 | + h2h_out: { | |
54 | + parse_sn: 'YES', | |
55 | + sn_pattern: 'refnum \\w* pada', | |
56 | + sn_remove_patterns_separator: '|', | |
57 | + sn_remove_patterns: 'refnum | pada' | |
58 | + } | |
59 | + }; | |
52 | 60 | |
53 | 61 | message = "#14837 XR5 ke:081809903333 SUKSES. Isi pulsa XR5 berhasil untuk nomor 6281809903333 sebesar 5.000, refnum B93D0792A47841AE03B0000000000000 pada tgl 16/06/15 15:47. \ |
54 | 62 | Sisa saldo Rp. 4,981,300 - Rp. 5,250 = Rp. 4,976,050"; |
55 | 63 | it ('should return B93D0792A47841AE03B0000000000000', function() { |
56 | - assert.equal('B93D0792A47841AE03B0000000000000', parseSN(message)); | |
64 | + assert.equal('B93D0792A47841AE03B0000000000000', partner.parseSN(message, config)); | |
57 | 65 | }); |
58 | 66 | |
59 | 67 | }); |
60 | - */ | |
68 | + | |
61 | 69 | }); |