Commit 29a9db174119628e45ec1636b36016c2caf0aedd
1 parent
2b2e7581eb
Exists in
master
Perbaikan calculateBaseBillAmount uppercase keyword
Showing 2 changed files with 49 additions and 8 deletions Inline Diff
index.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const regexLooperReplace = require('tektrans-lib/regex-looper/replace'); | 3 | const regexLooperReplace = require('tektrans-lib/regex-looper/replace'); |
4 | const rcFromMsg = require('komodo-sdk/rc-from-msg'); | 4 | const rcFromMsg = require('komodo-sdk/rc-from-msg'); |
5 | const organicRc = require('./rc'); | 5 | const organicRc = require('./rc'); |
6 | 6 | ||
7 | function isInquiryResponseMessage(msg) { | 7 | function isInquiryResponseMessage(msg) { |
8 | return (msg || '').indexOf('CEK TAGIHAN') >= 0; | 8 | return (msg || '').indexOf('CEK TAGIHAN') >= 0; |
9 | } | 9 | } |
10 | 10 | ||
11 | function isPaymentResponseMessage(msg) { | 11 | function isPaymentResponseMessage(msg) { |
12 | return (msg || '').indexOf('BAYAR TAGIHAN') >= 0; | 12 | return (msg || '').indexOf('BAYAR TAGIHAN') >= 0; |
13 | } | 13 | } |
14 | 14 | ||
15 | function isPostpaidResponseMessage(msg) { | 15 | function isPostpaidResponseMessage(msg) { |
16 | return isInquiryResponseMessage(msg) || isPaymentResponseMessage(msg); | 16 | return isInquiryResponseMessage(msg) || isPaymentResponseMessage(msg); |
17 | } | 17 | } |
18 | 18 | ||
19 | function getRcFromMessage(msg, customRc) { | 19 | function getRcFromMessage(msg, customRc) { |
20 | let rc; | 20 | let rc; |
21 | if (customRc && Array.isArray(customRc) && customRc.length) { | 21 | if (customRc && Array.isArray(customRc) && customRc.length) { |
22 | rc = rcFromMsg(msg, customRc); | 22 | rc = rcFromMsg(msg, customRc); |
23 | } | 23 | } |
24 | 24 | ||
25 | if (!rc) { | 25 | if (!rc) { |
26 | rc = rcFromMsg(msg, organicRc); | 26 | rc = rcFromMsg(msg, organicRc); |
27 | } | 27 | } |
28 | 28 | ||
29 | return rc; | 29 | return rc; |
30 | } | 30 | } |
31 | 31 | ||
32 | function getPriceFromMessage(msg, rule) { | 32 | function getPriceFromMessage(msg, rule) { |
33 | if (typeof msg !== 'string') { | 33 | if (typeof msg !== 'string') { |
34 | return; | 34 | return; |
35 | } | 35 | } |
36 | 36 | ||
37 | if (process.env.DEBUG_IRS && !rule) { | 37 | if (process.env.DEBUG_IRS && !rule) { |
38 | console.log('** IRS.getPriceFromMessage no rule'); // eslint-disable-line no-console | 38 | console.log('** IRS.getPriceFromMessage no rule'); // eslint-disable-line no-console |
39 | } | 39 | } |
40 | 40 | ||
41 | if (process.env.DEBUG_IRS && rule) { | 41 | if (process.env.DEBUG_IRS && rule) { |
42 | console.log('** IRS.getPriceFromMessage rule: ' + JSON.stringify(rule, null, 2)); // eslint-disable-line no-console | 42 | console.log('** IRS.getPriceFromMessage rule: ' + JSON.stringify(rule, null, 2)); // eslint-disable-line no-console |
43 | } | 43 | } |
44 | 44 | ||
45 | //const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "Harga: ([\\d\\.]+?) "; | 45 | //const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "Harga: ([\\d\\.]+?) "; |
46 | const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "\\d+\\s+-\\s+([\\d,\\.]+)\\s+="; | 46 | const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "\\d+\\s+-\\s+([\\d,\\.]+)\\s+="; |
47 | const match_idx = (rule && typeof rule.match_idx === 'number') ? rule.match_idx : 1; | 47 | const match_idx = (rule && typeof rule.match_idx === 'number') ? rule.match_idx : 1; |
48 | 48 | ||
49 | const re = new RegExp(pattern); | 49 | const re = new RegExp(pattern); |
50 | const matches = msg.match(re); | 50 | const matches = msg.match(re); |
51 | if (process.env.DEBUG_IRS) { | 51 | if (process.env.DEBUG_IRS) { |
52 | console.log('** IRS.getPriceFromMessage msg: "' + msg + '" active_pattern: "' + pattern + '" active_match_idx: ' + match_idx); // eslint-disable-line no-console | 52 | console.log('** IRS.getPriceFromMessage msg: "' + msg + '" active_pattern: "' + pattern + '" active_match_idx: ' + match_idx); // eslint-disable-line no-console |
53 | console.log('** IRS.getPriceFromMessage matches:\n' + JSON.stringify(matches)); // eslint-disable-line no-console | 53 | console.log('** IRS.getPriceFromMessage matches:\n' + JSON.stringify(matches)); // eslint-disable-line no-console |
54 | } | 54 | } |
55 | 55 | ||
56 | if (matches && matches[match_idx]) { | 56 | if (matches && matches[match_idx]) { |
57 | const result = Number(matches[match_idx].replace(/\./g, '')); | 57 | const result = Number(matches[match_idx].replace(/\./g, '')); |
58 | if (process.env.DEBUG_IRS) { | 58 | if (process.env.DEBUG_IRS) { |
59 | console.log('** IRS.getPriceFromMessage SUPPLIER-PRICE: ' + result); // eslint-disable-line no-console | 59 | console.log('** IRS.getPriceFromMessage SUPPLIER-PRICE: ' + result); // eslint-disable-line no-console |
60 | } | 60 | } |
61 | return result; | 61 | return result; |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | function extractFromMessage(msg, rule) { | 65 | function extractFromMessage(msg, rule) { |
66 | if (typeof msg !== 'string') { return; } | 66 | if (typeof msg !== 'string') { return; } |
67 | 67 | ||
68 | if (!rule) { return; } | 68 | if (!rule) { return; } |
69 | 69 | ||
70 | if (typeof rule !== 'object') { | 70 | if (typeof rule !== 'object') { |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | 73 | ||
74 | rule.match_idx = Number(rule.match_idx); | 74 | rule.match_idx = Number(rule.match_idx); |
75 | 75 | ||
76 | if (!rule.match_idx) { | 76 | if (!rule.match_idx) { |
77 | rule.match_idx = 1; | 77 | rule.match_idx = 1; |
78 | } | 78 | } |
79 | 79 | ||
80 | const re = new RegExp(rule.pattern); | 80 | const re = new RegExp(rule.pattern); |
81 | const matches = msg.match(re); | 81 | const matches = msg.match(re); |
82 | if (matches && matches[rule.match_idx] && typeof matches[rule.match_idx] === 'string') { | 82 | if (matches && matches[rule.match_idx] && typeof matches[rule.match_idx] === 'string') { |
83 | return matches[rule.match_idx]; | 83 | return matches[rule.match_idx]; |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | function getSnFromMessage(msg, rule) { | 87 | function getSnFromMessage(msg, rule) { |
88 | if (!rule) { | 88 | if (!rule) { |
89 | rule = { | 89 | rule = { |
90 | pattern: "[: ]S/*N:\\s*(.+?)\\s", | 90 | pattern: "[: ]S/*N:\\s*(.+?)\\s", |
91 | match_idx: 1 | 91 | match_idx: 1 |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | let sn = extractFromMessage(msg, rule); | 95 | let sn = extractFromMessage(msg, rule); |
96 | if (!sn || typeof sn !== 'string') { return; } | 96 | if (!sn || typeof sn !== 'string') { return; } |
97 | 97 | ||
98 | return sn.toUpperCase().replace(/[^a-zA-Z0-9:,/]/g, '-').replace(/-+/g, '-').replace(/-*\/-*/g, '/').replace(/^-+/, '').replace(/-+$/, ''); | 98 | return sn.toUpperCase().replace(/[^a-zA-Z0-9:,/]/g, '-').replace(/-+/g, '-').replace(/-*\/-*/g, '/').replace(/^-+/, '').replace(/-+$/, ''); |
99 | } | 99 | } |
100 | 100 | ||
101 | function getBalanceFromMessage(msg, rule) { | 101 | function getBalanceFromMessage(msg, rule) { |
102 | if (!rule) { | 102 | if (!rule) { |
103 | rule = { | 103 | rule = { |
104 | pattern: "Saldo: .+? = ([\\d\\.]+) ", | 104 | pattern: "Saldo: .+? = ([\\d\\.]+) ", |
105 | match_idx: 1 | 105 | match_idx: 1 |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | let result = extractFromMessage(msg, rule); | 109 | let result = extractFromMessage(msg, rule); |
110 | if (!result || typeof result !== 'string') { return; } | 110 | if (!result || typeof result !== 'string') { return; } |
111 | 111 | ||
112 | return Number(result.replace(/\./g, '')); | 112 | return Number(result.replace(/\./g, '')); |
113 | } | 113 | } |
114 | 114 | ||
115 | function getDetailFromMessage(msg, rule, replacementRules) { | 115 | function getDetailFromMessage(msg, rule, replacementRules) { |
116 | if (!rule) { | 116 | if (!rule) { |
117 | rule = { | 117 | rule = { |
118 | pattern: " Detail:\\s*(.+?)\\s+Sisa [Ss]aldo", | 118 | pattern: " Detail:\\s*(.+?)\\s+Sisa [Ss]aldo", |
119 | match_idx: 1, | 119 | match_idx: 1, |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | return ( | 123 | return ( |
124 | regexLooperReplace(extractFromMessage(msg, rule), replacementRules) || '' | 124 | regexLooperReplace(extractFromMessage(msg, rule), replacementRules) || '' |
125 | ).trim() || null; | 125 | ).trim() || null; |
126 | } | 126 | } |
127 | 127 | ||
128 | function splitPostpaidDetail(str) { | 128 | function splitPostpaidDetail(str) { |
129 | const retval = (str || '') | 129 | const retval = (str || '') |
130 | .split('/') | 130 | .split('/') |
131 | .map((item) => { | 131 | .map((item) => { |
132 | let [keyword, value] = item.split(':'); | 132 | let [keyword, value] = item.split(':'); |
133 | keyword = (keyword || '').trim() | 133 | keyword = (keyword || '').trim() |
134 | 134 | ||
135 | if (keyword === 'N') keyword = 'SN'; | 135 | if (keyword === 'N') keyword = 'SN'; |
136 | 136 | ||
137 | return { | 137 | return { |
138 | keyword, | 138 | keyword, |
139 | value: (value || '').trim(), | 139 | value: (value || '').trim(), |
140 | }; | 140 | }; |
141 | }) | 141 | }) |
142 | .filter((item) => item.keyword.length && item.value.length); | 142 | .filter((item) => item.keyword.length && item.value.length); |
143 | return retval; | 143 | return retval; |
144 | } | 144 | } |
145 | 145 | ||
146 | function calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval) { | 146 | function calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval) { |
147 | const tagihanAsliKeyvalKeywords = (productKeyval && productKeyval.KEYWORD_TAGASLI) ? productKeyval.KEYWORD_TAGASLI.split(/ *, */) | 147 | const tagihanAsliKeyvalKeywords = (productKeyval && productKeyval.KEYWORD_TAGASLI) ? productKeyval.KEYWORD_TAGASLI.split(/ *, */) |
148 | : null; | 148 | : null; |
149 | 149 | ||
150 | const keywords = (tagihanAsliKeyvalKeywords && Array.isArray(tagihanAsliKeyvalKeywords) && tagihanAsliKeyvalKeywords.length && tagihanAsliKeyvalKeywords) | 150 | const keywords = (tagihanAsliKeyvalKeywords && Array.isArray(tagihanAsliKeyvalKeywords) && tagihanAsliKeyvalKeywords.length && tagihanAsliKeyvalKeywords) |
151 | || customKeywords | 151 | || customKeywords |
152 | || ['TAGIHANASLI', 'TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA']; | 152 | || ['TAGIHANASLI', 'TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA']; |
153 | 153 | ||
154 | let retval = 0; | 154 | let retval = 0; |
155 | let detailCount = (detailSplitted || []).length; | 155 | let detailCount = (detailSplitted || []).length; |
156 | 156 | ||
157 | for (let i = 0; i < detailCount; i += 1) { | 157 | for (let i = 0; i < detailCount; i += 1) { |
158 | const item = detailSplitted[i]; | 158 | const item = detailSplitted[i]; |
159 | if (keywords.indexOf(item.keyword.toUpperCase()) >= 0) { | 159 | if (keywords.indexOf(item.keyword.toUpperCase()) >= 0) { |
160 | const value = (item.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''); | 160 | const value = (item.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''); |
161 | retval += Number(value) || 0; | 161 | retval += Number(value) || 0; |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
165 | return retval; | 165 | return retval; |
166 | } | 166 | } |
167 | 167 | ||
168 | function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, billCount) { | 168 | function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, billCount) { |
169 | if ( | 169 | if ( |
170 | !productKeyval | 170 | !productKeyval |
171 | || !Array.isArray(productKeyval) | 171 | || !productKeyval.KEYWORD_TOTALTAG |
172 | || !productKeyval.KEYWORD_TOTALTAG | ||
173 | || !productKeyval.KEYWORD_ADMINFEE | 172 | || !productKeyval.KEYWORD_ADMINFEE |
174 | ) { | 173 | ) { |
175 | return calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval, billCount); | 174 | return calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval, billCount); |
176 | } | 175 | } |
177 | 176 | ||
178 | const billCountOrDefault = billCount || 1; | 177 | const billCountOrDefault = billCount || 1; |
179 | 178 | ||
180 | const totalTagihanKeyword = productKeyval.KEYWORD_TOTALTAG; | 179 | const totalTagihanKeyword = productKeyval.KEYWORD_TOTALTAG; |
181 | if (!totalTagihanKeyword) return 0; | 180 | if (!totalTagihanKeyword) return 0; |
182 | 181 | ||
183 | const totalTagihanItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === totalTagihanKeyword); | 182 | const totalTagihanItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === totalTagihanKeyword.toUpperCase()); |
184 | const totalTagihanValue = Number((totalTagihanItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, '')); | 183 | const totalTagihanValue = Number((totalTagihanItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, '')); |
185 | if (!totalTagihanValue) return 0; | 184 | if (!totalTagihanValue) { |
185 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | ||
186 | // eslint-disable-next-line no-console | ||
187 | console.log('=========== MISSING totalTagihanValue D7282FA7'); | ||
188 | } | ||
189 | |||
190 | return 0; | ||
191 | } | ||
186 | 192 | ||
187 | const defaultAdminFee = Number(productKeyval.ADMINFEE || ''); | 193 | const defaultAdminFee = Number(productKeyval.ADMINFEE || ''); |
188 | 194 | ||
189 | const adminFeeKeyword = productKeyval.KEYWORD_ADMINFEE; | 195 | const adminFeeKeyword = productKeyval.KEYWORD_ADMINFEE; |
190 | if (!adminFeeKeyword && defaultAdminFee) return totalTagihanValue - (defaultAdminFee * billCountOrDefault); | 196 | if (!adminFeeKeyword && defaultAdminFee) { |
191 | if (!adminFeeKeyword) return 0; | 197 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { |
198 | // eslint-disable-next-line no-console | ||
199 | console.log('======== TOTAL TAGIHAN VALUE - (DEFAULT ADMIN FEE * BILL COUNT) D35E56AD') ; | ||
200 | } | ||
201 | return totalTagihanValue - (defaultAdminFee * billCountOrDefault); | ||
202 | } | ||
192 | 203 | ||
193 | const adminFeeItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === adminFeeKeyword); | 204 | if (!adminFeeKeyword) { |
205 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | ||
206 | // eslint-disable-next-line no-console | ||
207 | console.log('======== Missing adminFeeKeyword'); | ||
208 | } | ||
209 | |||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | const adminFeeItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === adminFeeKeyword.toUpperCase()); | ||
214 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | ||
215 | // eslint-disable-next-line no-console | ||
216 | console.log(`======== adminFeeItem: ${adminFeeKeyword}`, adminFeeItem); | ||
217 | } | ||
194 | const adminFeeValue = Number((adminFeeItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, '')); | 218 | const adminFeeValue = Number((adminFeeItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, '')); |
195 | if (!adminFeeValue) return 0; | 219 | if (!adminFeeValue) return 0; |
196 | 220 | ||
197 | return totalTagihanValue - (adminFeeValue * billCountOrDefault); | 221 | return totalTagihanValue - (adminFeeValue * billCountOrDefault); |
198 | } | 222 | } |
199 | 223 | ||
200 | 224 | ||
201 | function getBillCount(msg) { | 225 | function getBillCount(msg) { |
202 | const matches = (msg || '').match(/JMLBLN:(\d+)BLN/); | 226 | const matches = (msg || '').match(/JMLBLN:(\d+)BLN/); |
203 | return (matches && Number(matches[1])) || null; | 227 | return (matches && Number(matches[1])) || null; |
204 | } | 228 | } |
205 | 229 | ||
206 | exports.getRcFromMessage = getRcFromMessage; | 230 | exports.getRcFromMessage = getRcFromMessage; |
207 | exports.getPriceFromMessage = getPriceFromMessage; | 231 | exports.getPriceFromMessage = getPriceFromMessage; |
208 | exports.getSnFromMessage = getSnFromMessage; | 232 | exports.getSnFromMessage = getSnFromMessage; |
209 | exports.getBalanceFromMessage = getBalanceFromMessage; | 233 | exports.getBalanceFromMessage = getBalanceFromMessage; |
210 | exports.isInquiryResponseMessage = isInquiryResponseMessage; | 234 | exports.isInquiryResponseMessage = isInquiryResponseMessage; |
211 | exports.isPaymentResponseMessage = isPaymentResponseMessage; | 235 | exports.isPaymentResponseMessage = isPaymentResponseMessage; |
212 | exports.isPostpaidResponseMessage = isPostpaidResponseMessage; | 236 | exports.isPostpaidResponseMessage = isPostpaidResponseMessage; |
213 | exports.getDetailFromMessage = getDetailFromMessage; | 237 | exports.getDetailFromMessage = getDetailFromMessage; |
214 | exports.splitPostpaidDetail = splitPostpaidDetail; | 238 | exports.splitPostpaidDetail = splitPostpaidDetail; |
215 | exports.calculateBaseBillAmount = calculateBaseBillAmount; | 239 | exports.calculateBaseBillAmount = calculateBaseBillAmount; |
216 | exports.getBillCount = getBillCount; | 240 | exports.getBillCount = getBillCount; |
test/main.js
1 | /* eslint-disable no-console */ | 1 | /* eslint-disable no-console */ |
2 | /* global describe it */ | 2 | /* global describe it */ |
3 | 3 | ||
4 | //process.env.KOMODO_SDK_DEBUG_RC_FROM_MSG = 'YES'; | 4 | //process.env.KOMODO_SDK_DEBUG_RC_FROM_MSG = 'YES'; |
5 | 5 | ||
6 | const should = require('should'); | 6 | const should = require('should'); |
7 | const irs = require('../index'); | 7 | const irs = require('../index'); |
8 | 8 | ||
9 | describe('#irs', function() { | 9 | describe('#irs', function() { |
10 | describe('#getRcFromMessage', function() { | 10 | describe('#getRcFromMessage', function() { |
11 | it('should return correct rc', function() { | 11 | it('should return correct rc', function() { |
12 | irs.getRcFromMessage('Request IBP25 ke 085736328877 under proses..').should.equal('68'); | 12 | irs.getRcFromMessage('Request IBP25 ke 085736328877 under proses..').should.equal('68'); |
13 | irs.getRcFromMessage('Transaksi HX5 ke 081809903333 GAGAL. Mohon periksa kembali No tujuan sebelum di ulang. Saldo: Rp 26.857.538').should.equal('40'); | 13 | irs.getRcFromMessage('Transaksi HX5 ke 081809903333 GAGAL. Mohon periksa kembali No tujuan sebelum di ulang. Saldo: Rp 26.857.538').should.equal('40'); |
14 | irs.getRcFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal('00'); | 14 | irs.getRcFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal('00'); |
15 | 15 | ||
16 | irs.getRcFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal('00', 'postpaid inquiry success'); | 16 | irs.getRcFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal('00', 'postpaid inquiry success'); |
17 | irs.getRcFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal('00', 'postpaid payment success'); | 17 | irs.getRcFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal('00', 'postpaid payment success'); |
18 | 18 | ||
19 | irs.getRcFromMessage('Maaf Produk sedang gangguan').should.equal('90'); | 19 | irs.getRcFromMessage('Maaf Produk sedang gangguan').should.equal('90'); |
20 | }); | 20 | }); |
21 | }); | 21 | }); |
22 | 22 | ||
23 | describe('#getPriceFromMessage', function() { | 23 | describe('#getPriceFromMessage', function() { |
24 | describe('#generic', function() { | 24 | describe('#generic', function() { |
25 | it('should return correct price', function() { | 25 | it('should return correct price', function() { |
26 | irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal(24475); | 26 | irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL,Harga: 24.475 SN: 503133415264594 Sisa Saldo: 1.169.227 - 24.475 = 1.144.752 @5/3/2018 1:34:13 PM').should.equal(24475); |
27 | }); | 27 | }); |
28 | 28 | ||
29 | it('should handle postpaid response', () => { | 29 | it('should handle postpaid response', () => { |
30 | irs.getPriceFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal(0, 'postpaid inquiry succces'); | 30 | irs.getPriceFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16').should.equal(0, 'postpaid inquiry succces'); |
31 | irs.getPriceFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal(17741, 'postpaid payment success'); | 31 | irs.getPriceFromMessage('REFF#1239 BAYAR TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail:S/N:0BNS25G5043265250358/NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLNPERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALBAYAR:19041 Sisa Saldo: 180.318 - 17.741 = 162.577 @29/12/2017 9:48:41').should.equal(17741, 'postpaid payment success'); |
32 | irs.getPriceFromMessage('REFF#562126 BAYAR TAGIHAN PLN25 SUKSES IDPEL:172000147469 Detail:S/N: 0BNS25G5008509025529/NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALBAYAR:81840 Sisa Saldo: 1.000.000 - 79.540 = 920.460 @2019/12/20 19:49:21').should.equal(79540); | 32 | irs.getPriceFromMessage('REFF#562126 BAYAR TAGIHAN PLN25 SUKSES IDPEL:172000147469 Detail:S/N: 0BNS25G5008509025529/NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALBAYAR:81840 Sisa Saldo: 1.000.000 - 79.540 = 920.460 @2019/12/20 19:49:21').should.equal(79540); |
33 | }) | 33 | }) |
34 | 34 | ||
35 | it('should handle missing price', function() { | 35 | it('should handle missing price', function() { |
36 | should.not.exist(irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL, SN: 503133415264594 @5/3/2018 1:34:13 PM')); | 36 | should.not.exist(irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL, SN: 503133415264594 @5/3/2018 1:34:13 PM')); |
37 | }); | 37 | }); |
38 | }); | 38 | }); |
39 | 39 | ||
40 | describe('#eflashtron', function() { | 40 | describe('#eflashtron', function() { |
41 | it('should return correct price', function() { | 41 | it('should return correct price', function() { |
42 | irs.getPriceFromMessage('Trx HT5.08989355280 BERHASIL. SN: 0608211002164754102. Sisa Saldo: 536.581 - 5.265 = 531.316 @08/06/2019 21:10:03 Komplen max. H+7').should.equal(5265); | 42 | irs.getPriceFromMessage('Trx HT5.08989355280 BERHASIL. SN: 0608211002164754102. Sisa Saldo: 536.581 - 5.265 = 531.316 @08/06/2019 21:10:03 Komplen max. H+7').should.equal(5265); |
43 | }); | 43 | }); |
44 | }); | 44 | }); |
45 | 45 | ||
46 | describe('#some suppliers', () => { | 46 | describe('#some suppliers', () => { |
47 | it('should return correct price', () => { | 47 | it('should return correct price', () => { |
48 | irs.getPriceFromMessage('Trx S10 085212341234 BERHASIL, Harga: 5.285 SN: 41002553325946 Saldo: 2.284.011 - 5.285 = 2.278.726 @24/06/2018 18:38:06') | 48 | irs.getPriceFromMessage('Trx S10 085212341234 BERHASIL, Harga: 5.285 SN: 41002553325946 Saldo: 2.284.011 - 5.285 = 2.278.726 @24/06/2018 18:38:06') |
49 | .should.equal(5285, 'tajir price'); | 49 | .should.equal(5285, 'tajir price'); |
50 | }); | 50 | }); |
51 | }); | 51 | }); |
52 | 52 | ||
53 | describe('#custom', () => { | 53 | describe('#custom', () => { |
54 | it('should return correct price', () => { | 54 | it('should return correct price', () => { |
55 | const msg = 'HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105'; | 55 | const msg = 'HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105'; |
56 | const rule = { | 56 | const rule = { |
57 | pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp ([\\d\\.]+)', | 57 | pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp ([\\d\\.]+)', |
58 | match_idx: 1, | 58 | match_idx: 1, |
59 | } | 59 | } |
60 | irs.getPriceFromMessage(msg, rule).should.equal(5525); | 60 | irs.getPriceFromMessage(msg, rule).should.equal(5525); |
61 | should.not.exists(irs.getPriceFromMessage('kosong', rule)); | 61 | should.not.exists(irs.getPriceFromMessage('kosong', rule)); |
62 | }); | 62 | }); |
63 | }) | 63 | }) |
64 | }); | 64 | }); |
65 | 65 | ||
66 | describe('#getBalanceFromMessage', () => { | 66 | describe('#getBalanceFromMessage', () => { |
67 | 67 | ||
68 | describe('#some suppliers', () => { | 68 | describe('#some suppliers', () => { |
69 | it('should return correct price', () => { | 69 | it('should return correct price', () => { |
70 | irs.getBalanceFromMessage('Trx S10 085212341234 BERHASIL, Harga: 5.285 SN: 41002553325946 Saldo: 2.284.011 - 5.285 = 2.278.726 @24/06/2018 18:38:06') | 70 | irs.getBalanceFromMessage('Trx S10 085212341234 BERHASIL, Harga: 5.285 SN: 41002553325946 Saldo: 2.284.011 - 5.285 = 2.278.726 @24/06/2018 18:38:06') |
71 | .should.equal(2278726, 'tajir balance'); | 71 | .should.equal(2278726, 'tajir balance'); |
72 | }); | 72 | }); |
73 | }); | 73 | }); |
74 | 74 | ||
75 | 75 | ||
76 | describe('#custom', () => { | 76 | describe('#custom', () => { |
77 | it('should return correct price', () => { | 77 | it('should return correct price', () => { |
78 | const msg = 'HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105'; | 78 | const msg = 'HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105'; |
79 | const rule = { | 79 | const rule = { |
80 | pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp (?:[\\d\\.]+) = Rp ([\\d\\.]+)', | 80 | pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp (?:[\\d\\.]+) = Rp ([\\d\\.]+)', |
81 | match_idx: 1, | 81 | match_idx: 1, |
82 | } | 82 | } |
83 | irs.getBalanceFromMessage(msg, rule).should.equal(490105); | 83 | irs.getBalanceFromMessage(msg, rule).should.equal(490105); |
84 | should.not.exists(irs.getBalanceFromMessage('kosong', rule)); | 84 | should.not.exists(irs.getBalanceFromMessage('kosong', rule)); |
85 | }); | 85 | }); |
86 | }) | 86 | }) |
87 | }); | 87 | }); |
88 | 88 | ||
89 | describe('#getSnFromMessage', () => { | 89 | describe('#getSnFromMessage', () => { |
90 | it('should return correct result', () => { | 90 | it('should return correct result', () => { |
91 | irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN: 99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN: 99971113094584'); | 91 | irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN: 99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN: 99971113094584'); |
92 | irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN:99971113094584'); | 92 | irs.getSnFromMessage('HX5 No.087781522208 Berhasil SN:99971113094584 Tgl 2019-13-11 12:31:47.Saldo Anda 495.630 - Rp 5.525 = Rp 490.105').should.equal('99971113094584', 'SN:99971113094584'); |
93 | irs.getSnFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36') | 93 | irs.getSnFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36') |
94 | .should.equal('0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment'); | 94 | .should.equal('0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment'); |
95 | }); | 95 | }); |
96 | }); | 96 | }); |
97 | 97 | ||
98 | describe('#getDetailFromMessage', () => { | 98 | describe('#getDetailFromMessage', () => { |
99 | it('should return correct result', () => { | 99 | it('should return correct result', () => { |
100 | irs.getDetailFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16') | 100 | irs.getDetailFromMessage('REFF#1238 CEK TAGIHAN PLN16 SUKSES IDPEL:538710624871 Detail: NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041 Sisa Saldo: 180.318 - 0 = 180.318 @29/12/2017 9:48:16') |
101 | .should.equal('NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041', 'postpaid inquiry success'); | 101 | .should.equal('NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041', 'postpaid inquiry success'); |
102 | 102 | ||
103 | irs.getDetailFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36') | 103 | irs.getDetailFromMessage('REFF#22955367 BAYAR TAGIHAN PLN25 SUKSES IDPEL:173300992349 Detail:S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560 Sisa Saldo: 40.653.798 - 140.960 = 40.512.838 @2019/11/28 11:44:36') |
104 | .should.equal('S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment'); | 104 | .should.equal('S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560', 'kiosbayar postpaid payment'); |
105 | 105 | ||
106 | irs.getDetailFromMessage('REFF#561744 CEK TAGIHAN PLN25 SUKSES IDPEL:172000147469 Detail: NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALTAGIHAN:81840 Sisa Saldo: 1.000.000 - 0 = 1.000.000 @2019/12/20 19:41:21') | 106 | irs.getDetailFromMessage('REFF#561744 CEK TAGIHAN PLN25 SUKSES IDPEL:172000147469 Detail: NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALTAGIHAN:81840 Sisa Saldo: 1.000.000 - 0 = 1.000.000 @2019/12/20 19:41:21') |
107 | .should.equal('NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALTAGIHAN:81840'); | 107 | .should.equal('NAMA:MASJID-NURUL-IMAN/DAYA:900/TARIF:S2/JMLBLN:1BLN/PERIODE:201912/METERKINI:19627/METERLALU:19428/TAGIHAN:79340/ADM:2500/DENDA:0/TOTALTAGIHAN:81840'); |
108 | }); | 108 | }); |
109 | 109 | ||
110 | it('should return correct result with tajira response', () => { | 110 | it('should return correct result with tajira response', () => { |
111 | const detailPattern = { | 111 | const detailPattern = { |
112 | pattern: '(REFID: .*?)($|(, *SALDO))', | 112 | pattern: '(REFID: .*?)($|(, *SALDO))', |
113 | match_idx: 1, | 113 | match_idx: 1, |
114 | }; | 114 | }; |
115 | 115 | ||
116 | const detailReplacements = [ | 116 | const detailReplacements = [ |
117 | { | 117 | { |
118 | pattern: ' *\\.\\.+ *', | 118 | pattern: ' *\\.\\.+ *', |
119 | replacement: '/', | 119 | replacement: '/', |
120 | flags: 'g', | 120 | flags: 'g', |
121 | }, | 121 | }, |
122 | { | 122 | { |
123 | pattern: ' *, *', | 123 | pattern: ' *, *', |
124 | replacement: '/', | 124 | replacement: '/', |
125 | flags: 'g', | 125 | flags: 'g', |
126 | }, | 126 | }, |
127 | { | 127 | { |
128 | pattern: ' *: *', | 128 | pattern: ' *: *', |
129 | replacement: ':', | 129 | replacement: ':', |
130 | flags: 'g', | 130 | flags: 'g', |
131 | }, | 131 | }, |
132 | { | 132 | { |
133 | pattern: 'TOTAL TAGIHAN*', | 133 | pattern: 'TOTAL TAGIHAN*', |
134 | replacement: 'TOTALTAGIHAN', | 134 | replacement: 'TOTALTAGIHAN', |
135 | }, | 135 | }, |
136 | ] | 136 | ] |
137 | 137 | ||
138 | irs.getDetailFromMessage( | 138 | irs.getDetailFromMessage( |
139 | 'Cek Tagihan PLN SUKSES ke 520550410074, REFID: 520550410074/MASJID.. KATEGORI:S2/900 , PERIODE:092020, JUMLAH:1, TOTAL TAGIHAN : 72.010', | 139 | 'Cek Tagihan PLN SUKSES ke 520550410074, REFID: 520550410074/MASJID.. KATEGORI:S2/900 , PERIODE:092020, JUMLAH:1, TOTAL TAGIHAN : 72.010', |
140 | detailPattern, | 140 | detailPattern, |
141 | detailReplacements | 141 | detailReplacements |
142 | ).should.equal('REFID:520550410074/MASJID/KATEGORI:S2/900/PERIODE:092020/JUMLAH:1/TOTALTAGIHAN:72.010', 'TAJIRA PLN POSTPAID'); | 142 | ).should.equal('REFID:520550410074/MASJID/KATEGORI:S2/900/PERIODE:092020/JUMLAH:1/TOTALTAGIHAN:72.010', 'TAJIRA PLN POSTPAID'); |
143 | 143 | ||
144 | // const detailPattern2 = { | 144 | // const detailPattern2 = { |
145 | // pattern: '(REFID: .*), SALDO', | 145 | // pattern: '(REFID: .*), SALDO', |
146 | // match_idx: 1, | 146 | // match_idx: 1, |
147 | // }; | 147 | // }; |
148 | 148 | ||
149 | irs.getDetailFromMessage( | 149 | irs.getDetailFromMessage( |
150 | 'CEK TAGIHAN PLNFULL SUKSES KE 520550388323, REFID: 52055038832320700700.. NAMA:MUSHOLA AL AMIN, KATEGORIDAYA:S2/450, PERIODE:092020, TAGIHANASLI:16620, DENDA:3000, ADMIN:2750, TOTALBAYAR:19.370, SALDO:500.000', | 150 | 'CEK TAGIHAN PLNFULL SUKSES KE 520550388323, REFID: 52055038832320700700.. NAMA:MUSHOLA AL AMIN, KATEGORIDAYA:S2/450, PERIODE:092020, TAGIHANASLI:16620, DENDA:3000, ADMIN:2750, TOTALBAYAR:19.370, SALDO:500.000', |
151 | detailPattern, | 151 | detailPattern, |
152 | detailReplacements | 152 | detailReplacements |
153 | ).should.equal( | 153 | ).should.equal( |
154 | 'REFID:52055038832320700700/NAMA:MUSHOLA AL AMIN/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:16620/DENDA:3000/ADMIN:2750/TOTALBAYAR:19.370', | 154 | 'REFID:52055038832320700700/NAMA:MUSHOLA AL AMIN/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:16620/DENDA:3000/ADMIN:2750/TOTALBAYAR:19.370', |
155 | 'TAJIRA PLN POSTPAID 2', | 155 | 'TAJIRA PLN POSTPAID 2', |
156 | ); | 156 | ); |
157 | 157 | ||
158 | }); | 158 | }); |
159 | }); | 159 | }); |
160 | 160 | ||
161 | describe('#splitPostpaidDetail', () => { | 161 | describe('#splitPostpaidDetail', () => { |
162 | it('should return correct result - inquiry', () => { | 162 | it('should return correct result - inquiry', () => { |
163 | const detail = 'NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041'; | 163 | const detail = 'NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041'; |
164 | const splitted = irs.splitPostpaidDetail(detail); | 164 | const splitted = irs.splitPostpaidDetail(detail); |
165 | 165 | ||
166 | splitted.should.ok(); | 166 | splitted.should.ok(); |
167 | splitted.find((item) => item.keyword === 'NAMA').value.should.equal('MUSHOLLA-NURUL-KHOIR'); | 167 | splitted.find((item) => item.keyword === 'NAMA').value.should.equal('MUSHOLLA-NURUL-KHOIR'); |
168 | splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('14441'); | 168 | splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('14441'); |
169 | splitted.find((item) => item.keyword === 'DENDA').value.should.equal('3000'); | 169 | splitted.find((item) => item.keyword === 'DENDA').value.should.equal('3000'); |
170 | }); | 170 | }); |
171 | 171 | ||
172 | it('should return correct result - pay', () => { | 172 | it('should return correct result - pay', () => { |
173 | const detail = 'S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560'; | 173 | const detail = 'S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560'; |
174 | const splitted = irs.splitPostpaidDetail(detail); | 174 | const splitted = irs.splitPostpaidDetail(detail); |
175 | 175 | ||
176 | splitted.should.ok(); | 176 | splitted.should.ok(); |
177 | splitted.find((item) => item.keyword === 'SN').value.should.equal('0BNS25G5082152526173'); | 177 | splitted.find((item) => item.keyword === 'SN').value.should.equal('0BNS25G5082152526173'); |
178 | splitted.find((item) => item.keyword === 'NAMA').value.should.equal('DONAR-HARHAP'); | 178 | splitted.find((item) => item.keyword === 'NAMA').value.should.equal('DONAR-HARHAP'); |
179 | splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('131560'); | 179 | splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('131560'); |
180 | splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000'); | 180 | splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000'); |
181 | }); | 181 | }); |
182 | |||
183 | it('should return correct result - tajira', () => { | ||
184 | const splitted = irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'); | ||
185 | // console.log(splitted); | ||
186 | splitted.find((item) => item.keyword === 'REFID').value.should.equal('20770812'); | ||
187 | splitted.find((item) => item.keyword === 'Admin').value.should.equal('2500'); | ||
188 | }); | ||
182 | }); | 189 | }); |
183 | 190 | ||
184 | describe('#calculateBaseBillAmount', () => { | 191 | describe('#calculateBaseBillAmount', () => { |
185 | it('should return correct value - inquiry', () => { | 192 | it('should return correct value - inquiry', () => { |
186 | const detail = 'NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041'; | 193 | const detail = 'NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041'; |
187 | const splitted = irs.splitPostpaidDetail(detail); | 194 | const splitted = irs.splitPostpaidDetail(detail); |
188 | 195 | ||
189 | irs.calculateBaseBillAmount(splitted).should.equal(17441); | 196 | irs.calculateBaseBillAmount(splitted).should.equal(17441); |
190 | 197 | ||
191 | }) | 198 | }) |
192 | 199 | ||
193 | it('should return correct value - payment', () => { | 200 | it('should return correct value - payment', () => { |
194 | const detail = 'S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560'; | 201 | const detail = 'S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560'; |
195 | const splitted = irs.splitPostpaidDetail(detail); | 202 | const splitted = irs.splitPostpaidDetail(detail); |
196 | 203 | ||
197 | // console.log('--- DEBUG'); | 204 | // console.log('--- DEBUG'); |
198 | // console.log(splitted); | 205 | // console.log(splitted); |
199 | // console.log('---'); | 206 | // console.log('---'); |
200 | 207 | ||
201 | irs.calculateBaseBillAmount(splitted).should.equal(140560, '#2CBDCEB8'); | 208 | irs.calculateBaseBillAmount(splitted).should.equal(140560, '#2CBDCEB8'); |
202 | 209 | ||
203 | }) | 210 | }) |
204 | 211 | ||
205 | it('should return correct value - inquiry - tajira', () => { | 212 | it('should return correct value - inquiry - tajira', () => { |
206 | const detail = 'REFID:52055038964420747312/NAMA:MASJID AN NUR/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:7140/DENDA:3000/ADMIN:2750/TOTALBAYAR:12.890'; | 213 | const detail = 'REFID:52055038964420747312/NAMA:MASJID AN NUR/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:7140/DENDA:3000/ADMIN:2750/TOTALBAYAR:12.890'; |
207 | const splitted = irs.splitPostpaidDetail(detail); | 214 | const splitted = irs.splitPostpaidDetail(detail); |
208 | 215 | ||
209 | irs.calculateBaseBillAmount( | 216 | irs.calculateBaseBillAmount( |
210 | splitted, | 217 | splitted, |
211 | null, | 218 | null, |
212 | // { | 219 | // { |
213 | // KEYWORD_TAGASLI: 'TAGIHANASLI,DENDA', | 220 | // KEYWORD_TAGASLI: 'TAGIHANASLI,DENDA', |
214 | // }, | 221 | // }, |
215 | // 1 | 222 | // 1 |
216 | ).should.equal(10140); | 223 | ).should.equal(10140); |
224 | |||
225 | irs.calculateBaseBillAmount( | ||
226 | irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'), | ||
227 | null, | ||
228 | { | ||
229 | KEYWORD_TOTALTAG: 'TOTALBAYAR', | ||
230 | KEYWORD_ADMINFEE: 'Admin', | ||
231 | }, | ||
232 | 1 | ||
233 | ).should.equal(25500); | ||
217 | }); | 234 | }); |
218 | }); | 235 | }); |
219 | 236 | ||
220 | describe('#getBillCount', () => { | 237 | describe('#getBillCount', () => { |
221 | it('should return correct value', () => { | 238 | it('should return correct value', () => { |
222 | 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); | 239 | 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); |
223 | 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')); | 240 | 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')); |
224 | should.not.exists(irs.getBillCount('')); | 241 | should.not.exists(irs.getBillCount('')); |
225 | should.not.exists(irs.getBillCount()); | 242 | should.not.exists(irs.getBillCount()); |
226 | }); | 243 | }); |
227 | }); | 244 | }); |
228 | }); | 245 | }); |