Commit 86e71ad257586dadc9b81a83a5885636975f33ee
1 parent
4f5d7f25ee
Exists in
master
splitRemoteProduct
Showing 2 changed files with 35 additions and 1 deletions Side-by-side Diff
partner-bnisp.js
... | ... | @@ -46,9 +46,14 @@ function topupRequest(task) { |
46 | 46 | _hitTopup(task); |
47 | 47 | } |
48 | 48 | |
49 | +function splitRemoteProduct(remoteProduct) { | |
50 | + return remoteProduct.replace(/^\s+|\s+$/gm,'').split(/[\/\W]+/); | |
51 | +} | |
52 | + | |
49 | 53 | function _hitTopup(task, isCheckStatus) { |
50 | 54 | |
51 | - const remoteProduct = task.remoteProduct.split('/'); | |
55 | + const remoteProduct = splitRemoteProduct(task.remoteProduct); | |
56 | + | |
52 | 57 | if (remoteProduct.length < 4) { |
53 | 58 | callbackReport(task.requestId, '40', 'INTERNAL_MSG: Invalid remoteProduct', task) |
54 | 59 | return; |
... | ... | @@ -242,3 +247,4 @@ exports.createUrlPath = createUrlPath; |
242 | 247 | exports.parseResponseBody = parseResponseBody; |
243 | 248 | exports.responseDataProcessor = responseDataProcessor; |
244 | 249 | exports.topupRequest = topupRequest; |
250 | +exports.splitRemoteProduct = splitRemoteProduct; |
test.js
... | ... | @@ -54,4 +54,32 @@ describe("#partner", function() { |
54 | 54 | processed.balance.should.equal(94950); |
55 | 55 | }) |
56 | 56 | }) |
57 | + | |
58 | + describe('#splitRemoteProduct', function() { | |
59 | + it ('should return correctly using space as separator', function() { | |
60 | + const remoteProduct = 'PULSA THREE5000 0 0'; | |
61 | + partner.splitRemoteProduct(remoteProduct)[0].should.equal('PULSA'); | |
62 | + partner.splitRemoteProduct(remoteProduct)[1].should.equal('THREE5000'); | |
63 | + partner.splitRemoteProduct(remoteProduct)[2].should.equal('0'); | |
64 | + partner.splitRemoteProduct(remoteProduct)[3].should.equal('0'); | |
65 | + }) | |
66 | + | |
67 | + it ('should return correctly using comma as separator', function() { | |
68 | + const remoteProduct = 'PULSA,THREE5000,0,0'; | |
69 | + partner.splitRemoteProduct(remoteProduct)[0].should.equal('PULSA'); | |
70 | + partner.splitRemoteProduct(remoteProduct)[1].should.equal('THREE5000'); | |
71 | + partner.splitRemoteProduct(remoteProduct)[2].should.equal('0'); | |
72 | + partner.splitRemoteProduct(remoteProduct)[3].should.equal('0'); | |
73 | + }) | |
74 | + | |
75 | + it ('should return correctly using slash as separator', function() { | |
76 | + const remoteProduct = 'PULSA/THREE5000/0/0'; | |
77 | + partner.splitRemoteProduct(remoteProduct)[0].should.equal('PULSA'); | |
78 | + partner.splitRemoteProduct(remoteProduct)[1].should.equal('THREE5000'); | |
79 | + partner.splitRemoteProduct(remoteProduct)[2].should.equal('0'); | |
80 | + partner.splitRemoteProduct(remoteProduct)[3].should.equal('0'); | |
81 | + }) | |
82 | + | |
83 | + | |
84 | + }) | |
57 | 85 | }) |