Commit d03db4675bcd4bece0ca69898964657480429e9f

Authored by Adhidarma Hadiwinoto
1 parent bb387d2ec8
Exists in master

sisa stock

Showing 2 changed files with 87 additions and 10 deletions Side-by-side Diff

partner-scrappingkisel.js
... ... @@ -88,10 +88,12 @@ function topupRequest(task) {
88 88 var ref_num = result.trx_response.ref_num.join(' ').trim();
89 89 var harga = result.trx_response.harga.join(' ').trim();
90 90 var kode_voucher = result.trx_response.kode_voucher.join(' ').trim();
  91 + var stocks = result.trx_response.stock(' ').trim();
  92 + var stock = parseStock(stocks, product);
91 93  
92 94 response_code = '00';
93 95  
94   - message = 'SN=' + kode_voucher + '; ' + product + ' ' + destination + ' ' + harga + ' ref_num: ' + ref_num + ' kode_voucher: ' + kode_voucher;
  96 + message = 'SN=' + kode_voucher + '; ' + product + ' ' + destination + ' ' + harga + ' ref_num: ' + ref_num + ' kode_voucher: ' + kode_voucher + ' sisa stock: ' + stock + ' unit';
95 97 }
96 98  
97 99 callbackReport(task['requestId'], response_code, message);
... ... @@ -104,5 +106,39 @@ function start(_config, _callbackReport) {
104 106 callbackReport = _callbackReport
105 107 }
106 108  
  109 +function stockKeyword(product_desc) {
  110 + var keywords = product_desc.match(/\s\d+K$/);
  111 + if (!keywords) {
  112 + return;
  113 + }
  114 +
  115 + if (keywords.length < 1) {
  116 + return;
  117 + }
  118 +
  119 + return keywords[0].trim();
  120 +}
  121 +
  122 +function parseStock(stocks, product_desc) {
  123 + product_keyword = stockKeyword(product_desc);
  124 +
  125 + var _stocks = stocks.split('; ');
  126 + count = _stocks.length;
  127 + for (var i = 0; i < count; i++) {
  128 + var stock = _stocks[i].split(' = ');
  129 + if (stock.length < 2) {
  130 + continue;
  131 + }
  132 +
  133 + if (stock[0] == product_keyword) {
  134 + return parseInt(stock[1]);
  135 + }
  136 + }
  137 +
  138 + return 0;
  139 +}
  140 +
107 141 exports.start = start;
108 142 exports.topupRequest = topupRequest;
  143 +exports.stockKeyword = stockKeyword;
  144 +exports.parseStock = parseStock;
... ... @@ -33,17 +33,58 @@ describe(&#39;aaa&#39;, function() {
33 33 });
34 34  
35 35 describe('aaa', function() {
36   - var partner = require('./httppulsakita');
  36 + var partner = require('./partner-scrappingkisel');
37 37  
38   - describe("#parseResult()", function() {
39   - message = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><respon><tanggal>2015/6/16 15:43:35</tanggal><idagen>P0039</idagen><refid>AEE15B32987941D89FFF4BC7EF676C13</refid><produk>PLN20</produk><tujuan>14204279369</tujuan><rc>0000</rc><data> </data><token> </token><pesan>#14836 PLN20 ke:14204279369 SUKSES. SN:3520-2887-6627-6699-4826/TestDummyPanjang6955555/P1/7000VA/32,4. \
40   -Sisa saldo Rp. 5,000,000 - Rp. 18,700 = Rp. 4,981,300</pesan></respon>';
41   -
42   - data = partner.parseResult(message);
43   - console.log(data);
  38 + describe("#stockKeyword", function() {
  39 + it('should return 10K', function() {
  40 + assert.equal('10K', partner.stockKeyword('Telkomsel 10K'));
  41 + });
  42 +
  43 + it('should return 20K', function() {
  44 + assert.equal('20K', partner.stockKeyword('Telkomsel 20K'));
  45 + });
  46 +
  47 + it('should return 25K', function() {
  48 + assert.equal('25K', partner.stockKeyword('Telkomsel 25K'));
  49 + });
  50 +
  51 + it('should return 50K', function() {
  52 + assert.equal('50K', partner.stockKeyword('Telkomsel 50K'));
  53 + });
  54 +
  55 + it('should return 100K', function() {
  56 + assert.equal('100K', partner.stockKeyword('Telkomsel 100K'));
  57 + });
  58 + });
  59 +
  60 + describe("#parseStock", function() {
  61 + it('should return 476', function() {
  62 + assert.equal(476, partner.parseStock('10K = 476; 20K = 598; 25K = 600; 50K = 700; 100K = 400; 150K = 0; 200K = 0; 300K = 0; 500K = 0', 'Telkomsel 10K'));
  63 + });
  64 +
  65 + it('should return 598', function() {
  66 + assert.equal(598, partner.parseStock('10K = 476; 20K = 598; 25K = 600; 50K = 700; 100K = 400; 150K = 0; 200K = 0; 300K = 0; 500K = 0', 'Telkomsel 20K'));
  67 + });
  68 +
  69 + it('should return 0', function() {
  70 + assert.equal(0, partner.parseStock('10K = 476; 20K = 598; 25K = 600; 50K = 700; 100K = 400; 150K = 0; 200K = 0; 300K = 0; 500K = 0', 'Telkomsel 200K'));
  71 + });
  72 +
  73 + it('should return 0', function() {
  74 + assert.equal(0, partner.parseStock('10K = 476; 20K = 598; 25K = 600; 50K = 700; 100K = 400; 150K = 0; 200K = 0; 300K = 0; 500K = 0', 'Telkomsel 2000K'));
  75 + });
  76 +
  77 + it('should return 0', function() {
  78 + assert.equal(0, partner.parseStock('10K = 476; 20K = 598; 25K = 600; 50K = 700; 100K = 400; 150K = 0; 200K = 0; 300K = 0; 500K = 0', 'Telkomsel 2000'));
  79 + });
44 80  
45   - it('should return 2015/6/16 15:43:35', function() {
46   - assert.equal('2015/6/16 15:43:35', data.respon.tanggal);
  81 + it('should return 0', function() {
  82 + assert.equal(0, partner.parseStock('', 'Telkomsel 2000'));
47 83 });
  84 +
  85 + it('should return 0', function() {
  86 + assert.equal(0, partner.parseStock('10K = 476; 20K = 598; 25K = 600; 50K = 700; 100K = 400; 150K = 0; 200K = 0; 300K = 0; 500K = 0', ''));
  87 + });
  88 +
48 89 });
49 90 });