@mojaloop/sdk-scheme-adapter 18.0.0 → 18.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +18 -0
- package/.eslintignore +2 -0
- package/.ncurc.yaml +7 -0
- package/CHANGELOG.md +20 -0
- package/CODEOWNERS +31 -1
- package/README.md +1 -0
- package/audit-resolve.json +35 -0
- package/package.json +13 -13
- package/test/__mocks__/@mojaloop/sdk-standard-components.js +0 -151
- package/test/__mocks__/javascript-state-machine.js +0 -21
- package/test/__mocks__/redis.js +0 -78
- package/test/__mocks__/uuidv4.js +0 -16
- package/test/config/integration.env +0 -146
- package/test/integration/lib/Outbound/data/quotesPostRequest.json +0 -52
- package/test/integration/lib/Outbound/data/transfersPostRequest.json +0 -24
- package/test/integration/lib/Outbound/parties.test.js +0 -31
- package/test/integration/lib/Outbound/quotes.test.js +0 -62
- package/test/integration/lib/Outbound/simpleTransfers.test.js +0 -70
- package/test/integration/lib/cache.test.js +0 -79
- package/test/integration/testEnv.js +0 -4
- package/test/unit/ControlClient.test.js +0 -69
- package/test/unit/ControlServer/events.js +0 -41
- package/test/unit/ControlServer/index.js +0 -227
- package/test/unit/ControlServer.test.js +0 -66
- package/test/unit/InboundServer.test.js +0 -443
- package/test/unit/TestServer.test.js +0 -392
- package/test/unit/api/accounts/accounts.test.js +0 -128
- package/test/unit/api/accounts/data/postAccountsBody.json +0 -7
- package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +0 -33
- package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +0 -19
- package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +0 -31
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +0 -34
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +0 -39
- package/test/unit/api/accounts/utils.js +0 -79
- package/test/unit/api/proxy/data/proxyConfig.yaml +0 -82
- package/test/unit/api/proxy/data/requestBody.json +0 -22
- package/test/unit/api/proxy/data/requestHeaders.json +0 -5
- package/test/unit/api/proxy/data/requestQuery.json +0 -6
- package/test/unit/api/proxy/data/responseBody.json +0 -21
- package/test/unit/api/proxy/data/responseHeaders.json +0 -5
- package/test/unit/api/proxy/proxy.test.js +0 -220
- package/test/unit/api/proxy/utils.js +0 -79
- package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +0 -24
- package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +0 -18
- package/test/unit/api/transfers/data/postQuotesBody.json +0 -52
- package/test/unit/api/transfers/data/postTransfersBadBody.json +0 -17
- package/test/unit/api/transfers/data/postTransfersBody.json +0 -24
- package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +0 -62
- package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +0 -48
- package/test/unit/api/transfers/data/postTransfersSimpleBody.json +0 -26
- package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +0 -128
- package/test/unit/api/transfers/data/putPartiesBody.json +0 -20
- package/test/unit/api/transfers/data/putQuotesBody.json +0 -37
- package/test/unit/api/transfers/data/putTransfersBody.json +0 -17
- package/test/unit/api/transfers/transfers.test.js +0 -191
- package/test/unit/api/transfers/utils.js +0 -264
- package/test/unit/api/utils.js +0 -86
- package/test/unit/config.test.js +0 -119
- package/test/unit/data/commonHttpHeaders.json +0 -7
- package/test/unit/data/defaultConfig.json +0 -70
- package/test/unit/data/postQuotesBody.json +0 -52
- package/test/unit/data/putParticipantsBody.json +0 -12
- package/test/unit/data/putPartiesBody.json +0 -20
- package/test/unit/data/testFile.json +0 -29
- package/test/unit/data/testFile.yaml +0 -14
- package/test/unit/inboundApi/data/mockArguments.json +0 -117
- package/test/unit/inboundApi/data/mockTransactionRequest.json +0 -42
- package/test/unit/inboundApi/handlers.test.js +0 -786
- package/test/unit/index.test.js +0 -88
- package/test/unit/lib/cache.test.js +0 -145
- package/test/unit/lib/model/AccountsModel.test.js +0 -124
- package/test/unit/lib/model/InboundTransfersModel.test.js +0 -889
- package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +0 -253
- package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +0 -247
- package/test/unit/lib/model/OutboundRequestToPayModel.test.js +0 -166
- package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +0 -245
- package/test/unit/lib/model/OutboundTransfersModel.test.js +0 -1579
- package/test/unit/lib/model/PartiesModel.test.js +0 -478
- package/test/unit/lib/model/QuotesModel.test.js +0 -477
- package/test/unit/lib/model/TransfersModel.test.js +0 -481
- package/test/unit/lib/model/common/PersistentStateMachine.test.js +0 -178
- package/test/unit/lib/model/data/authorizationsResponse.json +0 -13
- package/test/unit/lib/model/data/bulkQuoteRequest.json +0 -27
- package/test/unit/lib/model/data/bulkQuoteResponse.json +0 -35
- package/test/unit/lib/model/data/bulkTransferFulfil.json +0 -13
- package/test/unit/lib/model/data/bulkTransferRequest.json +0 -29
- package/test/unit/lib/model/data/defaultConfig.json +0 -59
- package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +0 -42
- package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +0 -22
- package/test/unit/lib/model/data/getTransfersBackendResponse.json +0 -34
- package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +0 -17
- package/test/unit/lib/model/data/mockArguments.json +0 -188
- package/test/unit/lib/model/data/mockTxnRequestsArguments.json +0 -63
- package/test/unit/lib/model/data/notificationAbortedToPayee.json +0 -10
- package/test/unit/lib/model/data/notificationReservedToPayee.json +0 -10
- package/test/unit/lib/model/data/notificationToPayee.json +0 -10
- package/test/unit/lib/model/data/payeeParty.json +0 -18
- package/test/unit/lib/model/data/putQuotesResponse.json +0 -33
- package/test/unit/lib/model/data/putTransfersResponse.json +0 -5
- package/test/unit/lib/model/data/quoteResponse.json +0 -42
- package/test/unit/lib/model/data/requestToPayRequest.json +0 -20
- package/test/unit/lib/model/data/requestToPayTransferRequest.json +0 -27
- package/test/unit/lib/model/data/transactionRequestResponse.json +0 -18
- package/test/unit/lib/model/data/transferFulfil.json +0 -10
- package/test/unit/lib/model/data/transferRequest.json +0 -26
- package/test/unit/lib/model/mockedLibRequests.js +0 -74
- package/test/unit/mockLogger.js +0 -39
- package/test/unit/outboundApi/data/bulkQuoteRequest.json +0 -28
- package/test/unit/outboundApi/data/bulkTransferRequest.json +0 -28
- package/test/unit/outboundApi/data/mockBulkQuoteError.json +0 -45
- package/test/unit/outboundApi/data/mockBulkTransferError.json +0 -48
- package/test/unit/outboundApi/data/mockError.json +0 -41
- package/test/unit/outboundApi/data/mockGetPartiesError.json +0 -4
- package/test/unit/outboundApi/data/mockRequestToPayError.json +0 -32
- package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +0 -39
- package/test/unit/outboundApi/data/requestToPay.json +0 -21
- package/test/unit/outboundApi/data/requestToPayTransferRequest.json +0 -20
- package/test/unit/outboundApi/data/transferRequest.json +0 -21
- package/test/unit/outboundApi/handlers.test.js +0 -887
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const nock = require('nock');
|
|
2
|
-
const OpenAPIResponseValidator = require('openapi-response-validator').default;
|
|
3
|
-
|
|
4
|
-
const defaultConfig = require('../../data/defaultConfig');
|
|
5
|
-
const postAccountsBody = require('./data/postAccountsBody');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param reqInbound
|
|
10
|
-
* @param reqOutbound
|
|
11
|
-
* @param apiSpecsOutbound
|
|
12
|
-
* @returns Function(putBodyFn:function, responseCode:number, responseBody:object) => Promise
|
|
13
|
-
*/
|
|
14
|
-
function createPostAccountsTester({ reqInbound, reqOutbound, apiSpecsOutbound }) {
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @param putBodyFn {function}
|
|
18
|
-
* @param responseCode {number}
|
|
19
|
-
* @param responseBody {object}
|
|
20
|
-
*
|
|
21
|
-
* @return {Promise<any>}
|
|
22
|
-
*/
|
|
23
|
-
return async (putBodyFn, responseCode, responseBody) => {
|
|
24
|
-
let pendingRequest = Promise.resolve();
|
|
25
|
-
const endpoint = new URL(`http://${defaultConfig.alsEndpoint}`).host;
|
|
26
|
-
const switchEndpoint = `http://${endpoint}`;
|
|
27
|
-
|
|
28
|
-
const sendPutParticipants = async (requestBody) => {
|
|
29
|
-
const body = JSON.parse(requestBody);
|
|
30
|
-
const putBody = await Promise.resolve(putBodyFn(body));
|
|
31
|
-
let putUrl = `/participants/${body.requestId}`;
|
|
32
|
-
if (putBody.errorInformation) {
|
|
33
|
-
putUrl += '/error';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return reqInbound.put(putUrl)
|
|
37
|
-
.send(putBody)
|
|
38
|
-
.set('Date', new Date().toISOString())
|
|
39
|
-
.set('content-type', 'application/vnd.interoperability.participants+json;version=1.1')
|
|
40
|
-
.set('fspiop-source', 'mojaloop-sdk')
|
|
41
|
-
.expect(200);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
await nock(switchEndpoint)
|
|
45
|
-
.post('/participants')
|
|
46
|
-
.reply(202, (_, requestBody) => {
|
|
47
|
-
pendingRequest = sendPutParticipants(requestBody).then();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const res = await reqOutbound.post('/accounts').send(postAccountsBody);
|
|
51
|
-
const {body} = res;
|
|
52
|
-
expect(res.statusCode).toEqual(responseCode);
|
|
53
|
-
|
|
54
|
-
// remove elements of the response we do not want/need to compare for correctness.
|
|
55
|
-
// timestamps on requests/responses for example will be set by the HTTP framework
|
|
56
|
-
// and we dont want to compare against static values.
|
|
57
|
-
if (body.executionState) {
|
|
58
|
-
if(body.executionState.postAccountsResponse) {
|
|
59
|
-
delete body.executionState.postAccountsResponse.headers;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if(body.postAccountsResponse) {
|
|
64
|
-
delete body.postAccountsResponse.headers;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
expect(body).toEqual(responseBody);
|
|
68
|
-
const responseValidator = new OpenAPIResponseValidator(apiSpecsOutbound.paths['/accounts'].post);
|
|
69
|
-
const err = responseValidator.validateResponse(responseCode, body);
|
|
70
|
-
if (err) {
|
|
71
|
-
throw err;
|
|
72
|
-
}
|
|
73
|
-
await pendingRequest;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = {
|
|
78
|
-
createPostAccountsTester,
|
|
79
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
version: 1.0
|
|
2
|
-
routes:
|
|
3
|
-
- description: 'Routing by URL path as string'
|
|
4
|
-
match:
|
|
5
|
-
- path: /sdk-path-test-1
|
|
6
|
-
destination:
|
|
7
|
-
path: /switch-path-test-1
|
|
8
|
-
|
|
9
|
-
- description: 'Routing by URL path as regexp'
|
|
10
|
-
match:
|
|
11
|
-
- path: ~ ^\/sdk-.*2$
|
|
12
|
-
destination:
|
|
13
|
-
path: /switch-path-test-2
|
|
14
|
-
|
|
15
|
-
- description: 'Routing by Query params with regexp'
|
|
16
|
-
match:
|
|
17
|
-
- path: /sdk-path-test-3
|
|
18
|
-
query:
|
|
19
|
-
- key: queryString1One
|
|
20
|
-
value: Value1
|
|
21
|
-
- key: ~ query.*2Two
|
|
22
|
-
value: ~ val.*2
|
|
23
|
-
destination:
|
|
24
|
-
path: /switch-path-test-3
|
|
25
|
-
|
|
26
|
-
- description: 'Routing by Query params'
|
|
27
|
-
match:
|
|
28
|
-
- query:
|
|
29
|
-
- key: testParam3
|
|
30
|
-
value: testValue3
|
|
31
|
-
destination:
|
|
32
|
-
path: /switch-path-test-3-1
|
|
33
|
-
|
|
34
|
-
- description: 'Routing by Header params with regexp'
|
|
35
|
-
match:
|
|
36
|
-
- headers:
|
|
37
|
-
- name: customHeader2
|
|
38
|
-
value: ~ .*stomval.*
|
|
39
|
-
- name: ~ cus.*header3
|
|
40
|
-
value: ~ .*
|
|
41
|
-
destination:
|
|
42
|
-
path: /switch-path-test-4
|
|
43
|
-
|
|
44
|
-
- description: 'Routing by Header params should work'
|
|
45
|
-
match:
|
|
46
|
-
- path: /sdk-path-test-4
|
|
47
|
-
headers:
|
|
48
|
-
- name: customReq-Header2
|
|
49
|
-
value: ~ .*eq-va.*
|
|
50
|
-
- name: ~ .*header3
|
|
51
|
-
value: ~ .*
|
|
52
|
-
destination:
|
|
53
|
-
path: /switch-path-test-4
|
|
54
|
-
|
|
55
|
-
- description: 'Routing by Header values'
|
|
56
|
-
match:
|
|
57
|
-
- headers:
|
|
58
|
-
- name: ~ *
|
|
59
|
-
value: ~ .*st.*val.*
|
|
60
|
-
- name: ~ *
|
|
61
|
-
value: ~ .*st.*value5
|
|
62
|
-
destination:
|
|
63
|
-
path: '/switch-path-test-5'
|
|
64
|
-
|
|
65
|
-
- description: 'Routing by multiple match rules'
|
|
66
|
-
match:
|
|
67
|
-
- path: ~ /sdk-.*-8
|
|
68
|
-
headers:
|
|
69
|
-
- name: requiredName
|
|
70
|
-
value: yes
|
|
71
|
-
- headers:
|
|
72
|
-
- name: ~ .*hkey81
|
|
73
|
-
value: ~ *
|
|
74
|
-
- headers:
|
|
75
|
-
- name: ~ .*hkey82
|
|
76
|
-
value: ~ *
|
|
77
|
-
- query:
|
|
78
|
-
- key: ~ .*qkey81
|
|
79
|
-
value: ~ *
|
|
80
|
-
|
|
81
|
-
destination:
|
|
82
|
-
path: '/switch-path-test-8'
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"pipe": {
|
|
3
|
-
"gate": {
|
|
4
|
-
"wonder": "pie",
|
|
5
|
-
"motion": -1954091019.282176,
|
|
6
|
-
"sat": -1408621945.196569,
|
|
7
|
-
"paint": false,
|
|
8
|
-
"mass": "cool",
|
|
9
|
-
"ship": 301008758.9371433
|
|
10
|
-
},
|
|
11
|
-
"rear": false,
|
|
12
|
-
"kept": true,
|
|
13
|
-
"shape": "bottle",
|
|
14
|
-
"shine": 190280734.75563002,
|
|
15
|
-
"shown": -822072188
|
|
16
|
-
},
|
|
17
|
-
"trip": -995941977,
|
|
18
|
-
"anybody": -1773044919,
|
|
19
|
-
"shoe": -1775269105,
|
|
20
|
-
"market": "room",
|
|
21
|
-
"your": "pilot"
|
|
22
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"sample": "pick",
|
|
3
|
-
"drop": [
|
|
4
|
-
{
|
|
5
|
-
"stretch": "raise",
|
|
6
|
-
"cloud": "area",
|
|
7
|
-
"mysterious": "slide",
|
|
8
|
-
"system": "headed",
|
|
9
|
-
"human": -935415263.1668315
|
|
10
|
-
},
|
|
11
|
-
-1910628437.0222688,
|
|
12
|
-
1097437779,
|
|
13
|
-
728983216,
|
|
14
|
-
true,
|
|
15
|
-
"percent"
|
|
16
|
-
],
|
|
17
|
-
"low": "material",
|
|
18
|
-
"discussion": "studying",
|
|
19
|
-
"leather": -1095320503,
|
|
20
|
-
"spent": true
|
|
21
|
-
}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
/**************************************************************************
|
|
2
|
-
* (C) Copyright ModusBox Inc. 2019 - All rights reserved. *
|
|
3
|
-
* *
|
|
4
|
-
* This file is made available under the terms of the license agreement *
|
|
5
|
-
* specified in the corresponding source code repository. *
|
|
6
|
-
* *
|
|
7
|
-
* ORIGINAL AUTHOR: *
|
|
8
|
-
* Yevhen Kyriukha - yevhen.kyriukha@modusbox.com *
|
|
9
|
-
**************************************************************************/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
jest.unmock('@mojaloop/sdk-standard-components');
|
|
14
|
-
jest.mock('redis');
|
|
15
|
-
|
|
16
|
-
const yaml = require('js-yaml');
|
|
17
|
-
const path = require('path');
|
|
18
|
-
const fs = require('fs');
|
|
19
|
-
|
|
20
|
-
const { createTestServers, destroyTestServers } = require('../utils');
|
|
21
|
-
const { createProxyTester } = require('./utils');
|
|
22
|
-
|
|
23
|
-
const defaultConfig = require('../../data/defaultConfig');
|
|
24
|
-
|
|
25
|
-
defaultConfig.peerEndpoint = `${defaultConfig.peerEndpoint}/abc/def`;
|
|
26
|
-
|
|
27
|
-
describe('Proxy', () => {
|
|
28
|
-
let serversInfo;
|
|
29
|
-
let testProxy;
|
|
30
|
-
|
|
31
|
-
const configPath = path.join(__dirname, 'data', 'proxyConfig.yaml');
|
|
32
|
-
const proxyConfig = yaml.load(fs.readFileSync(configPath));
|
|
33
|
-
|
|
34
|
-
beforeEach(async () => {
|
|
35
|
-
serversInfo = await createTestServers({
|
|
36
|
-
...defaultConfig,
|
|
37
|
-
proxyConfig,
|
|
38
|
-
});
|
|
39
|
-
testProxy = createProxyTester({
|
|
40
|
-
reqOutbound: serversInfo.reqOutbound,
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
afterEach(async () => {
|
|
45
|
-
await destroyTestServers(serversInfo);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('should return success POST response', async () =>
|
|
49
|
-
testProxy({
|
|
50
|
-
sdkUrlPath: '/sdk-path-test-1',
|
|
51
|
-
method: 'POST',
|
|
52
|
-
query: {},
|
|
53
|
-
headers: {},
|
|
54
|
-
switchUrlPath: '/switch-path-test-1',
|
|
55
|
-
shouldForward: true,
|
|
56
|
-
}));
|
|
57
|
-
|
|
58
|
-
test('should return success PUT response', async () =>
|
|
59
|
-
testProxy({
|
|
60
|
-
sdkUrlPath: '/sdk-path-test-1',
|
|
61
|
-
method: 'PUT',
|
|
62
|
-
query: {},
|
|
63
|
-
headers: {},
|
|
64
|
-
switchUrlPath: '/switch-path-test-1',
|
|
65
|
-
shouldForward: true,
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
test('should return success GET response', async () =>
|
|
69
|
-
testProxy({
|
|
70
|
-
sdkUrlPath: '/sdk-path-test-1',
|
|
71
|
-
method: 'GET',
|
|
72
|
-
query: {},
|
|
73
|
-
headers: {},
|
|
74
|
-
switchUrlPath: '/switch-path-test-1',
|
|
75
|
-
shouldForward: true,
|
|
76
|
-
}));
|
|
77
|
-
|
|
78
|
-
test('should return error response', async () =>
|
|
79
|
-
testProxy({
|
|
80
|
-
sdkUrlPath: '/unknown-sdk-path-test-1',
|
|
81
|
-
method: 'POST',
|
|
82
|
-
query: {},
|
|
83
|
-
headers: {},
|
|
84
|
-
switchUrlPath: '/switch-path-test-1',
|
|
85
|
-
shouldForward: false,
|
|
86
|
-
}));
|
|
87
|
-
|
|
88
|
-
test('should forward by path regexp', async () =>
|
|
89
|
-
testProxy({
|
|
90
|
-
sdkUrlPath: '/sdk-path-test-2',
|
|
91
|
-
method: 'POST',
|
|
92
|
-
query: {},
|
|
93
|
-
headers: {},
|
|
94
|
-
switchUrlPath: '/switch-path-test-2',
|
|
95
|
-
shouldForward: true,
|
|
96
|
-
}));
|
|
97
|
-
|
|
98
|
-
test('should forward by query params', async () =>
|
|
99
|
-
testProxy({
|
|
100
|
-
sdkUrlPath: '/sdk-path-test',
|
|
101
|
-
method: 'POST',
|
|
102
|
-
query: { testParam3: 'testValue3' },
|
|
103
|
-
headers: {},
|
|
104
|
-
switchUrlPath: '/switch-path-test-3-1',
|
|
105
|
-
shouldForward: true,
|
|
106
|
-
}));
|
|
107
|
-
|
|
108
|
-
test('should not forward by query params', async () =>
|
|
109
|
-
testProxy({
|
|
110
|
-
sdkUrlPath: '/sdk-path-test',
|
|
111
|
-
method: 'POST',
|
|
112
|
-
query: { testParam3: 'testValue4' },
|
|
113
|
-
headers: {},
|
|
114
|
-
switchUrlPath: '/switch-path-test-3-1',
|
|
115
|
-
shouldForward: false,
|
|
116
|
-
}));
|
|
117
|
-
|
|
118
|
-
test('should forward by header params', async () =>
|
|
119
|
-
testProxy({
|
|
120
|
-
sdkUrlPath: '/sdk-path-test',
|
|
121
|
-
method: 'POST',
|
|
122
|
-
query: { },
|
|
123
|
-
headers: {
|
|
124
|
-
customHeader2: 'customValue2',
|
|
125
|
-
customHeader3: 'other value'
|
|
126
|
-
},
|
|
127
|
-
switchUrlPath: '/switch-path-test-4',
|
|
128
|
-
shouldForward: true,
|
|
129
|
-
}));
|
|
130
|
-
|
|
131
|
-
test('should not forward by header params', async () =>
|
|
132
|
-
testProxy({
|
|
133
|
-
sdkUrlPath: '/sdk-path-test',
|
|
134
|
-
method: 'POST',
|
|
135
|
-
query: { },
|
|
136
|
-
headers: {
|
|
137
|
-
customHeader2: 'customValue2',
|
|
138
|
-
},
|
|
139
|
-
switchUrlPath: '/switch-path-test-4',
|
|
140
|
-
shouldForward: false,
|
|
141
|
-
}));
|
|
142
|
-
|
|
143
|
-
test('should forward by header values', async () =>
|
|
144
|
-
testProxy({
|
|
145
|
-
sdkUrlPath: '/sdk-path-test',
|
|
146
|
-
method: 'POST',
|
|
147
|
-
query: { },
|
|
148
|
-
headers: {
|
|
149
|
-
someHeader1: 'someCustomValue',
|
|
150
|
-
someHeader2: 'customValue5',
|
|
151
|
-
},
|
|
152
|
-
switchUrlPath: '/switch-path-test-5',
|
|
153
|
-
shouldForward: true,
|
|
154
|
-
}));
|
|
155
|
-
|
|
156
|
-
test('should forward using multi-match rule (path and headers)', async () =>
|
|
157
|
-
testProxy({
|
|
158
|
-
sdkUrlPath: '/sdk-path-test-8',
|
|
159
|
-
method: 'POST',
|
|
160
|
-
query: { },
|
|
161
|
-
headers: {
|
|
162
|
-
requiredName: 'yes',
|
|
163
|
-
},
|
|
164
|
-
switchUrlPath: '/switch-path-test-8',
|
|
165
|
-
shouldForward: true,
|
|
166
|
-
}));
|
|
167
|
-
|
|
168
|
-
test('should not forward using multi-match rule (wrong headers)', async () =>
|
|
169
|
-
testProxy({
|
|
170
|
-
sdkUrlPath: '/sdk-path-test-8',
|
|
171
|
-
method: 'POST',
|
|
172
|
-
query: { },
|
|
173
|
-
headers: {
|
|
174
|
-
requiredName: 'no',
|
|
175
|
-
},
|
|
176
|
-
switchUrlPath: '/switch-path-test-8',
|
|
177
|
-
shouldForward: false,
|
|
178
|
-
}));
|
|
179
|
-
|
|
180
|
-
test('should forward using multi-match rule (query)', async () =>
|
|
181
|
-
testProxy({
|
|
182
|
-
sdkUrlPath: '/sdk-path-test-8',
|
|
183
|
-
method: 'POST',
|
|
184
|
-
query: { customQkey81: 'some qval' },
|
|
185
|
-
headers: {
|
|
186
|
-
requiredName: 'no',
|
|
187
|
-
},
|
|
188
|
-
switchUrlPath: '/switch-path-test-8',
|
|
189
|
-
shouldForward: true,
|
|
190
|
-
}));
|
|
191
|
-
|
|
192
|
-
test('should forward using multi-match rule (headers)', async () =>
|
|
193
|
-
testProxy({
|
|
194
|
-
sdkUrlPath: '/sdk-path-test-8',
|
|
195
|
-
method: 'POST',
|
|
196
|
-
query: { customQkey81Unknown: 'some qval' },
|
|
197
|
-
headers: {
|
|
198
|
-
requiredName: 'no',
|
|
199
|
-
SomeHKEY82: 'some val',
|
|
200
|
-
'content-type': 'application/json',
|
|
201
|
-
},
|
|
202
|
-
switchUrlPath: '/switch-path-test-8',
|
|
203
|
-
shouldForward: true,
|
|
204
|
-
}));
|
|
205
|
-
|
|
206
|
-
test('should handle binary response', async () =>
|
|
207
|
-
testProxy({
|
|
208
|
-
sdkUrlPath: '/sdk-path-test-8',
|
|
209
|
-
method: 'POST',
|
|
210
|
-
query: { customQkey81Unknown: 'some qval' },
|
|
211
|
-
headers: {
|
|
212
|
-
requiredName: 'no',
|
|
213
|
-
SomeHKEY82: 'some val',
|
|
214
|
-
'content-type': 'application/json',
|
|
215
|
-
},
|
|
216
|
-
switchUrlPath: '/switch-path-test-8',
|
|
217
|
-
shouldForward: true,
|
|
218
|
-
binary: true,
|
|
219
|
-
}));
|
|
220
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const nock = require('nock');
|
|
2
|
-
const crypto = require('crypto');
|
|
3
|
-
|
|
4
|
-
const defaultConfig = require('../../data/defaultConfig');
|
|
5
|
-
const requestBody = require('./data/requestBody');
|
|
6
|
-
const requestHeaders = require('./data/requestHeaders');
|
|
7
|
-
const requestQuery = require('./data/requestQuery');
|
|
8
|
-
const responseBodyJSON = require('./data/responseBody');
|
|
9
|
-
const responseHeaders = require('./data/responseHeaders');
|
|
10
|
-
|
|
11
|
-
const responseBodyBinary = crypto.randomBytes(10000);
|
|
12
|
-
|
|
13
|
-
const convertToLowerCaseKeys = (obj) => Object.entries(obj).reduce(
|
|
14
|
-
(acc, [k, v]) => ({...acc, [k.toLowerCase()]: v}),
|
|
15
|
-
{},
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param reqOutbound
|
|
21
|
-
* @returns Function => Promise
|
|
22
|
-
*/
|
|
23
|
-
function createProxyTester({ reqOutbound }) {
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param sdkUrlPath {string}
|
|
27
|
-
* @param switchUrlPath {string}
|
|
28
|
-
* @param method {string} - one of POST, GET, PUT
|
|
29
|
-
* @param expectedStatusCode {number}
|
|
30
|
-
*
|
|
31
|
-
* @return {Promise<any>}
|
|
32
|
-
*/
|
|
33
|
-
return async ({sdkUrlPath, switchUrlPath, method, shouldForward, query, headers, binary}) => {
|
|
34
|
-
const endpoint = new URL(`http://${defaultConfig.peerEndpoint}`).host;
|
|
35
|
-
const switchEndpoint = `http://${endpoint}`;
|
|
36
|
-
const responseBody = binary ? responseBodyBinary : responseBodyJSON;
|
|
37
|
-
nock(switchEndpoint, {
|
|
38
|
-
reqheaders: {
|
|
39
|
-
...requestHeaders,
|
|
40
|
-
...headers,
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
.intercept(switchUrlPath, method.toUpperCase())
|
|
44
|
-
.query({
|
|
45
|
-
...requestQuery,
|
|
46
|
-
...query,
|
|
47
|
-
})
|
|
48
|
-
.reply(200, responseBody, responseHeaders);
|
|
49
|
-
|
|
50
|
-
const res = await reqOutbound[method.toLowerCase()](sdkUrlPath)
|
|
51
|
-
.query({
|
|
52
|
-
...requestQuery,
|
|
53
|
-
...query,
|
|
54
|
-
})
|
|
55
|
-
.send(requestBody)
|
|
56
|
-
.set({
|
|
57
|
-
...requestHeaders,
|
|
58
|
-
...headers,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (shouldForward) {
|
|
62
|
-
const expectedHeaders = convertToLowerCaseKeys(responseHeaders);
|
|
63
|
-
const receivedHeaders = convertToLowerCaseKeys(res.headers);
|
|
64
|
-
expect(res.body).toEqual(responseBody);
|
|
65
|
-
expect(receivedHeaders).toMatchObject(expectedHeaders);
|
|
66
|
-
expect(res.statusCode).toBe(200);
|
|
67
|
-
} else {
|
|
68
|
-
expect(res.body).toEqual({
|
|
69
|
-
'message': `Couldn't match path ${sdkUrlPath}`,
|
|
70
|
-
'statusCode': 400,
|
|
71
|
-
});
|
|
72
|
-
expect(res.statusCode).toBe(400);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = {
|
|
78
|
-
createProxyTester,
|
|
79
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"currentState": "COMPLETED",
|
|
3
|
-
"direction": "OUTBOUND",
|
|
4
|
-
"fulfil": {
|
|
5
|
-
"body": {
|
|
6
|
-
"completedTimestamp": "2017-11-15T14:16:09.663+01:00",
|
|
7
|
-
"extensionList": {
|
|
8
|
-
"extension": [
|
|
9
|
-
{
|
|
10
|
-
"key": "treskey1",
|
|
11
|
-
"value": "tresvalue1"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"key": "treskey2",
|
|
15
|
-
"value": "tresvalue2"
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
"fulfilment": "87mm1reS3SAi8oIWXgBkLmgWc1MkZ_yLbFDX5XAdo5o",
|
|
20
|
-
"transferState": "COMMITTED"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"transferId": "00000000-0000-1000-8000-000000000001"
|
|
24
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"message": "Got an error response retrieving transfer: {\n errorInformation: { errorCode: '3208', errorDescription: 'Transaction not found' }\n}",
|
|
3
|
-
"statusCode": "3208",
|
|
4
|
-
"transferState": {
|
|
5
|
-
"currentState": "ERROR_OCCURRED",
|
|
6
|
-
"direction": "OUTBOUND",
|
|
7
|
-
"lastError": {
|
|
8
|
-
"httpStatusCode": 500,
|
|
9
|
-
"mojaloopError": {
|
|
10
|
-
"errorInformation": {
|
|
11
|
-
"errorCode": "3208",
|
|
12
|
-
"errorDescription": "Transaction not found"
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"transferId": "00000000-0000-1000-8000-000000000001"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"amount": {
|
|
3
|
-
"amount": "100",
|
|
4
|
-
"currency": "USD"
|
|
5
|
-
},
|
|
6
|
-
"amountType": "SEND",
|
|
7
|
-
"expiration": "2020-01-20T11:31:49.325Z",
|
|
8
|
-
"extensionList": {
|
|
9
|
-
"extension": [
|
|
10
|
-
{
|
|
11
|
-
"key": "qreqkey1",
|
|
12
|
-
"value": "qreqvalue1"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"key": "qreqkey2",
|
|
16
|
-
"value": "qreqvalue2"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
|
-
"note": "test payment",
|
|
21
|
-
"payee": {
|
|
22
|
-
"partyIdInfo": {
|
|
23
|
-
"fspId": "sim",
|
|
24
|
-
"partyIdType": "PERSONAL_ID",
|
|
25
|
-
"partyIdentifier": "987654321",
|
|
26
|
-
"partySubIdOrType": "PASSPORT"
|
|
27
|
-
},
|
|
28
|
-
"personalInfo": {
|
|
29
|
-
"complexName": {
|
|
30
|
-
"firstName": "John",
|
|
31
|
-
"lastName": "Doe",
|
|
32
|
-
"middleName": "Someone"
|
|
33
|
-
},
|
|
34
|
-
"dateOfBirth": "1980-01-01"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"payer": {
|
|
38
|
-
"name": "John Doe",
|
|
39
|
-
"partyIdInfo": {
|
|
40
|
-
"fspId": "mojaloop-sdk",
|
|
41
|
-
"partyIdType": "MSISDN",
|
|
42
|
-
"partyIdentifier": "123456789"
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
"quoteId": "00000000-0000-1000-8000-000000000002",
|
|
46
|
-
"transactionId": "00000000-0000-1000-8000-000000000001",
|
|
47
|
-
"transactionType": {
|
|
48
|
-
"initiator": "PAYER",
|
|
49
|
-
"initiatorType": "CONSUMER",
|
|
50
|
-
"scenario": "TRANSFER"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"from": {
|
|
3
|
-
"displayName": "James Bush",
|
|
4
|
-
"idType": "MSISDN",
|
|
5
|
-
"idValue": "987654321"
|
|
6
|
-
},
|
|
7
|
-
"to": {
|
|
8
|
-
"idType": "",
|
|
9
|
-
"idValue": "123456789"
|
|
10
|
-
},
|
|
11
|
-
"amountType": "SEND",
|
|
12
|
-
"currency": "USD",
|
|
13
|
-
"amount": "100",
|
|
14
|
-
"transactionType": "TRANSFER",
|
|
15
|
-
"note": "test payment",
|
|
16
|
-
"homeTransactionId": "123ABC"
|
|
17
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"amount": {
|
|
3
|
-
"amount": "500",
|
|
4
|
-
"currency": "USD"
|
|
5
|
-
},
|
|
6
|
-
"condition": "fH9pAYDQbmoZLPbvv3CSW2RfjU4jvM4ApG_fqGnR7Xs",
|
|
7
|
-
"expiration": "2020-01-20T11:32:52.167Z",
|
|
8
|
-
"extensionList": {
|
|
9
|
-
"extension": [
|
|
10
|
-
{
|
|
11
|
-
"key": "treqkey1",
|
|
12
|
-
"value": "treqvalue1"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"key": "treqkey2",
|
|
16
|
-
"value": "treqvalue2"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
|
-
"ilpPacket": "AQAAAAAAACasIWcuc2UubW9iaWxlbW9uZXkubXNpc2RuLjEyMzQ1Njc4OYIEIXsNCiAgICAidHJhbnNhY3Rpb25JZCI6ICI4NWZlYWMyZi0zOWIyLTQ5MWItODE3ZS00YTAzMjAzZDRmMTQiLA0KICAgICJxdW90ZUlkIjogIjdjMjNlODBjLWQwNzgtNDA3Ny04MjYzLTJjMDQ3ODc2ZmNmNiIsDQogICAgInBheWVlIjogew0KICAgICAgICAicGFydHlJZEluZm8iOiB7DQogICAgICAgICAgICAicGFydHlJZFR5cGUiOiAiTVNJU0ROIiwNCiAgICAgICAgICAgICJwYXJ0eUlkZW50aWZpZXIiOiAiMTIzNDU2Nzg5IiwNCiAgICAgICAgICAgICJmc3BJZCI6ICJNb2JpbGVNb25leSINCiAgICAgICAgfSwNCiAgICAgICAgInBlcnNvbmFsSW5mbyI6IHsNCiAgICAgICAgICAgICJjb21wbGV4TmFtZSI6IHsNCiAgICAgICAgICAgICAgICAiZmlyc3ROYW1lIjogIkhlbnJpayIsDQogICAgICAgICAgICAgICAgImxhc3ROYW1lIjogIkthcmxzc29uIg0KICAgICAgICAgICAgfQ0KICAgICAgICB9DQogICAgfSwNCiAgICAicGF5ZXIiOiB7DQogICAgICAgICJwZXJzb25hbEluZm8iOiB7DQogICAgICAgICAgICAiY29tcGxleE5hbWUiOiB7DQogICAgICAgICAgICAgICAgImZpcnN0TmFtZSI6ICJNYXRzIiwNCiAgICAgICAgICAgICAgICAibGFzdE5hbWUiOiAiSGFnbWFuIg0KICAgICAgICAgICAgfQ0KICAgICAgICB9LA0KICAgICAgICAicGFydHlJZEluZm8iOiB7DQogICAgICAgICAgICAicGFydHlJZFR5cGUiOiAiSUJBTiIsDQogICAgICAgICAgICAicGFydHlJZGVudGlmaWVyIjogIlNFNDU1MDAwMDAwMDA1ODM5ODI1NzQ2NiIsDQogICAgICAgICAgICAiZnNwSWQiOiAiQmFua05yT25lIg0KICAgICAgICB9DQogICAgfSwNCiAgICAiYW1vdW50Ijogew0KICAgICAgICAiYW1vdW50IjogIjEwMCIsDQogICAgICAgICJjdXJyZW5jeSI6ICJVU0QiDQogICAgfSwNCiAgICAidHJhbnNhY3Rpb25UeXBlIjogew0KICAgICAgICAic2NlbmFyaW8iOiAiVFJBTlNGRVIiLA0KICAgICAgICAiaW5pdGlhdG9yIjogIlBBWUVSIiwNCiAgICAgICAgImluaXRpYXRvclR5cGUiOiAiQ09OU1VNRVIiDQogICAgfSwNCiAgICAibm90ZSI6ICJGcm9tIE1hdHMiDQp9DQo==",
|
|
21
|
-
"payeeFsp": "sim",
|
|
22
|
-
"payerFsp": "mojaloop-sdk",
|
|
23
|
-
"transferId": "00000000-0000-1000-8000-000000000001"
|
|
24
|
-
}
|