@mojaloop/sdk-scheme-adapter 12.2.3 → 13.0.1
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/.env.example +3 -0
- package/CHANGELOG.md +26 -0
- package/audit-resolve.json +71 -1
- package/docker/ml-testing-toolkit/spec_files/api_definitions/fspiop_1.1/trigger_templates/transaction_request_followup.json +2 -2
- package/docker/ml-testing-toolkit/spec_files/rules_callback/default.json +7 -7
- package/docker/ml-testing-toolkit/spec_files/rules_response/default.json +16 -16
- package/docker/ml-testing-toolkit/spec_files/rules_response/default_pisp_rules.json +5 -5
- package/docker/ml-testing-toolkit/spec_files/rules_validation/default.json +10 -10
- package/package.json +5 -3
- package/src/InboundServer/handlers.js +114 -52
- package/src/OutboundServer/api.yaml +54 -3
- package/src/OutboundServer/api_interfaces/openapi.d.ts +24 -3
- package/src/OutboundServer/api_template/components/schemas/accountsResponse.yaml +9 -0
- package/src/OutboundServer/api_template/components/schemas/transferRequest.yaml +3 -0
- package/src/OutboundServer/api_template/components/schemas/transferResponse.yaml +28 -2
- package/src/OutboundServer/api_template/components/schemas/transferStatusResponse.yaml +8 -1
- package/src/OutboundServer/handlers.js +4 -1
- package/src/OutboundServer/index.js +6 -4
- package/src/config.js +1 -1
- package/src/index.js +198 -8
- package/src/lib/cache.js +110 -52
- package/src/lib/metrics.js +148 -0
- package/src/lib/model/AccountsModel.js +13 -11
- package/src/lib/model/InboundTransfersModel.js +166 -24
- package/src/lib/model/OutboundRequestToPayModel.js +5 -6
- package/src/lib/model/OutboundRequestToPayTransferModel.js +2 -2
- package/src/lib/model/OutboundTransfersModel.js +314 -52
- package/src/lib/model/PartiesModel.js +1 -1
- package/src/lib/model/common/BackendError.js +28 -4
- package/src/lib/model/common/index.js +2 -1
- package/test/__mocks__/@mojaloop/sdk-standard-components.js +3 -2
- package/test/__mocks__/redis.js +4 -0
- package/test/integration/lib/Outbound/parties.test.js +1 -1
- package/test/unit/InboundServer.test.js +9 -9
- package/test/unit/TestServer.test.js +11 -13
- package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +11 -3
- package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +14 -0
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +13 -0
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +18 -0
- package/test/unit/api/accounts/utils.js +15 -1
- package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +18 -15
- package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +1 -0
- package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +9 -0
- package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +1 -0
- package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +74 -47
- package/test/unit/api/transfers/utils.js +85 -4
- package/test/unit/api/utils.js +4 -1
- package/test/unit/data/commonHttpHeaders.json +1 -0
- package/test/unit/inboundApi/handlers.test.js +45 -14
- package/test/unit/index.test.js +95 -3
- package/test/unit/lib/model/AccountsModel.test.js +9 -6
- package/test/unit/lib/model/InboundTransfersModel.test.js +210 -30
- package/test/unit/lib/model/OutboundRequestToPayModel.test.js +1 -1
- package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +3 -3
- package/test/unit/lib/model/OutboundTransfersModel.test.js +862 -157
- package/test/unit/lib/model/data/defaultConfig.json +9 -9
- package/test/unit/lib/model/data/mockArguments.json +97 -40
- package/test/unit/lib/model/data/payeeParty.json +13 -11
- package/test/unit/lib/model/data/quoteResponse.json +36 -25
- package/test/unit/lib/model/data/transferFulfil.json +5 -3
|
@@ -35,7 +35,7 @@ function createGetTransfersTester({ reqInbound, reqOutbound, apiSpecsOutbound })
|
|
|
35
35
|
|
|
36
36
|
return reqInbound.put(putUrl)
|
|
37
37
|
.send(putBody)
|
|
38
|
-
.set('content-type', 'application/vnd.interoperability.transfers+json;version=1.
|
|
38
|
+
.set('content-type', 'application/vnd.interoperability.transfers+json;version=1.1')
|
|
39
39
|
.set('Date', new Date().toISOString())
|
|
40
40
|
.set('fspiop-source', 'mojaloop-sdk')
|
|
41
41
|
.expect(200);
|
|
@@ -50,9 +50,49 @@ function createGetTransfersTester({ reqInbound, reqOutbound, apiSpecsOutbound })
|
|
|
50
50
|
const res = await reqOutbound.get(`/transfers/${TRANSFER_ID}`);
|
|
51
51
|
const {body} = res;
|
|
52
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.
|
|
53
57
|
delete body.initiatedTimestamp;
|
|
54
58
|
if (body.transferState) {
|
|
55
59
|
delete body.transferState.initiatedTimestamp;
|
|
60
|
+
if(body.transferState.quoteResponse) {
|
|
61
|
+
delete body.transferState.quoteResponse.headers;
|
|
62
|
+
}
|
|
63
|
+
if(body.transferState.getPartiesResponse) {
|
|
64
|
+
delete body.transferState.getPartiesResponse.headers;
|
|
65
|
+
}
|
|
66
|
+
if(body.transferState.fulfil) {
|
|
67
|
+
delete body.transferState.fulfil.headers;
|
|
68
|
+
}
|
|
69
|
+
if(body.transferState.quoteRequest) {
|
|
70
|
+
delete body.transferState.quoteRequest;
|
|
71
|
+
}
|
|
72
|
+
if(body.transferState.getPartiesRequest) {
|
|
73
|
+
delete body.transferState.getPartiesRequest;
|
|
74
|
+
}
|
|
75
|
+
if(body.transferState.prepare) {
|
|
76
|
+
delete body.transferState.prepare;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if(body.quoteResponse) {
|
|
80
|
+
delete body.quoteResponse.headers;
|
|
81
|
+
}
|
|
82
|
+
if(body.getPartiesResponse) {
|
|
83
|
+
delete body.getPartiesResponse.headers;
|
|
84
|
+
}
|
|
85
|
+
if(body.fulfil) {
|
|
86
|
+
delete body.fulfil.headers;
|
|
87
|
+
}
|
|
88
|
+
if(body.quoteRequest) {
|
|
89
|
+
delete body.quoteRequest;
|
|
90
|
+
}
|
|
91
|
+
if(body.getPartiesRequest) {
|
|
92
|
+
delete body.getPartiesRequest;
|
|
93
|
+
}
|
|
94
|
+
if(body.prepare) {
|
|
95
|
+
delete body.prepare;
|
|
56
96
|
}
|
|
57
97
|
expect(body).toEqual(responseBody);
|
|
58
98
|
const responseValidator = new OpenAPIResponseValidator(apiSpecsOutbound.paths['/transfers/{transferId}'].get);
|
|
@@ -108,17 +148,17 @@ function createPostTransfersTester(
|
|
|
108
148
|
if (urlPath.startsWith('/parties/')) {
|
|
109
149
|
putBody = await Promise.resolve(bodyFn.parties.put());
|
|
110
150
|
putUrl = urlPath;
|
|
111
|
-
contentType = 'application/vnd.interoperability.parties+json;version=1.
|
|
151
|
+
contentType = 'application/vnd.interoperability.parties+json;version=1.1';
|
|
112
152
|
} else if (urlPath === '/quotes') {
|
|
113
153
|
expect(body).toEqual(bodyFn.quotes.post(body));
|
|
114
154
|
putBody = await Promise.resolve(bodyFn.quotes.put(body));
|
|
115
155
|
putUrl = `/quotes/${body.quoteId}`;
|
|
116
|
-
contentType = 'application/vnd.interoperability.quotes+json;version=1.
|
|
156
|
+
contentType = 'application/vnd.interoperability.quotes+json;version=1.1';
|
|
117
157
|
} else if (urlPath === '/transfers') {
|
|
118
158
|
expect(body).toEqual(bodyFn.transfers.post(body));
|
|
119
159
|
putBody = await Promise.resolve(bodyFn.transfers.put(body));
|
|
120
160
|
putUrl = `/transfers/${body.transferId}`;
|
|
121
|
-
contentType = 'application/vnd.interoperability.transfers+json;version=1.
|
|
161
|
+
contentType = 'application/vnd.interoperability.transfers+json;version=1.1';
|
|
122
162
|
} else {
|
|
123
163
|
throw new Error(`Unexpected url ${urlPath}`);
|
|
124
164
|
}
|
|
@@ -162,10 +202,51 @@ function createPostTransfersTester(
|
|
|
162
202
|
|
|
163
203
|
const res = await reqOutbound.post('/transfers').send(postTransfersSimpleBody);
|
|
164
204
|
const {body} = res;
|
|
205
|
+
console.log(body)
|
|
165
206
|
expect(res.statusCode).toEqual(responseCode);
|
|
207
|
+
|
|
208
|
+
// remove elements of the response we do not want/need to compare for correctness.
|
|
209
|
+
// timestamps on requests/responses for example will be set by the HTTP framework
|
|
210
|
+
// and we dont want to compare against static values.
|
|
166
211
|
delete body.initiatedTimestamp;
|
|
167
212
|
if (body.transferState) {
|
|
168
213
|
delete body.transferState.initiatedTimestamp;
|
|
214
|
+
if(body.transferState.quoteResponse) {
|
|
215
|
+
delete body.transferState.quoteResponse.headers;
|
|
216
|
+
}
|
|
217
|
+
if(body.transferState.getPartiesResponse) {
|
|
218
|
+
delete body.transferState.getPartiesResponse.headers;
|
|
219
|
+
}
|
|
220
|
+
if(body.transferState.fulfil) {
|
|
221
|
+
delete body.transferState.fulfil.headers;
|
|
222
|
+
}
|
|
223
|
+
if(body.transferState.quoteRequest) {
|
|
224
|
+
delete body.transferState.quoteRequest;
|
|
225
|
+
}
|
|
226
|
+
if(body.transferState.getPartiesRequest) {
|
|
227
|
+
delete body.transferState.getPartiesRequest;
|
|
228
|
+
}
|
|
229
|
+
if(body.transferState.prepare) {
|
|
230
|
+
delete body.transferState.prepare;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if(body.quoteResponse) {
|
|
234
|
+
delete body.quoteResponse.headers;
|
|
235
|
+
}
|
|
236
|
+
if(body.getPartiesResponse) {
|
|
237
|
+
delete body.getPartiesResponse.headers;
|
|
238
|
+
}
|
|
239
|
+
if(body.fulfil) {
|
|
240
|
+
delete body.fulfil.headers;
|
|
241
|
+
}
|
|
242
|
+
if(body.quoteRequest) {
|
|
243
|
+
delete body.quoteRequest;
|
|
244
|
+
}
|
|
245
|
+
if(body.getPartiesRequest) {
|
|
246
|
+
delete body.getPartiesRequest;
|
|
247
|
+
}
|
|
248
|
+
if(body.prepare) {
|
|
249
|
+
delete body.prepare;
|
|
169
250
|
}
|
|
170
251
|
expect(body).toEqual(responseBody);
|
|
171
252
|
const responseValidator = new OpenAPIResponseValidator(apiSpecsOutbound.paths['/transfers'].post);
|
package/test/unit/api/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ const Validate = require('~/lib/validate');
|
|
|
6
6
|
|
|
7
7
|
const InboundServer = require('~/InboundServer');
|
|
8
8
|
const OutboundServer = require('~/OutboundServer');
|
|
9
|
+
const { MetricsClient } = require('~/lib/metrics');
|
|
9
10
|
const { Logger } = require('@mojaloop/sdk-standard-components');
|
|
10
11
|
const Cache = require('~/lib/cache');
|
|
11
12
|
|
|
@@ -47,7 +48,9 @@ const createTestServers = async (config) => {
|
|
|
47
48
|
});
|
|
48
49
|
await cache.connect();
|
|
49
50
|
defConfig.requestProcessingTimeoutSeconds = 2;
|
|
50
|
-
const
|
|
51
|
+
const metricsClient = new MetricsClient();
|
|
52
|
+
metricsClient._prometheusRegister.clear();
|
|
53
|
+
const serverOutbound = new OutboundServer(defConfig, logger, cache, metricsClient);
|
|
51
54
|
await serverOutbound.start();
|
|
52
55
|
const reqOutbound = supertest(serverOutbound._server);
|
|
53
56
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"content-type": "application/vnd.interoperability.parties+json;version=1.1",
|
|
2
3
|
"fspiop-source": "other-dfsp",
|
|
3
4
|
"fspiop-destination": "mojaloop-sdk",
|
|
4
5
|
"fspiop-signature": "{\"signature\":\"aTTa1TTCBJA1K1VoEFgpSicWYU0q1VYXV-bjkk7uoeNicog7QSp9_AbwtYm4u8NJ1HFM_3mekE8wioAs5YNugnTlJ1k-q4Ouvp5Jo3ZnozoPVtnLaqdhxRMUBOHfDp0X8eCHEo7lETjKcCcH4r5_KT_9Vwx5TMytoG_y9Be8PpviJFkOqOV5jCeIl7XzL_pZQoY0pRJdkXDzYpXDu-HTYKr8ckxWQzx4HO-viJQd2ByQkbqPfQom9IQaAX1t4yztCCpOQn1LY9j9sbfEX9RPXG3UbY6UyDsNjUKYP9BAhXwI9pFWlgv2i9FvEtay2QYdwbW7XEpIiGZ_vi5d6yc12w\",\"protectedHeader\":\"eyJhbGciOiJSUzI1NiIsIkZTUElPUC1VUkkiOiIvcGFydGllcy9NU0lTRE4vMTIzNDU2Nzg5IiwiRlNQSU9QLUhUVFAtTWV0aG9kIjoiUFVUIiwiRlNQSU9QLVNvdXJjZSI6InNpbSIsIkZTUElPUC1EZXN0aW5hdGlvbiI6ImRmc3AiLCJEYXRlIjoiVGh1LCAzMSBPY3QgMjAxOSAxMTo0MTo0MyBHTVQifQ\"}",
|
|
@@ -58,7 +58,7 @@ describe('Inbound API handlers:', () => {
|
|
|
58
58
|
await expect(handlers['/quotes'].post(mockContext)).resolves.toBe(undefined);
|
|
59
59
|
|
|
60
60
|
expect(quoteRequestSpy).toHaveBeenCalledTimes(1);
|
|
61
|
-
expect(quoteRequestSpy.mock.calls[0][0]).
|
|
61
|
+
expect(quoteRequestSpy.mock.calls[0][0]).toStrictEqual(mockContext.request);
|
|
62
62
|
expect(quoteRequestSpy.mock.calls[0][1]).toBe(mockContext.request.headers['fspiop-source']);
|
|
63
63
|
});
|
|
64
64
|
|
|
@@ -138,7 +138,10 @@ describe('Inbound API handlers:', () => {
|
|
|
138
138
|
expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
|
|
139
139
|
expect(triggerDeferredJobSpy).toBeCalledWith({
|
|
140
140
|
cache: mockContext.state.cache,
|
|
141
|
-
message:
|
|
141
|
+
message: {
|
|
142
|
+
body: mockContext.request.body,
|
|
143
|
+
headers: mockContext.request.headers,
|
|
144
|
+
},
|
|
142
145
|
args: {
|
|
143
146
|
quoteId: mockContext.state.path.params.ID
|
|
144
147
|
}
|
|
@@ -215,8 +218,10 @@ describe('Inbound API handlers:', () => {
|
|
|
215
218
|
expect(bulkQuotesSpy).toHaveBeenCalledTimes(1);
|
|
216
219
|
expect(bulkQuotesSpy.mock.calls[0][1]).toMatchObject({
|
|
217
220
|
type: 'bulkQuoteResponse',
|
|
218
|
-
data:
|
|
219
|
-
|
|
221
|
+
data: {
|
|
222
|
+
body: mockContext.request.body,
|
|
223
|
+
headers: mockContext.request.headers,
|
|
224
|
+
}
|
|
220
225
|
});
|
|
221
226
|
});
|
|
222
227
|
});
|
|
@@ -263,7 +268,10 @@ describe('Inbound API handlers:', () => {
|
|
|
263
268
|
expect(bulkQuotesSpy).toHaveBeenCalledTimes(1);
|
|
264
269
|
expect(bulkQuotesSpy.mock.calls[0][1]).toMatchObject({
|
|
265
270
|
type: 'bulkQuoteResponseError',
|
|
266
|
-
data:
|
|
271
|
+
data: {
|
|
272
|
+
body: mockContext.request.body,
|
|
273
|
+
headers: mockContext.request.headers,
|
|
274
|
+
}
|
|
267
275
|
});
|
|
268
276
|
});
|
|
269
277
|
});
|
|
@@ -372,8 +380,10 @@ describe('Inbound API handlers:', () => {
|
|
|
372
380
|
expect(bulkTransfersSpy).toHaveBeenCalledTimes(1);
|
|
373
381
|
expect(bulkTransfersSpy.mock.calls[0][1]).toMatchObject({
|
|
374
382
|
type: 'bulkTransferResponse',
|
|
375
|
-
data:
|
|
376
|
-
|
|
383
|
+
data: {
|
|
384
|
+
body: mockContext.request.body,
|
|
385
|
+
headers: mockContext.request.headers,
|
|
386
|
+
}
|
|
377
387
|
});
|
|
378
388
|
});
|
|
379
389
|
});
|
|
@@ -420,7 +430,10 @@ describe('Inbound API handlers:', () => {
|
|
|
420
430
|
expect(bulkTransfersSpy).toHaveBeenCalledTimes(1);
|
|
421
431
|
expect(bulkTransfersSpy.mock.calls[0][1]).toMatchObject({
|
|
422
432
|
type: 'bulkTransferResponseError',
|
|
423
|
-
data:
|
|
433
|
+
data: {
|
|
434
|
+
body: mockContext.request.body,
|
|
435
|
+
headers: mockContext.request.headers,
|
|
436
|
+
}
|
|
424
437
|
});
|
|
425
438
|
});
|
|
426
439
|
});
|
|
@@ -601,7 +614,10 @@ describe('Inbound API handlers:', () => {
|
|
|
601
614
|
expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
|
|
602
615
|
expect(triggerDeferredJobSpy).toBeCalledWith({
|
|
603
616
|
cache: mockContext.state.cache,
|
|
604
|
-
message:
|
|
617
|
+
message: {
|
|
618
|
+
body: mockContext.request.body,
|
|
619
|
+
headers: mockContext.request.headers,
|
|
620
|
+
},
|
|
605
621
|
args: {
|
|
606
622
|
type: mockContext.state.path.params.Type,
|
|
607
623
|
id: mockContext.state.path.params.ID
|
|
@@ -620,7 +636,10 @@ describe('Inbound API handlers:', () => {
|
|
|
620
636
|
expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
|
|
621
637
|
expect(triggerDeferredJobSpy).toBeCalledWith({
|
|
622
638
|
cache: mockContext.state.cache,
|
|
623
|
-
message:
|
|
639
|
+
message: {
|
|
640
|
+
body: mockContext.request.body,
|
|
641
|
+
headers: mockContext.request.headers,
|
|
642
|
+
},
|
|
624
643
|
args: {
|
|
625
644
|
type: mockContext.state.path.params.Type,
|
|
626
645
|
id: mockContext.state.path.params.ID,
|
|
@@ -667,7 +686,10 @@ describe('Inbound API handlers:', () => {
|
|
|
667
686
|
expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
|
|
668
687
|
expect(triggerDeferredJobSpy).toBeCalledWith({
|
|
669
688
|
cache: mockContext.state.cache,
|
|
670
|
-
message:
|
|
689
|
+
message: {
|
|
690
|
+
body: mockContext.request.body,
|
|
691
|
+
headers: mockContext.request.headers,
|
|
692
|
+
},
|
|
671
693
|
args: {
|
|
672
694
|
transferId: mockContext.state.path.params.ID
|
|
673
695
|
}
|
|
@@ -682,7 +704,10 @@ describe('Inbound API handlers:', () => {
|
|
|
682
704
|
expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
|
|
683
705
|
expect(triggerDeferredJobSpy).toBeCalledWith({
|
|
684
706
|
cache: mockContext.state.cache,
|
|
685
|
-
message:
|
|
707
|
+
message: {
|
|
708
|
+
body: mockContext.request.body,
|
|
709
|
+
headers: mockContext.request.headers,
|
|
710
|
+
},
|
|
686
711
|
args: {
|
|
687
712
|
transferId: mockContext.state.path.params.ID,
|
|
688
713
|
}
|
|
@@ -728,7 +753,10 @@ describe('Inbound API handlers:', () => {
|
|
|
728
753
|
expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
|
|
729
754
|
expect(triggerDeferredJobSpy).toBeCalledWith({
|
|
730
755
|
cache: mockContext.state.cache,
|
|
731
|
-
message:
|
|
756
|
+
message: {
|
|
757
|
+
body: mockContext.request.body,
|
|
758
|
+
headers: mockContext.request.headers,
|
|
759
|
+
},
|
|
732
760
|
args: {
|
|
733
761
|
transferId: mockContext.state.path.params.ID
|
|
734
762
|
}
|
|
@@ -743,7 +771,10 @@ describe('Inbound API handlers:', () => {
|
|
|
743
771
|
expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
|
|
744
772
|
expect(triggerDeferredJobSpy).toBeCalledWith({
|
|
745
773
|
cache: mockContext.state.cache,
|
|
746
|
-
message:
|
|
774
|
+
message: {
|
|
775
|
+
body: mockContext.request.body,
|
|
776
|
+
headers: mockContext.request.headers,
|
|
777
|
+
},
|
|
747
778
|
args: {
|
|
748
779
|
transferId: mockContext.state.path.params.ID,
|
|
749
780
|
}
|
package/test/unit/index.test.js
CHANGED
|
@@ -10,13 +10,18 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
const { Logger } = require('@mojaloop/sdk-standard-components');
|
|
14
|
-
const defaultConfig = require('./data/defaultConfig');
|
|
15
|
-
|
|
16
13
|
jest.mock('dotenv', () => ({
|
|
17
14
|
config: jest.fn()
|
|
18
15
|
}));
|
|
19
16
|
|
|
17
|
+
const promClient = require('prom-client');
|
|
18
|
+
const defaultConfig = require('./data/defaultConfig.json');
|
|
19
|
+
const { Logger } = require('@mojaloop/sdk-standard-components');
|
|
20
|
+
const { MetricsClient } = require('~/lib/metrics');
|
|
21
|
+
|
|
22
|
+
const TestControlServer = require('./ControlServer');
|
|
23
|
+
|
|
24
|
+
|
|
20
25
|
process.env.PEER_ENDPOINT = '172.17.0.3:4000';
|
|
21
26
|
process.env.BACKEND_ENDPOINT = '172.17.0.5:4000';
|
|
22
27
|
process.env.CACHE_HOST = '172.17.0.2';
|
|
@@ -26,6 +31,10 @@ process.env.MGMT_API_WS_URL = '0.0.0.0';
|
|
|
26
31
|
const index = require('~/index.js');
|
|
27
32
|
|
|
28
33
|
describe('index.js', () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
promClient.register.clear();
|
|
36
|
+
});
|
|
37
|
+
|
|
29
38
|
test('WSO2 error events in OutboundServer propagate to top-level server', () => {
|
|
30
39
|
const logger = new Logger.Logger({ stringify: () => '' });
|
|
31
40
|
const svr = new index.Server(defaultConfig, logger);
|
|
@@ -53,3 +62,86 @@ describe('index.js', () => {
|
|
|
53
62
|
expect(typeof(index.Cache)).toBe('function');
|
|
54
63
|
});
|
|
55
64
|
});
|
|
65
|
+
|
|
66
|
+
describe('Server', () => {
|
|
67
|
+
let server, controlServer, conf, logger;
|
|
68
|
+
|
|
69
|
+
beforeEach(async () => {
|
|
70
|
+
promClient.register.clear();
|
|
71
|
+
logger = new Logger.Logger({ stringify: () => '' });
|
|
72
|
+
conf = JSON.parse(JSON.stringify(defaultConfig));
|
|
73
|
+
conf.enableTestFeatures = true;
|
|
74
|
+
conf.pm4mlEnabled = true;
|
|
75
|
+
conf.control.mgmtAPIWsUrl = 'localhost';
|
|
76
|
+
conf.control.mgmtAPIWsPort = 4005;
|
|
77
|
+
conf.control.port = conf.control.mgmtAPIWsPort;
|
|
78
|
+
controlServer = new TestControlServer.Server({ logger, appConfig: conf });
|
|
79
|
+
server = new index.Server(conf, logger);
|
|
80
|
+
await server.start();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
afterEach(async () => {
|
|
84
|
+
await controlServer.stop();
|
|
85
|
+
await server.stop();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('is reconfigured correctly by the control client', () => {
|
|
89
|
+
let newConf;
|
|
90
|
+
beforeEach(async () => {
|
|
91
|
+
// not every server restarts on every config change, we'll make sure they all restart
|
|
92
|
+
newConf = { ...conf, logIndent: conf.logIndent + 1, control: { ...conf.control, rubbish: 'data' }, test: { trash: 'data' } };
|
|
93
|
+
// Just in case, we'll assert the new configuration is different to the old one
|
|
94
|
+
expect(newConf).not.toEqual(conf);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('reconfigures and restarts constituent servers when triggered by control client', async () => {
|
|
98
|
+
const [restartInbound, restartOutbound, restartControl, restartOAuthTest, restartTest] =
|
|
99
|
+
Array.from({ length: 5 }).map(() => jest.fn());
|
|
100
|
+
server.inboundServer.reconfigure = jest.fn(() => restartInbound);
|
|
101
|
+
server.outboundServer.reconfigure = jest.fn(() => restartOutbound);
|
|
102
|
+
server.testServer.reconfigure = jest.fn(() => restartTest);
|
|
103
|
+
server.oauthTestServer.reconfigure = jest.fn(() => restartOAuthTest);
|
|
104
|
+
server.controlClient.reconfigure = jest.fn(() => restartControl);
|
|
105
|
+
|
|
106
|
+
await controlServer.broadcastConfigChange(newConf);
|
|
107
|
+
|
|
108
|
+
// We wait for the servers to get restarted
|
|
109
|
+
await new Promise((wait) => setTimeout(wait, 1000));
|
|
110
|
+
|
|
111
|
+
expect(server.inboundServer.reconfigure).toHaveBeenCalledTimes(1);
|
|
112
|
+
expect(server.inboundServer.reconfigure).toHaveBeenCalledWith(
|
|
113
|
+
newConf, expect.any(Logger.Logger), expect.any(index.Cache)
|
|
114
|
+
);
|
|
115
|
+
expect(server.outboundServer.reconfigure).toHaveBeenCalledTimes(1);
|
|
116
|
+
const metricsClient = new MetricsClient();
|
|
117
|
+
expect(server.outboundServer.reconfigure).toHaveBeenCalledWith(
|
|
118
|
+
newConf, expect.any(Logger.Logger), expect.any(index.Cache), metricsClient
|
|
119
|
+
);
|
|
120
|
+
expect(server.controlClient.reconfigure).toHaveBeenCalledTimes(1);
|
|
121
|
+
expect(server.controlClient.reconfigure).toHaveBeenCalledWith({
|
|
122
|
+
logger: expect.any(Logger.Logger),
|
|
123
|
+
port: newConf.control.port,
|
|
124
|
+
appConfig: newConf
|
|
125
|
+
});
|
|
126
|
+
expect(server.testServer.reconfigure).toHaveBeenCalledTimes(1);
|
|
127
|
+
expect(server.testServer.reconfigure).toHaveBeenCalledWith({
|
|
128
|
+
logger: expect.any(Logger.Logger),
|
|
129
|
+
cache: expect.any(index.Cache),
|
|
130
|
+
port: newConf.test.port
|
|
131
|
+
});
|
|
132
|
+
expect(server.oauthTestServer.reconfigure).toHaveBeenCalledTimes(1);
|
|
133
|
+
expect(server.oauthTestServer.reconfigure).toHaveBeenCalledWith({
|
|
134
|
+
logger: expect.any(Logger.Logger),
|
|
135
|
+
clientKey: newConf.oauthTestServer.clientKey,
|
|
136
|
+
clientSecret: newConf.oauthTestServer.clientSecret,
|
|
137
|
+
port: newConf.oauthTestServer.listenPort,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
expect(restartInbound).toHaveBeenCalledTimes(1);
|
|
141
|
+
expect(restartOutbound).toHaveBeenCalledTimes(1);
|
|
142
|
+
expect(restartTest).toHaveBeenCalledTimes(1);
|
|
143
|
+
expect(restartOAuthTest).toHaveBeenCalledTimes(1);
|
|
144
|
+
expect(restartControl).toHaveBeenCalledTimes(1);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -51,14 +51,17 @@ describe('AccountsModel', () => {
|
|
|
51
51
|
const response = {
|
|
52
52
|
type: 'accountsCreationSuccessfulResponse',
|
|
53
53
|
data: {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
body: {
|
|
55
|
+
partyList: request.partyList.map(party => ({
|
|
56
|
+
partyId: party,
|
|
57
|
+
// errorInformation: null
|
|
58
|
+
})),
|
|
59
|
+
currency: request.currency,
|
|
60
|
+
},
|
|
61
|
+
headers: {}
|
|
59
62
|
},
|
|
60
63
|
};
|
|
61
|
-
cache.publish(`ac_${request.requestId}`,
|
|
64
|
+
cache.publish(`ac_${request.requestId}`, response);
|
|
62
65
|
return Promise.resolve();
|
|
63
66
|
});
|
|
64
67
|
|