test.js
4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"use strict";
const should = require("should");
const partner = require("./partner-bnisp");
describe("#partner", function() {
describe("#createUrlPath", function() {
it('should return correct url path based on example', function() {
let options = {
noid: 1002003,
token: 'CIPY6t6ruy5UuGG0PCqu',
product: 'PULSA',
product_type: 'THREE5000',
id_pel: '0895385381299',
trace_id: 16
}
partner.createUrlPath(options).should.equal('/get/purchase/json/1002003/CIPY6t6ruy5UuGG0PCqu/PULSA/THREE5000/0895385381299/0/0/16')
})
})
describe("#createUrlPathAdvice", function() {
it('should return correct url path based on example', function() {
let options = {
noid: 1002003,
token: 'CIPY6t6ruy5UuGG0PCqu',
trace_id: 16
}
partner.createUrlPathAdvice(options).should.equal('/get/advice/json/1002003/CIPY6t6ruy5UuGG0PCqu/16')
})
})
const responseBody = '{"trxId":"064024","response_code":"0000","response_message":"SUKSES","detail":{"jmlTagihan":"1","kodeThree":"012001","nilaiPulsa":"000000005000","noHp":"0895385381299","transactionId":"0612143023138365102 ","voucherSerialNumber":"20170612143620980249"},"reff":"20170612143620980249","loadTime":"0.0107","tipe_request":"purchase","prv":"hpay","userID":"1002003","idpel":"0895385381299","product":"PULSA","produk":"PULSA","product_detail":"THREE5000","produk_tipe":"THREE5000","traceId":16,"tagihan":5050,"total_tagihan":5050,"amount":5050,"saldo":94950,"waktu":"2017-07-17 18:43:32"}';
const responseData = partner.parseResponseBody(responseBody);
describe('#parseResponseBody', function() {
it('should return correct response code', function() {
responseData.response_code.should.equal('0000');
})
it('should return correct voucher serial number', function() {
responseData.detail.voucherSerialNumber.should.equal('20170612143620980249');
})
})
describe('#responseDataProcessor', function() {
const processed = partner.responseDataProcessor(responseData);
it('should return correct rc', function() {
processed.rc.should.equal('00');
})
it('should return correct sn', function() {
processed.sn.should.equal('20170612143620980249');
})
it('should return correct amount', function() {
processed.amount.should.equal(5050);
})
it('should return correct balance', function() {
processed.balance.should.equal(94950);
})
})
describe('#splitRemoteProduct', function() {
it ('should return correctly using space as separator', function() {
const remoteProduct = 'PULSA THREE5000 0 0';
partner.splitRemoteProduct(remoteProduct)[0].should.equal('PULSA');
partner.splitRemoteProduct(remoteProduct)[1].should.equal('THREE5000');
partner.splitRemoteProduct(remoteProduct)[2].should.equal('0');
partner.splitRemoteProduct(remoteProduct)[3].should.equal('0');
})
it ('should return correctly using comma as separator', function() {
const remoteProduct = 'PULSA,THREE5000,0,0';
partner.splitRemoteProduct(remoteProduct)[0].should.equal('PULSA');
partner.splitRemoteProduct(remoteProduct)[1].should.equal('THREE5000');
partner.splitRemoteProduct(remoteProduct)[2].should.equal('0');
partner.splitRemoteProduct(remoteProduct)[3].should.equal('0');
})
it ('should return correctly using slash as separator', function() {
const remoteProduct = 'PULSA/THREE5000/0/0';
partner.splitRemoteProduct(remoteProduct)[0].should.equal('PULSA');
partner.splitRemoteProduct(remoteProduct)[1].should.equal('THREE5000');
partner.splitRemoteProduct(remoteProduct)[2].should.equal('0');
partner.splitRemoteProduct(remoteProduct)[3].should.equal('0');
})
})
})