Commit 9dc1005b5b4465ee4a5238ad95b62d82d9d7dff4

Authored by Adhidarma Hadiwinoto
1 parent 7ac39207f5
Exists in master

splitDetail

Showing 2 changed files with 42 additions and 0 deletions Side-by-side Diff

... ... @@ -123,6 +123,24 @@ function getDetailFromMessage(msg, rule) {
123 123 return (result || '').trim();
124 124 }
125 125  
  126 +function splitPostpaidDetail(str) {
  127 + const retval = (str || '')
  128 + .split('/')
  129 + .map((item) => {
  130 + let [keyword, value] = item.split(':');
  131 + keyword = (keyword || '').trim()
  132 +
  133 + if (keyword === 'N') keyword = 'SN';
  134 +
  135 + return {
  136 + keyword,
  137 + value: (value || '').trim(),
  138 + };
  139 + })
  140 + .filter((item) => item.keyword.length && item.value.length);
  141 + return retval;
  142 +}
  143 +
126 144 exports.getRcFromMessage = getRcFromMessage;
127 145 exports.getPriceFromMessage = getPriceFromMessage;
128 146 exports.getSnFromMessage = getSnFromMessage;
... ... @@ -131,3 +149,4 @@ exports.isInquiryResponseMessage = isInquiryResponseMessage;
131 149 exports.isPaymentResponseMessage = isPaymentResponseMessage;
132 150 exports.isPostpaidResponseMessage = isPostpaidResponseMessage;
133 151 exports.getDetailFromMessage = getDetailFromMessage;
  152 +exports.splitPostpaidDetail = splitPostpaidDetail;
134 153 \ No newline at end of file
... ... @@ -87,4 +87,27 @@ describe('#irs', function() {
87 87 });
88 88  
89 89 });
  90 +
  91 + describe('#splitPostpaidDetail', () => {
  92 + it('should return correct result - inquiry', () => {
  93 + 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';
  94 + const splitted = irs.splitPostpaidDetail(detail);
  95 +
  96 + splitted.should.ok();
  97 + splitted.find((item) => item.keyword === 'NAMA').value.should.equal('MUSHOLLA-NURUL-KHOIR');
  98 + splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('14441');
  99 + splitted.find((item) => item.keyword === 'DENDA').value.should.equal('3000');
  100 + });
  101 +
  102 + it('should return correct result - pay', () => {
  103 + 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';
  104 + const splitted = irs.splitPostpaidDetail(detail);
  105 +
  106 + splitted.should.ok();
  107 + splitted.find((item) => item.keyword === 'SN').value.should.equal('0BNS25G5082152526173');
  108 + splitted.find((item) => item.keyword === 'NAMA').value.should.equal('DONAR-HARHAP');
  109 + splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('131560');
  110 + splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000');
  111 + });
  112 + });
90 113 });
91 114 \ No newline at end of file