Commit a42ac8d00ecf2e64163cb39f7c47607bfaa8aba0
1 parent
09e99f6add
Exists in
master
Perbaikan getBillCount. TESTED
Showing 2 changed files with 38 additions and 8 deletions Inline Diff
index.js
1 | /* eslint-disable no-console */ | 1 | /* eslint-disable no-console */ |
2 | "use strict"; | 2 | "use strict"; |
3 | 3 | ||
4 | const regexLooperReplace = require('tektrans-lib/regex-looper/replace'); | 4 | const regexLooperReplace = require('tektrans-lib/regex-looper/replace'); |
5 | const rcFromMsg = require('komodo-sdk/rc-from-msg'); | 5 | const rcFromMsg = require('komodo-sdk/rc-from-msg'); |
6 | const organicRc = require('./rc'); | 6 | const organicRc = require('./rc'); |
7 | 7 | ||
8 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | 8 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { |
9 | console.log('DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT detected'); | 9 | console.log('DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT detected'); |
10 | } | 10 | } |
11 | 11 | ||
12 | function isInquiryResponseMessage(msg) { | 12 | function isInquiryResponseMessage(msg) { |
13 | return (msg || '').indexOf('CEK TAGIHAN') >= 0; | 13 | return (msg || '').indexOf('CEK TAGIHAN') >= 0; |
14 | } | 14 | } |
15 | 15 | ||
16 | function isPaymentResponseMessage(msg) { | 16 | function isPaymentResponseMessage(msg) { |
17 | return (msg || '').indexOf('BAYAR TAGIHAN') >= 0; | 17 | return (msg || '').indexOf('BAYAR TAGIHAN') >= 0; |
18 | } | 18 | } |
19 | 19 | ||
20 | function isPostpaidResponseMessage(msg) { | 20 | function isPostpaidResponseMessage(msg) { |
21 | return isInquiryResponseMessage(msg) || isPaymentResponseMessage(msg); | 21 | return isInquiryResponseMessage(msg) || isPaymentResponseMessage(msg); |
22 | } | 22 | } |
23 | 23 | ||
24 | function getRcFromMessage(msg, customRc) { | 24 | function getRcFromMessage(msg, customRc) { |
25 | let rc; | 25 | let rc; |
26 | if (customRc && Array.isArray(customRc) && customRc.length) { | 26 | if (customRc && Array.isArray(customRc) && customRc.length) { |
27 | rc = rcFromMsg(msg, customRc); | 27 | rc = rcFromMsg(msg, customRc); |
28 | } | 28 | } |
29 | 29 | ||
30 | if (!rc) { | 30 | if (!rc) { |
31 | rc = rcFromMsg(msg, organicRc); | 31 | rc = rcFromMsg(msg, organicRc); |
32 | } | 32 | } |
33 | 33 | ||
34 | return rc; | 34 | return rc; |
35 | } | 35 | } |
36 | 36 | ||
37 | function getPriceFromMessage(msg, rule) { | 37 | function getPriceFromMessage(msg, rule) { |
38 | if (typeof msg !== 'string') { | 38 | if (typeof msg !== 'string') { |
39 | return; | 39 | return; |
40 | } | 40 | } |
41 | 41 | ||
42 | if (process.env.DEBUG_IRS && !rule) { | 42 | if (process.env.DEBUG_IRS && !rule) { |
43 | console.log('** IRS.getPriceFromMessage no rule'); // eslint-disable-line no-console | 43 | console.log('** IRS.getPriceFromMessage no rule'); // eslint-disable-line no-console |
44 | } | 44 | } |
45 | 45 | ||
46 | if (process.env.DEBUG_IRS && rule) { | 46 | if (process.env.DEBUG_IRS && rule) { |
47 | console.log('** IRS.getPriceFromMessage rule: ' + JSON.stringify(rule, null, 2)); // eslint-disable-line no-console | 47 | console.log('** IRS.getPriceFromMessage rule: ' + JSON.stringify(rule, null, 2)); // eslint-disable-line no-console |
48 | } | 48 | } |
49 | 49 | ||
50 | //const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "Harga: ([\\d\\.]+?) "; | 50 | //const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "Harga: ([\\d\\.]+?) "; |
51 | const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "\\d+\\s+-\\s+([\\d,\\.]+)\\s+="; | 51 | const pattern = (rule && typeof rule.pattern === 'string') ? rule.pattern : "\\d+\\s+-\\s+([\\d,\\.]+)\\s+="; |
52 | const match_idx = (rule && typeof rule.match_idx === 'number') ? rule.match_idx : 1; | 52 | const match_idx = (rule && typeof rule.match_idx === 'number') ? rule.match_idx : 1; |
53 | 53 | ||
54 | const re = new RegExp(pattern); | 54 | const re = new RegExp(pattern); |
55 | const matches = msg.match(re); | 55 | const matches = msg.match(re); |
56 | if (process.env.DEBUG_IRS) { | 56 | if (process.env.DEBUG_IRS) { |
57 | console.log('** IRS.getPriceFromMessage msg: "' + msg + '" active_pattern: "' + pattern + '" active_match_idx: ' + match_idx); // eslint-disable-line no-console | 57 | console.log('** IRS.getPriceFromMessage msg: "' + msg + '" active_pattern: "' + pattern + '" active_match_idx: ' + match_idx); // eslint-disable-line no-console |
58 | console.log('** IRS.getPriceFromMessage matches:\n' + JSON.stringify(matches)); // eslint-disable-line no-console | 58 | console.log('** IRS.getPriceFromMessage matches:\n' + JSON.stringify(matches)); // eslint-disable-line no-console |
59 | } | 59 | } |
60 | 60 | ||
61 | if (matches && matches[match_idx]) { | 61 | if (matches && matches[match_idx]) { |
62 | const result = Number(matches[match_idx].replace(/\./g, '')); | 62 | const result = Number(matches[match_idx].replace(/\./g, '')); |
63 | if (process.env.DEBUG_IRS) { | 63 | if (process.env.DEBUG_IRS) { |
64 | console.log('** IRS.getPriceFromMessage SUPPLIER-PRICE: ' + result); // eslint-disable-line no-console | 64 | console.log('** IRS.getPriceFromMessage SUPPLIER-PRICE: ' + result); // eslint-disable-line no-console |
65 | } | 65 | } |
66 | return result; | 66 | return result; |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | function extractFromMessage(msg, rule) { | 70 | function extractFromMessage(msg, rule) { |
71 | if (typeof msg !== 'string') { return; } | 71 | if (typeof msg !== 'string') { return; } |
72 | 72 | ||
73 | if (!rule) { return; } | 73 | if (!rule) { return; } |
74 | 74 | ||
75 | if (typeof rule !== 'object') { | 75 | if (typeof rule !== 'object') { |
76 | return; | 76 | return; |
77 | } | 77 | } |
78 | 78 | ||
79 | rule.match_idx = Number(rule.match_idx); | 79 | rule.match_idx = Number(rule.match_idx); |
80 | 80 | ||
81 | if (!rule.match_idx) { | 81 | if (!rule.match_idx) { |
82 | rule.match_idx = 1; | 82 | rule.match_idx = 1; |
83 | } | 83 | } |
84 | 84 | ||
85 | const re = new RegExp(rule.pattern); | 85 | const re = new RegExp(rule.pattern); |
86 | const matches = msg.match(re); | 86 | const matches = msg.match(re); |
87 | if (matches && matches[rule.match_idx] && typeof matches[rule.match_idx] === 'string') { | 87 | if (matches && matches[rule.match_idx] && typeof matches[rule.match_idx] === 'string') { |
88 | return matches[rule.match_idx]; | 88 | return matches[rule.match_idx]; |
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
92 | function getSnFromMessage(msg, rule) { | 92 | function getSnFromMessage(msg, rule) { |
93 | if (!rule) { | 93 | if (!rule) { |
94 | rule = { | 94 | rule = { |
95 | pattern: "[: ]S/*N:\\s*(.+?)\\s", | 95 | pattern: "[: ]S/*N:\\s*(.+?)\\s", |
96 | match_idx: 1 | 96 | match_idx: 1 |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | let sn = extractFromMessage(msg, rule); | 100 | let sn = extractFromMessage(msg, rule); |
101 | if (!sn || typeof sn !== 'string') { return; } | 101 | if (!sn || typeof sn !== 'string') { return; } |
102 | 102 | ||
103 | return sn.toUpperCase().replace(/[^a-zA-Z0-9:,/]/g, '-').replace(/-+/g, '-').replace(/-*\/-*/g, '/').replace(/^-+/, '').replace(/-+$/, ''); | 103 | return sn.toUpperCase().replace(/[^a-zA-Z0-9:,/]/g, '-').replace(/-+/g, '-').replace(/-*\/-*/g, '/').replace(/^-+/, '').replace(/-+$/, ''); |
104 | } | 104 | } |
105 | 105 | ||
106 | function getBalanceFromMessage(msg, rule) { | 106 | function getBalanceFromMessage(msg, rule) { |
107 | if (!rule) { | 107 | if (!rule) { |
108 | rule = { | 108 | rule = { |
109 | pattern: "Saldo: .+? = ([\\d\\.]+) ", | 109 | pattern: "Saldo: .+? = ([\\d\\.]+) ", |
110 | match_idx: 1 | 110 | match_idx: 1 |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | let result = extractFromMessage(msg, rule); | 114 | let result = extractFromMessage(msg, rule); |
115 | if (!result || typeof result !== 'string') { return; } | 115 | if (!result || typeof result !== 'string') { return; } |
116 | 116 | ||
117 | return Number(result.replace(/\D/g, '')); | 117 | return Number(result.replace(/\D/g, '')); |
118 | } | 118 | } |
119 | 119 | ||
120 | function getDetailFromMessage(msg, rule, replacementRules) { | 120 | function getDetailFromMessage(msg, rule, replacementRules) { |
121 | if (!rule) { | 121 | if (!rule) { |
122 | rule = { | 122 | rule = { |
123 | pattern: " Detail:\\s*(.+?)\\s+Sisa [Ss]aldo", | 123 | pattern: " Detail:\\s*(.+?)\\s+Sisa [Ss]aldo", |
124 | match_idx: 1, | 124 | match_idx: 1, |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | return ( | 128 | return ( |
129 | regexLooperReplace(extractFromMessage(msg, rule), replacementRules) || '' | 129 | regexLooperReplace(extractFromMessage(msg, rule), replacementRules) || '' |
130 | ).trim() || null; | 130 | ).trim() || null; |
131 | } | 131 | } |
132 | 132 | ||
133 | function splitPostpaidDetail(str) { | 133 | function splitPostpaidDetail(str) { |
134 | const retval = (str || '') | 134 | const retval = (str || '') |
135 | .split('/') | 135 | .split('/') |
136 | .map((item) => { | 136 | .map((item) => { |
137 | let [keyword, value] = item.split(/[:=]/); | 137 | let [keyword, value] = item.split(/[:=]/); |
138 | keyword = (keyword || '').trim() | 138 | keyword = (keyword || '').trim() |
139 | 139 | ||
140 | if (keyword === 'N') keyword = 'SN'; | 140 | if (keyword === 'N') keyword = 'SN'; |
141 | 141 | ||
142 | return { | 142 | return { |
143 | keyword, | 143 | keyword, |
144 | value: (value || '').trim(), | 144 | value: (value || '').trim(), |
145 | }; | 145 | }; |
146 | }) | 146 | }) |
147 | .filter((item) => item.keyword.length && item.value.length); | 147 | .filter((item) => item.keyword.length && item.value.length); |
148 | return retval; | 148 | return retval; |
149 | } | 149 | } |
150 | 150 | ||
151 | function calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval) { | 151 | function calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval) { |
152 | const tagihanAsliKeyvalKeywords = (productKeyval && productKeyval.KEYWORD_TAGASLI) ? productKeyval.KEYWORD_TAGASLI.split(/ *, */) | 152 | const tagihanAsliKeyvalKeywords = (productKeyval && productKeyval.KEYWORD_TAGASLI) ? productKeyval.KEYWORD_TAGASLI.split(/ *, */) |
153 | : null; | 153 | : null; |
154 | 154 | ||
155 | const keywords = (tagihanAsliKeyvalKeywords && Array.isArray(tagihanAsliKeyvalKeywords) && tagihanAsliKeyvalKeywords.length && tagihanAsliKeyvalKeywords) | 155 | const keywords = (tagihanAsliKeyvalKeywords && Array.isArray(tagihanAsliKeyvalKeywords) && tagihanAsliKeyvalKeywords.length && tagihanAsliKeyvalKeywords) |
156 | || customKeywords | 156 | || customKeywords |
157 | || ['TAGIHANASLI', 'TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA']; | 157 | || ['TAGIHANASLI', 'TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA']; |
158 | 158 | ||
159 | let retval = 0; | 159 | let retval = 0; |
160 | let detailCount = (detailSplitted || []).length; | 160 | let detailCount = (detailSplitted || []).length; |
161 | 161 | ||
162 | for (let i = 0; i < detailCount; i += 1) { | 162 | for (let i = 0; i < detailCount; i += 1) { |
163 | const item = detailSplitted[i]; | 163 | const item = detailSplitted[i]; |
164 | if (keywords.indexOf(item.keyword.toUpperCase()) >= 0) { | 164 | if (keywords.indexOf(item.keyword.toUpperCase()) >= 0) { |
165 | const value = (item.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''); | 165 | const value = (item.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''); |
166 | retval += Number(value) || 0; | 166 | retval += Number(value) || 0; |
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | return retval; | 170 | return retval; |
171 | } | 171 | } |
172 | 172 | ||
173 | function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, billCount) { | 173 | function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, billCount) { |
174 | if ( | 174 | if ( |
175 | !productKeyval | 175 | !productKeyval |
176 | || !productKeyval.KEYWORD_TOTALTAG | 176 | || !productKeyval.KEYWORD_TOTALTAG |
177 | || (!productKeyval.KEYWORD_ADMINFEE && !productKeyval.ADMINFEE) | 177 | || (!productKeyval.KEYWORD_ADMINFEE && !productKeyval.ADMINFEE) |
178 | ) { | 178 | ) { |
179 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | 179 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { |
180 | console.log(`=========== 0D299D07 using calculateBaseBillAmountAuto KEYWORD_TOTALTAG=${productKeyval.KEYWORD_TOTALTAG} KEYWORD_KEYWORD_ADMINFEE=${productKeyval.KEYWORD_ADMINFEE} KEYWORD_ADMINFEE=${productKeyval.ADMINFEE}`); | 180 | console.log(`=========== 0D299D07 using calculateBaseBillAmountAuto KEYWORD_TOTALTAG=${productKeyval.KEYWORD_TOTALTAG} KEYWORD_KEYWORD_ADMINFEE=${productKeyval.KEYWORD_ADMINFEE} KEYWORD_ADMINFEE=${productKeyval.ADMINFEE}`); |
181 | } | 181 | } |
182 | return calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval, billCount); | 182 | return calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval, billCount); |
183 | } | 183 | } |
184 | 184 | ||
185 | const billCountOrDefault = billCount || 1; | 185 | const billCountOrDefault = billCount || 1; |
186 | 186 | ||
187 | const totalTagihanKeyword = productKeyval.KEYWORD_TOTALTAG; | 187 | const totalTagihanKeyword = productKeyval.KEYWORD_TOTALTAG; |
188 | if (!totalTagihanKeyword) return 0; | 188 | if (!totalTagihanKeyword) return 0; |
189 | 189 | ||
190 | const totalTagihanItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === totalTagihanKeyword.toUpperCase()); | 190 | const totalTagihanItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === totalTagihanKeyword.toUpperCase()); |
191 | const totalTagihanValue = Number( | 191 | const totalTagihanValue = Number( |
192 | ((totalTagihanItem && totalTagihanItem.value) || '') | 192 | ((totalTagihanItem && totalTagihanItem.value) || '') |
193 | .trim() | 193 | .trim() |
194 | .replace(/^rp */i, '') | 194 | .replace(/^rp */i, '') |
195 | .replace(/\./g, '') | 195 | .replace(/\./g, '') |
196 | ); | 196 | ); |
197 | 197 | ||
198 | if (!totalTagihanValue) { | 198 | if (!totalTagihanValue) { |
199 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | 199 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { |
200 | console.log('=========== MISSING totalTagihanValue D7282FA7'); | 200 | console.log('=========== MISSING totalTagihanValue D7282FA7'); |
201 | } | 201 | } |
202 | 202 | ||
203 | return 0; | 203 | return 0; |
204 | } | 204 | } |
205 | 205 | ||
206 | const defaultAdminFee = Number(productKeyval.ADMINFEE || ''); | 206 | const defaultAdminFee = Number(productKeyval.ADMINFEE || ''); |
207 | 207 | ||
208 | const adminFeeKeyword = productKeyval.KEYWORD_ADMINFEE; | 208 | const adminFeeKeyword = productKeyval.KEYWORD_ADMINFEE; |
209 | if (!adminFeeKeyword && defaultAdminFee) { | 209 | if (!adminFeeKeyword && defaultAdminFee) { |
210 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | 210 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { |
211 | // eslint-disable-next-line no-console | 211 | // eslint-disable-next-line no-console |
212 | console.log('======== TOTAL TAGIHAN VALUE - (DEFAULT ADMIN FEE * BILL COUNT) D35E56AD') ; | 212 | console.log('======== TOTAL TAGIHAN VALUE - (DEFAULT ADMIN FEE * BILL COUNT) D35E56AD') ; |
213 | } | 213 | } |
214 | return totalTagihanValue - (defaultAdminFee * billCountOrDefault); | 214 | return totalTagihanValue - (defaultAdminFee * billCountOrDefault); |
215 | } | 215 | } |
216 | 216 | ||
217 | if (!adminFeeKeyword) { | 217 | if (!adminFeeKeyword) { |
218 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | 218 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { |
219 | // eslint-disable-next-line no-console | 219 | // eslint-disable-next-line no-console |
220 | console.log('======== Missing adminFeeKeyword'); | 220 | console.log('======== Missing adminFeeKeyword'); |
221 | } | 221 | } |
222 | 222 | ||
223 | return 0; | 223 | return 0; |
224 | } | 224 | } |
225 | 225 | ||
226 | const adminFeeItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === adminFeeKeyword.toUpperCase()); | 226 | const adminFeeItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === adminFeeKeyword.toUpperCase()); |
227 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { | 227 | if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) { |
228 | // eslint-disable-next-line no-console | 228 | // eslint-disable-next-line no-console |
229 | console.log(`======== adminFeeItem: ${adminFeeKeyword}`, adminFeeItem); | 229 | console.log(`======== adminFeeItem: ${adminFeeKeyword}`, adminFeeItem); |
230 | } | 230 | } |
231 | const adminFeeValue = Number((adminFeeItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, '')); | 231 | const adminFeeValue = Number((adminFeeItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, '')); |
232 | if (!adminFeeValue) return 0; | 232 | if (!adminFeeValue) return 0; |
233 | 233 | ||
234 | return totalTagihanValue - (adminFeeValue * billCountOrDefault); | 234 | return totalTagihanValue - (adminFeeValue * billCountOrDefault); |
235 | } | 235 | } |
236 | 236 | ||
237 | /** | 237 | /** |
238 | * get bill count from splitted detail | 238 | * get bill count from splitted detail |
239 | * @date 2020-10-02 | 239 | * @date 2020-10-02 |
240 | * @param {Object} detailSplitted | 240 | * @param {Object} detailSplitted |
241 | * @param {string} [customKeyword] | 241 | * @param {string} [customKeyword] |
242 | * @returns {number} | 242 | * @returns {number} |
243 | */ | 243 | */ |
244 | function getBillCount(detailSplitted, customKeyword) { | 244 | function getBillCount(detailSplitted, customKeyword) { |
245 | if (!detailSplitted) return 0; | 245 | if (!detailSplitted) return 0; |
246 | 246 | ||
247 | return Number( | 247 | return Number( |
248 | (customKeyword && detailSplitted[customKeyword]) | 248 | ( |
249 | || detailSplitted['JMLBLN'] | 249 | (customKeyword && detailSplitted[customKeyword]) |
250 | || '0' | 250 | || detailSplitted['JMLBLN'] |
251 | ); | 251 | || '' |
252 | ).replace(/\D+$/g, '') | ||
253 | ) || 0; | ||
252 | } | 254 | } |
253 | 255 | ||
254 | exports.getRcFromMessage = getRcFromMessage; | 256 | exports.getRcFromMessage = getRcFromMessage; |
255 | exports.getPriceFromMessage = getPriceFromMessage; | 257 | exports.getPriceFromMessage = getPriceFromMessage; |
256 | exports.getSnFromMessage = getSnFromMessage; | 258 | exports.getSnFromMessage = getSnFromMessage; |
257 | exports.getBalanceFromMessage = getBalanceFromMessage; | 259 | exports.getBalanceFromMessage = getBalanceFromMessage; |
258 | exports.isInquiryResponseMessage = isInquiryResponseMessage; | 260 | exports.isInquiryResponseMessage = isInquiryResponseMessage; |
259 | exports.isPaymentResponseMessage = isPaymentResponseMessage; | 261 | exports.isPaymentResponseMessage = isPaymentResponseMessage; |
260 | exports.isPostpaidResponseMessage = isPostpaidResponseMessage; | 262 | exports.isPostpaidResponseMessage = isPostpaidResponseMessage; |
261 | exports.getDetailFromMessage = getDetailFromMessage; | 263 | exports.getDetailFromMessage = getDetailFromMessage; |
262 | exports.splitPostpaidDetail = splitPostpaidDetail; | 264 | exports.splitPostpaidDetail = splitPostpaidDetail; |
263 | exports.calculateBaseBillAmount = calculateBaseBillAmount; | 265 | exports.calculateBaseBillAmount = calculateBaseBillAmount; |
264 | exports.getBillCount = getBillCount; | 266 | exports.getBillCount = getBillCount; |
265 | 267 |
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 | irs.getRcFromMessage('Trx PLN ke 0001465757368 GAGAL. NOMOR ID YANG ANDA MASUKKAN SALAH, MOHON TELITI KEMBALI 43.156.10').should.equal('14'); | 21 | irs.getRcFromMessage('Trx PLN ke 0001465757368 GAGAL. NOMOR ID YANG ANDA MASUKKAN SALAH, MOHON TELITI KEMBALI 43.156.10').should.equal('14'); |
22 | }); | 22 | }); |
23 | }); | 23 | }); |
24 | 24 | ||
25 | describe('#getPriceFromMessage', function() { | 25 | describe('#getPriceFromMessage', function() { |
26 | describe('#generic', function() { | 26 | describe('#generic', function() { |
27 | it('should return correct price', function() { | 27 | it('should return correct price', function() { |
28 | 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); | 28 | 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); |
29 | }); | 29 | }); |
30 | 30 | ||
31 | it('should handle postpaid response', () => { | 31 | it('should handle postpaid response', () => { |
32 | 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'); | 32 | 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'); |
33 | 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'); | 33 | 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'); |
34 | 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); | 34 | 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); |
35 | }) | 35 | }) |
36 | 36 | ||
37 | it('should handle missing price', function() { | 37 | it('should handle missing price', function() { |
38 | should.not.exist(irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL, SN: 503133415264594 @5/3/2018 1:34:13 PM')); | 38 | should.not.exist(irs.getPriceFromMessage('REFF#11538167 Trx IBP25.085736328877 BERHASIL, SN: 503133415264594 @5/3/2018 1:34:13 PM')); |
39 | }); | 39 | }); |
40 | }); | 40 | }); |
41 | 41 | ||
42 | describe('#eflashtron', function() { | 42 | describe('#eflashtron', function() { |
43 | it('should return correct price', function() { | 43 | it('should return correct price', function() { |
44 | 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); | 44 | 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); |
45 | }); | 45 | }); |
46 | }); | 46 | }); |
47 | 47 | ||
48 | describe('#some suppliers', () => { | 48 | describe('#some suppliers', () => { |
49 | it('should return correct price', () => { | 49 | it('should return correct price', () => { |
50 | 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') | 50 | 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') |
51 | .should.equal(5285, 'tajir price'); | 51 | .should.equal(5285, 'tajir price'); |
52 | }); | 52 | }); |
53 | }); | 53 | }); |
54 | 54 | ||
55 | describe('#custom', () => { | 55 | describe('#custom', () => { |
56 | it('should return correct price', () => { | 56 | it('should return correct price', () => { |
57 | 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'; | 57 | 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'; |
58 | const rule = { | 58 | const rule = { |
59 | pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp ([\\d\\.]+)', | 59 | pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp ([\\d\\.]+)', |
60 | match_idx: 1, | 60 | match_idx: 1, |
61 | } | 61 | } |
62 | irs.getPriceFromMessage(msg, rule).should.equal(5525); | 62 | irs.getPriceFromMessage(msg, rule).should.equal(5525); |
63 | should.not.exists(irs.getPriceFromMessage('kosong', rule)); | 63 | should.not.exists(irs.getPriceFromMessage('kosong', rule)); |
64 | }); | 64 | }); |
65 | }) | 65 | }) |
66 | }); | 66 | }); |
67 | 67 | ||
68 | describe('#getBalanceFromMessage', () => { | 68 | describe('#getBalanceFromMessage', () => { |
69 | 69 | ||
70 | describe('#some suppliers', () => { | 70 | describe('#some suppliers', () => { |
71 | it('should return correct price', () => { | 71 | it('should return correct price', () => { |
72 | 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') | 72 | 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') |
73 | .should.equal(2278726, 'tajir balance'); | 73 | .should.equal(2278726, 'tajir balance'); |
74 | }); | 74 | }); |
75 | }); | 75 | }); |
76 | 76 | ||
77 | 77 | ||
78 | describe('#custom', () => { | 78 | describe('#custom', () => { |
79 | it('should return correct price', () => { | 79 | it('should return correct price', () => { |
80 | 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'; | 80 | 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'; |
81 | const rule = { | 81 | const rule = { |
82 | pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp (?:[\\d\\.]+) = Rp ([\\d\\.]+)', | 82 | pattern: 'Saldo Anda (?:[\\d\\.]+) - Rp (?:[\\d\\.]+) = Rp ([\\d\\.]+)', |
83 | match_idx: 1, | 83 | match_idx: 1, |
84 | } | 84 | } |
85 | irs.getBalanceFromMessage(msg, rule).should.equal(490105); | 85 | irs.getBalanceFromMessage(msg, rule).should.equal(490105); |
86 | should.not.exists(irs.getBalanceFromMessage('kosong', rule)); | 86 | should.not.exists(irs.getBalanceFromMessage('kosong', rule)); |
87 | }); | 87 | }); |
88 | }) | 88 | }) |
89 | }); | 89 | }); |
90 | 90 | ||
91 | describe('#getSnFromMessage', () => { | 91 | describe('#getSnFromMessage', () => { |
92 | it('should return correct result', () => { | 92 | it('should return correct result', () => { |
93 | 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('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'); |
94 | 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'); | 94 | 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'); |
95 | 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') | 95 | 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') |
96 | .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'); | 96 | .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'); |
97 | }); | 97 | }); |
98 | }); | 98 | }); |
99 | 99 | ||
100 | describe('#getDetailFromMessage', () => { | 100 | describe('#getDetailFromMessage', () => { |
101 | it('should return correct result', () => { | 101 | it('should return correct result', () => { |
102 | 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') | 102 | 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') |
103 | .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'); | 103 | .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'); |
104 | 104 | ||
105 | 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') | 105 | 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') |
106 | .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'); | 106 | .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'); |
107 | 107 | ||
108 | 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') | 108 | 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') |
109 | .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'); | 109 | .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'); |
110 | }); | 110 | }); |
111 | 111 | ||
112 | it('should return correct result with htc postpaid bpjsks response', () => { | 112 | it('should return correct result with htc postpaid bpjsks response', () => { |
113 | const msg = 'CEK BPJSKS BERHASIL,SN:IDPEL:0001465757368,NAMA:BAMBANG PARTODEWO,CABANG:1101-SEMARANG,JML:,TOTALBAYAR:28.000'; | 113 | const msg = 'CEK BPJSKS BERHASIL,SN:IDPEL:0001465757368,NAMA:BAMBANG PARTODEWO,CABANG:1101-SEMARANG,JML:,TOTALBAYAR:28.000'; |
114 | 114 | ||
115 | const detailPattern = { | 115 | const detailPattern = { |
116 | pattern: 'SN:(.*)($|(, *SALDO))', | 116 | pattern: 'SN:(.*)($|(, *SALDO))', |
117 | match_idx: 1, | 117 | match_idx: 1, |
118 | }; | 118 | }; |
119 | 119 | ||
120 | const detailReplacements = [ | 120 | const detailReplacements = [ |
121 | { | 121 | { |
122 | pattern: ' *\\.\\.+ *', | 122 | pattern: ' *\\.\\.+ *', |
123 | replacement: '/', | 123 | replacement: '/', |
124 | flags: 'g', | 124 | flags: 'g', |
125 | }, | 125 | }, |
126 | { | 126 | { |
127 | pattern: ' *, *', | 127 | pattern: ' *, *', |
128 | replacement: '/', | 128 | replacement: '/', |
129 | flags: 'g', | 129 | flags: 'g', |
130 | }, | 130 | }, |
131 | { | 131 | { |
132 | pattern: ' *: *', | 132 | pattern: ' *: *', |
133 | replacement: ':', | 133 | replacement: ':', |
134 | flags: 'g', | 134 | flags: 'g', |
135 | }, | 135 | }, |
136 | ] | 136 | ] |
137 | 137 | ||
138 | irs.getDetailFromMessage( | 138 | irs.getDetailFromMessage( |
139 | msg, | 139 | msg, |
140 | detailPattern, | 140 | detailPattern, |
141 | detailReplacements | 141 | detailReplacements |
142 | ).should.equal('IDPEL:0001465757368/NAMA:BAMBANG PARTODEWO/CABANG:1101-SEMARANG/JML:/TOTALBAYAR:28.000', 'HTC BPJSK POSTPAID'); | 142 | ).should.equal('IDPEL:0001465757368/NAMA:BAMBANG PARTODEWO/CABANG:1101-SEMARANG/JML:/TOTALBAYAR:28.000', 'HTC BPJSK POSTPAID'); |
143 | 143 | ||
144 | }); | 144 | }); |
145 | 145 | ||
146 | it('should return correct result with tajira response', () => { | 146 | it('should return correct result with tajira response', () => { |
147 | const detailPattern = { | 147 | const detailPattern = { |
148 | pattern: '(REFID: .*?)($|(, *SALDO))', | 148 | pattern: '(REFID: .*?)($|(, *SALDO))', |
149 | match_idx: 1, | 149 | match_idx: 1, |
150 | }; | 150 | }; |
151 | 151 | ||
152 | const detailReplacements = [ | 152 | const detailReplacements = [ |
153 | { | 153 | { |
154 | pattern: ' *\\.\\.+ *', | 154 | pattern: ' *\\.\\.+ *', |
155 | replacement: '/', | 155 | replacement: '/', |
156 | flags: 'g', | 156 | flags: 'g', |
157 | }, | 157 | }, |
158 | { | 158 | { |
159 | pattern: ' *, *', | 159 | pattern: ' *, *', |
160 | replacement: '/', | 160 | replacement: '/', |
161 | flags: 'g', | 161 | flags: 'g', |
162 | }, | 162 | }, |
163 | { | 163 | { |
164 | pattern: ' *: *', | 164 | pattern: ' *: *', |
165 | replacement: ':', | 165 | replacement: ':', |
166 | flags: 'g', | 166 | flags: 'g', |
167 | }, | 167 | }, |
168 | { | 168 | { |
169 | pattern: 'TOTAL TAGIHAN*', | 169 | pattern: 'TOTAL TAGIHAN*', |
170 | replacement: 'TOTALTAGIHAN', | 170 | replacement: 'TOTALTAGIHAN', |
171 | }, | 171 | }, |
172 | ] | 172 | ] |
173 | 173 | ||
174 | irs.getDetailFromMessage( | 174 | irs.getDetailFromMessage( |
175 | 'Cek Tagihan PLN SUKSES ke 520550410074, REFID: 520550410074/MASJID.. KATEGORI:S2/900 , PERIODE:092020, JUMLAH:1, TOTAL TAGIHAN : 72.010', | 175 | 'Cek Tagihan PLN SUKSES ke 520550410074, REFID: 520550410074/MASJID.. KATEGORI:S2/900 , PERIODE:092020, JUMLAH:1, TOTAL TAGIHAN : 72.010', |
176 | detailPattern, | 176 | detailPattern, |
177 | detailReplacements | 177 | detailReplacements |
178 | ).should.equal('REFID:520550410074/MASJID/KATEGORI:S2/900/PERIODE:092020/JUMLAH:1/TOTALTAGIHAN:72.010', 'TAJIRA PLN POSTPAID'); | 178 | ).should.equal('REFID:520550410074/MASJID/KATEGORI:S2/900/PERIODE:092020/JUMLAH:1/TOTALTAGIHAN:72.010', 'TAJIRA PLN POSTPAID'); |
179 | 179 | ||
180 | // const detailPattern2 = { | 180 | // const detailPattern2 = { |
181 | // pattern: '(REFID: .*), SALDO', | 181 | // pattern: '(REFID: .*), SALDO', |
182 | // match_idx: 1, | 182 | // match_idx: 1, |
183 | // }; | 183 | // }; |
184 | 184 | ||
185 | irs.getDetailFromMessage( | 185 | irs.getDetailFromMessage( |
186 | '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', | 186 | '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', |
187 | detailPattern, | 187 | detailPattern, |
188 | detailReplacements | 188 | detailReplacements |
189 | ).should.equal( | 189 | ).should.equal( |
190 | 'REFID:52055038832320700700/NAMA:MUSHOLA AL AMIN/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:16620/DENDA:3000/ADMIN:2750/TOTALBAYAR:19.370', | 190 | 'REFID:52055038832320700700/NAMA:MUSHOLA AL AMIN/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:16620/DENDA:3000/ADMIN:2750/TOTALBAYAR:19.370', |
191 | 'TAJIRA PLN POSTPAID 2', | 191 | 'TAJIRA PLN POSTPAID 2', |
192 | ); | 192 | ); |
193 | 193 | ||
194 | irs.getDetailFromMessage( | 194 | irs.getDetailFromMessage( |
195 | 'Cek Tagihan BPJSKH2H SUKSES ke 0002058343828, REFID: 20809404.. NAMA:SALWA AZ ZAHRA, CABANG:1012-DEPOK, Periode:1,Admin:2500, TOTALBAYAR:28.000, SALDO:186.856', | 195 | 'Cek Tagihan BPJSKH2H SUKSES ke 0002058343828, REFID: 20809404.. NAMA:SALWA AZ ZAHRA, CABANG:1012-DEPOK, Periode:1,Admin:2500, TOTALBAYAR:28.000, SALDO:186.856', |
196 | detailPattern, | 196 | detailPattern, |
197 | detailReplacements, | 197 | detailReplacements, |
198 | ).should.equal( | 198 | ).should.equal( |
199 | 'REFID:20809404/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000', | 199 | 'REFID:20809404/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000', |
200 | 'TAJIRA BPJS', | 200 | 'TAJIRA BPJS', |
201 | ) | 201 | ) |
202 | 202 | ||
203 | }); | 203 | }); |
204 | }); | 204 | }); |
205 | 205 | ||
206 | describe('#splitPostpaidDetail', () => { | 206 | describe('#splitPostpaidDetail', () => { |
207 | it('should handle invalid input', () => { | 207 | it('should handle invalid input', () => { |
208 | irs.splitPostpaidDetail(null).length.should.equal(0); | 208 | irs.splitPostpaidDetail(null).length.should.equal(0); |
209 | irs.splitPostpaidDetail('').length.should.equal(0); | 209 | irs.splitPostpaidDetail('').length.should.equal(0); |
210 | }); | 210 | }); |
211 | 211 | ||
212 | it('should return correct result - inquiry', () => { | 212 | it('should return correct result - inquiry', () => { |
213 | 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'; | 213 | 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'; |
214 | const splitted = irs.splitPostpaidDetail(detail); | 214 | const splitted = irs.splitPostpaidDetail(detail); |
215 | 215 | ||
216 | splitted.should.ok(); | 216 | splitted.should.ok(); |
217 | splitted.find((item) => item.keyword === 'NAMA').value.should.equal('MUSHOLLA-NURUL-KHOIR'); | 217 | splitted.find((item) => item.keyword === 'NAMA').value.should.equal('MUSHOLLA-NURUL-KHOIR'); |
218 | splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('14441'); | 218 | splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('14441'); |
219 | splitted.find((item) => item.keyword === 'DENDA').value.should.equal('3000'); | 219 | splitted.find((item) => item.keyword === 'DENDA').value.should.equal('3000'); |
220 | }); | 220 | }); |
221 | 221 | ||
222 | it('should return correct result - pay', () => { | 222 | it('should return correct result - pay', () => { |
223 | 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'; | 223 | 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'; |
224 | const splitted = irs.splitPostpaidDetail(detail); | 224 | const splitted = irs.splitPostpaidDetail(detail); |
225 | 225 | ||
226 | splitted.should.ok(); | 226 | splitted.should.ok(); |
227 | splitted.find((item) => item.keyword === 'SN').value.should.equal('0BNS25G5082152526173'); | 227 | splitted.find((item) => item.keyword === 'SN').value.should.equal('0BNS25G5082152526173'); |
228 | splitted.find((item) => item.keyword === 'NAMA').value.should.equal('DONAR-HARHAP'); | 228 | splitted.find((item) => item.keyword === 'NAMA').value.should.equal('DONAR-HARHAP'); |
229 | splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('131560'); | 229 | splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('131560'); |
230 | splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000'); | 230 | splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000'); |
231 | }); | 231 | }); |
232 | 232 | ||
233 | it('should return correct result - tajira', () => { | 233 | it('should return correct result - tajira', () => { |
234 | const splitted = irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'); | 234 | const splitted = irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'); |
235 | // console.log(splitted); | 235 | // console.log(splitted); |
236 | splitted.find((item) => item.keyword === 'REFID').value.should.equal('20770812'); | 236 | splitted.find((item) => item.keyword === 'REFID').value.should.equal('20770812'); |
237 | splitted.find((item) => item.keyword === 'Admin').value.should.equal('2500'); | 237 | splitted.find((item) => item.keyword === 'Admin').value.should.equal('2500'); |
238 | 238 | ||
239 | const splitted2 = irs.splitPostpaidDetail('REFID:20809404/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'); | 239 | const splitted2 = irs.splitPostpaidDetail('REFID:20809404/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'); |
240 | splitted2.find((item) => item.keyword === 'TOTALBAYAR').value.should.equal('28.000', 'TAJIRA BPJS'); | 240 | splitted2.find((item) => item.keyword === 'TOTALBAYAR').value.should.equal('28.000', 'TAJIRA BPJS'); |
241 | }); | 241 | }); |
242 | }); | 242 | }); |
243 | 243 | ||
244 | describe('#calculateBaseBillAmount', () => { | 244 | describe('#calculateBaseBillAmount', () => { |
245 | it('should return correct value - inquiry', () => { | 245 | it('should return correct value - inquiry', () => { |
246 | 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'; | 246 | 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'; |
247 | const splitted = irs.splitPostpaidDetail(detail); | 247 | const splitted = irs.splitPostpaidDetail(detail); |
248 | 248 | ||
249 | irs.calculateBaseBillAmount(splitted).should.equal(17441); | 249 | irs.calculateBaseBillAmount(splitted).should.equal(17441); |
250 | 250 | ||
251 | }) | 251 | }) |
252 | 252 | ||
253 | it('should return correct value - payment', () => { | 253 | it('should return correct value - payment', () => { |
254 | 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'; | 254 | 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'; |
255 | const splitted = irs.splitPostpaidDetail(detail); | 255 | const splitted = irs.splitPostpaidDetail(detail); |
256 | 256 | ||
257 | // console.log('--- DEBUG'); | 257 | // console.log('--- DEBUG'); |
258 | // console.log(splitted); | 258 | // console.log(splitted); |
259 | // console.log('---'); | 259 | // console.log('---'); |
260 | 260 | ||
261 | irs.calculateBaseBillAmount(splitted).should.equal(140560, '#2CBDCEB8'); | 261 | irs.calculateBaseBillAmount(splitted).should.equal(140560, '#2CBDCEB8'); |
262 | 262 | ||
263 | }) | 263 | }) |
264 | 264 | ||
265 | it('should return correct value - inquiry - tajira', () => { | 265 | it('should return correct value - inquiry - tajira', () => { |
266 | const detail = 'REFID:52055038964420747312/NAMA:MASJID AN NUR/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:7140/DENDA:3000/ADMIN:2750/TOTALBAYAR:12.890'; | 266 | const detail = 'REFID:52055038964420747312/NAMA:MASJID AN NUR/KATEGORIDAYA:S2/450/PERIODE:092020/TAGIHANASLI:7140/DENDA:3000/ADMIN:2750/TOTALBAYAR:12.890'; |
267 | const splitted = irs.splitPostpaidDetail(detail); | 267 | const splitted = irs.splitPostpaidDetail(detail); |
268 | 268 | ||
269 | irs.calculateBaseBillAmount( | 269 | irs.calculateBaseBillAmount( |
270 | splitted, | 270 | splitted, |
271 | null, | 271 | null, |
272 | // { | 272 | // { |
273 | // KEYWORD_TAGASLI: 'TAGIHANASLI,DENDA', | 273 | // KEYWORD_TAGASLI: 'TAGIHANASLI,DENDA', |
274 | // }, | 274 | // }, |
275 | // 1 | 275 | // 1 |
276 | ).should.equal(10140); | 276 | ).should.equal(10140); |
277 | 277 | ||
278 | irs.calculateBaseBillAmount( | 278 | irs.calculateBaseBillAmount( |
279 | irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'), | 279 | irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'), |
280 | null, | 280 | null, |
281 | { | 281 | { |
282 | KEYWORD_TOTALTAG: 'TOTALBAYAR', | 282 | KEYWORD_TOTALTAG: 'TOTALBAYAR', |
283 | KEYWORD_ADMINFEE: 'Admin', | 283 | KEYWORD_ADMINFEE: 'Admin', |
284 | }, | 284 | }, |
285 | 1 | 285 | 1 |
286 | ).should.equal(25500); | 286 | ).should.equal(25500); |
287 | 287 | ||
288 | const productKeyvalBPJSK = { | 288 | const productKeyvalBPJSK = { |
289 | KEYWORD_TOTALTAG: 'TOTALBAYAR', | 289 | KEYWORD_TOTALTAG: 'TOTALBAYAR', |
290 | KEYWORD_ADMINFEE: 'Admin', | 290 | KEYWORD_ADMINFEE: 'Admin', |
291 | }; | 291 | }; |
292 | irs.calculateBaseBillAmount( | 292 | irs.calculateBaseBillAmount( |
293 | irs.splitPostpaidDetail('REFID:20809404/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'), | 293 | irs.splitPostpaidDetail('REFID:20809404/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'), |
294 | null, | 294 | null, |
295 | productKeyvalBPJSK, | 295 | productKeyvalBPJSK, |
296 | 1 | 296 | 1 |
297 | ).should.equal(25500, 'TAJIRA BPJS #8A46CFD1'); | 297 | ).should.equal(25500, 'TAJIRA BPJS #8A46CFD1'); |
298 | }); | 298 | }); |
299 | }); | 299 | }); |
300 | 300 | ||
301 | describe('#getBillCount', () => { | 301 | describe('#getBillCount', () => { |
302 | it('should return correct value', () => { | 302 | it('should return correct value', () => { |
303 | 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); | 303 | // 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); |
304 | 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')); | 304 | irs.getBillCount({ |
305 | should.not.exists(irs.getBillCount('')); | 305 | NAMA: 'SUYATMAN', |
306 | should.not.exists(irs.getBillCount()); | 306 | DAYA: '900', |
307 | TARIF: 'R1M', | ||
308 | JMLBLN: 'BLN', | ||
309 | PERIODE: '201911,201912', | ||
310 | }).should.equal(0); | ||
311 | |||
312 | irs.getBillCount({ | ||
313 | NAMA: 'SUYATMAN', | ||
314 | DAYA: '900', | ||
315 | TARIF: 'R1M', | ||
316 | JMLBLN: '2', | ||
317 | PERIODE: '201911,201912', | ||
318 | }).should.equal(2); | ||
319 | |||
320 | irs.getBillCount({ | ||
321 | NAMA: 'SUYATMAN', | ||
322 | DAYA: '900', | ||
323 | TARIF: 'R1M', | ||
324 | JMLBLN: '2BLN', | ||
325 | PERIODE: '201911,201912', | ||
326 | }, null).should.equal(2); | ||
327 | |||
328 | irs.getBillCount({ | ||
329 | NAMA: 'SUYATMAN', | ||
330 | DAYA: '900', | ||
331 | TARIF: 'R1M', | ||
332 | JML: '2BLN', | ||
333 | PERIODE: '201911,201912', | ||
334 | }, 'JML').should.equal(2); | ||
307 | }); | 335 | }); |
308 | }); | 336 | }); |
309 | }); | 337 | }); |