compose-payload.js
2.29 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
/* eslint-disable no-console */
/* global describe it */
const should = require('should');
const xmlParser = require('fast-xml-parser');
const composePayload = require('../../lib/generic-xmlrpc/compose-payload');
describe('#generic-xmlrpc', () => {
describe('#compose-payload', () => {
it('should compose payload correctly (params is an array)', () => {
const resultStr = composePayload('topUpRequest', [
{
name: 'MSISDN',
value: '62818181818',
},
{
name: 'REQUESTID',
value: '1234',
},
]);
// console.log(result);
should.exists(resultStr, '5033DD9C');
const resultObj = xmlParser.parse(resultStr);
// console.log(JSON.stringify(resultObj, null, 2));
resultObj.methodCall.params.param.value.struct.member.find((item) => item.name === 'MSISDN').value.string.should.equal(62818181818, '06C60D8C');
});
it('should compose payload correctly (params is an object)', () => {
const resultStr = composePayload('topUpRequest', {
MSISDN: { value: '62818181818' },
REQUESTID: { value: '1234' },
});
// console.log(result);
should.exists(resultStr, '13E0279E');
const resultObj = xmlParser.parse(resultStr);
// console.log(JSON.stringify(resultObj, null, 2));
resultObj.methodCall.params.param.value.struct.member.find((item) => item.name === 'MSISDN').value.string.should.equal(62818181818, '3399A280');
});
it('should compose payload correctly (params is an object, and value is not an object)', () => {
const resultStr = composePayload('topUpRequest', {
MSISDN: '62818181818',
REQUESTID: '1234',
});
// console.log(resultStr);
should.exists(resultStr, '99413C25');
const resultObj = xmlParser.parse(resultStr);
// console.log(JSON.stringify(resultObj, null, 2));
resultObj.methodCall.params.param.value.struct.member.find((item) => item.name === 'MSISDN').value.string.should.equal(62818181818, 'C49C657D');
});
});
});