@mojaloop/sdk-scheme-adapter 18.0.0 → 18.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.
Files changed (116) hide show
  1. package/.dockerignore +18 -0
  2. package/.eslintignore +2 -0
  3. package/CHANGELOG.md +8 -0
  4. package/audit-resolve.json +5 -0
  5. package/package.json +2 -2
  6. package/test/__mocks__/@mojaloop/sdk-standard-components.js +0 -151
  7. package/test/__mocks__/javascript-state-machine.js +0 -21
  8. package/test/__mocks__/redis.js +0 -78
  9. package/test/__mocks__/uuidv4.js +0 -16
  10. package/test/config/integration.env +0 -146
  11. package/test/integration/lib/Outbound/data/quotesPostRequest.json +0 -52
  12. package/test/integration/lib/Outbound/data/transfersPostRequest.json +0 -24
  13. package/test/integration/lib/Outbound/parties.test.js +0 -31
  14. package/test/integration/lib/Outbound/quotes.test.js +0 -62
  15. package/test/integration/lib/Outbound/simpleTransfers.test.js +0 -70
  16. package/test/integration/lib/cache.test.js +0 -79
  17. package/test/integration/testEnv.js +0 -4
  18. package/test/unit/ControlClient.test.js +0 -69
  19. package/test/unit/ControlServer/events.js +0 -41
  20. package/test/unit/ControlServer/index.js +0 -227
  21. package/test/unit/ControlServer.test.js +0 -66
  22. package/test/unit/InboundServer.test.js +0 -443
  23. package/test/unit/TestServer.test.js +0 -392
  24. package/test/unit/api/accounts/accounts.test.js +0 -128
  25. package/test/unit/api/accounts/data/postAccountsBody.json +0 -7
  26. package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +0 -33
  27. package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +0 -19
  28. package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +0 -31
  29. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +0 -34
  30. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +0 -39
  31. package/test/unit/api/accounts/utils.js +0 -79
  32. package/test/unit/api/proxy/data/proxyConfig.yaml +0 -82
  33. package/test/unit/api/proxy/data/requestBody.json +0 -22
  34. package/test/unit/api/proxy/data/requestHeaders.json +0 -5
  35. package/test/unit/api/proxy/data/requestQuery.json +0 -6
  36. package/test/unit/api/proxy/data/responseBody.json +0 -21
  37. package/test/unit/api/proxy/data/responseHeaders.json +0 -5
  38. package/test/unit/api/proxy/proxy.test.js +0 -220
  39. package/test/unit/api/proxy/utils.js +0 -79
  40. package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +0 -24
  41. package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +0 -18
  42. package/test/unit/api/transfers/data/postQuotesBody.json +0 -52
  43. package/test/unit/api/transfers/data/postTransfersBadBody.json +0 -17
  44. package/test/unit/api/transfers/data/postTransfersBody.json +0 -24
  45. package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +0 -62
  46. package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +0 -48
  47. package/test/unit/api/transfers/data/postTransfersSimpleBody.json +0 -26
  48. package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +0 -128
  49. package/test/unit/api/transfers/data/putPartiesBody.json +0 -20
  50. package/test/unit/api/transfers/data/putQuotesBody.json +0 -37
  51. package/test/unit/api/transfers/data/putTransfersBody.json +0 -17
  52. package/test/unit/api/transfers/transfers.test.js +0 -191
  53. package/test/unit/api/transfers/utils.js +0 -264
  54. package/test/unit/api/utils.js +0 -86
  55. package/test/unit/config.test.js +0 -119
  56. package/test/unit/data/commonHttpHeaders.json +0 -7
  57. package/test/unit/data/defaultConfig.json +0 -70
  58. package/test/unit/data/postQuotesBody.json +0 -52
  59. package/test/unit/data/putParticipantsBody.json +0 -12
  60. package/test/unit/data/putPartiesBody.json +0 -20
  61. package/test/unit/data/testFile.json +0 -29
  62. package/test/unit/data/testFile.yaml +0 -14
  63. package/test/unit/inboundApi/data/mockArguments.json +0 -117
  64. package/test/unit/inboundApi/data/mockTransactionRequest.json +0 -42
  65. package/test/unit/inboundApi/handlers.test.js +0 -786
  66. package/test/unit/index.test.js +0 -88
  67. package/test/unit/lib/cache.test.js +0 -145
  68. package/test/unit/lib/model/AccountsModel.test.js +0 -124
  69. package/test/unit/lib/model/InboundTransfersModel.test.js +0 -889
  70. package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +0 -253
  71. package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +0 -247
  72. package/test/unit/lib/model/OutboundRequestToPayModel.test.js +0 -166
  73. package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +0 -245
  74. package/test/unit/lib/model/OutboundTransfersModel.test.js +0 -1579
  75. package/test/unit/lib/model/PartiesModel.test.js +0 -478
  76. package/test/unit/lib/model/QuotesModel.test.js +0 -477
  77. package/test/unit/lib/model/TransfersModel.test.js +0 -481
  78. package/test/unit/lib/model/common/PersistentStateMachine.test.js +0 -178
  79. package/test/unit/lib/model/data/authorizationsResponse.json +0 -13
  80. package/test/unit/lib/model/data/bulkQuoteRequest.json +0 -27
  81. package/test/unit/lib/model/data/bulkQuoteResponse.json +0 -35
  82. package/test/unit/lib/model/data/bulkTransferFulfil.json +0 -13
  83. package/test/unit/lib/model/data/bulkTransferRequest.json +0 -29
  84. package/test/unit/lib/model/data/defaultConfig.json +0 -59
  85. package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +0 -42
  86. package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +0 -22
  87. package/test/unit/lib/model/data/getTransfersBackendResponse.json +0 -34
  88. package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +0 -17
  89. package/test/unit/lib/model/data/mockArguments.json +0 -188
  90. package/test/unit/lib/model/data/mockTxnRequestsArguments.json +0 -63
  91. package/test/unit/lib/model/data/notificationAbortedToPayee.json +0 -10
  92. package/test/unit/lib/model/data/notificationReservedToPayee.json +0 -10
  93. package/test/unit/lib/model/data/notificationToPayee.json +0 -10
  94. package/test/unit/lib/model/data/payeeParty.json +0 -18
  95. package/test/unit/lib/model/data/putQuotesResponse.json +0 -33
  96. package/test/unit/lib/model/data/putTransfersResponse.json +0 -5
  97. package/test/unit/lib/model/data/quoteResponse.json +0 -42
  98. package/test/unit/lib/model/data/requestToPayRequest.json +0 -20
  99. package/test/unit/lib/model/data/requestToPayTransferRequest.json +0 -27
  100. package/test/unit/lib/model/data/transactionRequestResponse.json +0 -18
  101. package/test/unit/lib/model/data/transferFulfil.json +0 -10
  102. package/test/unit/lib/model/data/transferRequest.json +0 -26
  103. package/test/unit/lib/model/mockedLibRequests.js +0 -74
  104. package/test/unit/mockLogger.js +0 -39
  105. package/test/unit/outboundApi/data/bulkQuoteRequest.json +0 -28
  106. package/test/unit/outboundApi/data/bulkTransferRequest.json +0 -28
  107. package/test/unit/outboundApi/data/mockBulkQuoteError.json +0 -45
  108. package/test/unit/outboundApi/data/mockBulkTransferError.json +0 -48
  109. package/test/unit/outboundApi/data/mockError.json +0 -41
  110. package/test/unit/outboundApi/data/mockGetPartiesError.json +0 -4
  111. package/test/unit/outboundApi/data/mockRequestToPayError.json +0 -32
  112. package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +0 -39
  113. package/test/unit/outboundApi/data/requestToPay.json +0 -21
  114. package/test/unit/outboundApi/data/requestToPayTransferRequest.json +0 -20
  115. package/test/unit/outboundApi/data/transferRequest.json +0 -21
  116. package/test/unit/outboundApi/handlers.test.js +0 -887
@@ -1,392 +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
- * James Bush - james.bush@modusbox.com *
9
- **************************************************************************/
10
-
11
- 'use strict';
12
-
13
- const supertest = require('supertest');
14
-
15
- const defaultConfig = require('./data/defaultConfig');
16
- const putPartiesBody = require('./data/putPartiesBody');
17
- const postQuotesBody = require('./data/postQuotesBody');
18
- const putParticipantsBody = require('./data/putParticipantsBody');
19
- const commonHttpHeaders = require('./data/commonHttpHeaders');
20
- const WebSocket = require('ws');
21
- const { Logger } = require('@mojaloop/sdk-standard-components');
22
-
23
- jest.mock('~/lib/cache');
24
- jest.mock('@mojaloop/sdk-standard-components');
25
- jest.mock('~/lib/model/lib/requests', () => require('./lib/model/mockedLibRequests'));
26
-
27
- const Cache = require('~/lib/cache');
28
- const InboundServer = require('~/InboundServer');
29
- const TestServer = require('~/TestServer');
30
-
31
- const createWsClient = async (port, path) => {
32
- const result = new WebSocket(`ws://127.0.0.1:${port}${path}`);
33
- await new Promise((resolve, reject) => {
34
- result.on('open', resolve);
35
- result.on('error', reject);
36
- });
37
- return result;
38
- };
39
-
40
- describe('Test Server', () => {
41
- let testServer, inboundServer, inboundReq, testReq, serverConfig, wsClients, testServerPort,
42
- logger, cache;
43
-
44
- beforeEach(async () => {
45
- Cache.mockClear();
46
-
47
- logger = new Logger.Logger({ stringify: () => '' });
48
-
49
- serverConfig = {
50
- ...JSON.parse(JSON.stringify(defaultConfig)),
51
- enableTestFeatures: true,
52
- };
53
- cache = new Cache({ cacheUrl: serverConfig.cacheUrl, logger: logger.push({ component: 'cache' }), enableTestFeatures: true });
54
-
55
- testServer = new TestServer({ logger, cache });
56
- await testServer.start();
57
- testServerPort = testServer._server.address().port;
58
-
59
- expect(testServer._server.listening).toBe(true);
60
- testReq = supertest.agent(testServer._server);
61
-
62
- inboundServer = new InboundServer(serverConfig, logger, cache);
63
- await inboundServer.start();
64
- inboundReq = supertest(inboundServer._server);
65
-
66
- wsClients = {
67
- root: await createWsClient(testServerPort, '/'),
68
- callbacks: await createWsClient(testServerPort, '/callbacks'),
69
- requests: await createWsClient(testServerPort, '/requests'),
70
- };
71
-
72
- expect(Object.values(wsClients).every((cli) => cli.readyState === WebSocket.OPEN)).toBe(true);
73
- expect(testServer._wsapi._wsClients.size).toBeGreaterThan(0);
74
-
75
- expect(Cache).toHaveBeenCalledTimes(1);
76
- });
77
-
78
- afterEach(async () => {
79
- await Promise.all(Object.values(wsClients).map((cli) => {
80
- cli.close();
81
- return new Promise((resolve) => cli.on('close', resolve));
82
- }));
83
- await testServer.stop();
84
- await inboundServer.stop();
85
- });
86
-
87
- // TODO: check this happens correctly with top-level server if possible?
88
- test('Inbound server and Test server construct cache with same parameters when provided same config', async () => {
89
- expect(Cache).toHaveBeenCalledTimes(1);
90
- const testArgs = { ...Cache.mock.calls[0][0], logger: expect.anything() };
91
- expect(Cache).toHaveBeenNthCalledWith(1, testArgs);
92
- });
93
-
94
- test('Health check', async () => {
95
- const result = await testReq.get('/');
96
- expect(result.ok).toBeTruthy();
97
- expect(result.statusCode).toEqual(204);
98
- });
99
-
100
- test('PUT /parties cache get and set use same value', async () => {
101
- const MSISDN = '123456789';
102
-
103
- await inboundReq
104
- .put(`/parties/MSISDN/${MSISDN}`)
105
- .send(putPartiesBody)
106
- .set(commonHttpHeaders)
107
- .set('content-type', 'application/vnd.interoperability.parties+json;version=1.1')
108
- .set('fspiop-http-method', 'PUT')
109
- .set('fspiop-uri', `/parties/MSISDN/${MSISDN}`)
110
- .set('date', new Date().toISOString());
111
-
112
- await testReq.get(`/callbacks/${MSISDN}`);
113
-
114
- expect(cache.set.mock.calls[0][0]).toEqual(cache.get.mock.calls[0][0]);
115
- });
116
-
117
- test('POST /quotes requests cache get and set use same value', async () => {
118
- await inboundReq
119
- .post('/quotes')
120
- .send(postQuotesBody)
121
- .set(commonHttpHeaders)
122
- .set('content-type', 'application/vnd.interoperability.quotes+json;version=1.1')
123
- .set('fspiop-http-method', 'POST')
124
- .set('fspiop-uri', '/quotes')
125
- .set('date', new Date().toISOString());
126
-
127
- await testReq.get(`/requests/${postQuotesBody.quoteId}`);
128
-
129
- expect(cache.set.mock.calls[0][0]).toEqual(cache.get.mock.calls[0][0]);
130
- });
131
-
132
- test('PUT /participants callbacks cache get and set use same value', async () => {
133
- const participantId = '00000000-0000-1000-a000-000000000002';
134
-
135
- await inboundReq
136
- .put(`/participants/${participantId}`)
137
- .send(putParticipantsBody)
138
- .set(commonHttpHeaders)
139
- .set('content-type', 'application/vnd.interoperability.participants+json;version=1.1')
140
- .set('fspiop-http-method', 'PUT')
141
- .set('fspiop-uri', `/participants/${participantId}`)
142
- .set('date', new Date().toISOString());
143
-
144
- await testReq.get(`/callbacks/${participantId}`);
145
-
146
- expect(cache.set.mock.calls[0][0]).toEqual(cache.get.mock.calls[0][0]);
147
- });
148
-
149
- test('Subscribes to the keyevent set notification', async () => {
150
- expect(testServer._wsapi._cache.subscribe).toBeCalledTimes(1);
151
- expect(testServer._wsapi._cache.subscribe).toHaveBeenCalledWith(
152
- testServer._wsapi._cache.EVENT_SET,
153
- expect.any(Function),
154
- );
155
- });
156
-
157
- test('WebSocket /callbacks and / endpoint triggers send to client when callback received to inbound server', async () => {
158
- const participantId = '00000000-0000-1000-a000-000000000002';
159
-
160
- const headers = {
161
- ...commonHttpHeaders,
162
- 'content-type': 'application/vnd.interoperability.participants+json;version=1.1',
163
- 'fspiop-http-method': 'PUT',
164
- 'fspiop-uri': `/participants/${participantId}`,
165
- 'date': new Date().toISOString(),
166
- };
167
-
168
- const putParticipantWsClient = await createWsClient(
169
- testServerPort,
170
- `/callbacks/${participantId}`
171
- );
172
-
173
- const putParticipantEndpointMessageReceived = new Promise(resolve => {
174
- putParticipantWsClient.on('message', resolve);
175
- });
176
- const serverCallbackEndpointMessageReceived = new Promise(resolve => {
177
- wsClients.callbacks.on('message', resolve);
178
- });
179
- const serverRootEndpointMessageReceived = new Promise(resolve => {
180
- wsClients.root.on('message', resolve);
181
- });
182
-
183
- // get the callback function that the test server subscribed with, and mock the cache by
184
- // calling the callback when the inbound server sets a key in the cache.
185
- const callback = testServer._wsapi._cache.subscribe.mock.calls[0][1];
186
- inboundServer._api._cache.set = jest.fn(async (key) => await callback(
187
- inboundServer._api._cache.EVENT_SET,
188
- key,
189
- 1,
190
- ));
191
- testServer._wsapi._cache.get = jest.fn(() => ({
192
- data: putParticipantsBody,
193
- headers,
194
- }));
195
-
196
- await inboundReq
197
- .put(`/participants/${participantId}`)
198
- .send(putParticipantsBody)
199
- .set(headers);
200
-
201
- expect(inboundServer._api._cache.set).toHaveBeenCalledTimes(1);
202
- expect(inboundServer._api._cache.set).toHaveBeenCalledWith(
203
- `${testServer._wsapi._cache.CALLBACK_PREFIX}${participantId}`,
204
- {
205
- data: putParticipantsBody,
206
- headers: expect.objectContaining(headers),
207
- }
208
- );
209
-
210
- expect(testServer._wsapi._cache.get).toHaveBeenCalledTimes(1);
211
- expect(testServer._wsapi._cache.get).toHaveBeenCalledWith(
212
- `${testServer._wsapi._cache.CALLBACK_PREFIX}${participantId}`
213
- );
214
-
215
- const expectedMessage = {
216
- data: putParticipantsBody,
217
- headers: expect.objectContaining(headers),
218
- id: participantId
219
- };
220
-
221
- // Expect the client websockets to receive a message containing the callback headers and
222
- // body
223
- const callbackClientResult = JSON.parse(await serverCallbackEndpointMessageReceived);
224
- expect(callbackClientResult).toEqual(expectedMessage);
225
- const rootClientResult = JSON.parse(await serverRootEndpointMessageReceived);
226
- expect(rootClientResult).toEqual(expectedMessage);
227
- const putParticipantClientClientResult = JSON.parse(await putParticipantEndpointMessageReceived);
228
- expect(putParticipantClientClientResult).toEqual(expectedMessage);
229
- });
230
-
231
- test('WebSocket /requests and / endpoint triggers send to client when callback received to inbound server', async () => {
232
- const headers = {
233
- ...commonHttpHeaders,
234
- 'content-type': 'application/vnd.interoperability.quotes+json;version=1.1',
235
- 'fspiop-http-method': 'POST',
236
- 'fspiop-uri': '/quotes',
237
- 'date': new Date().toISOString(),
238
- };
239
-
240
- const postQuoteWsClient = await createWsClient(
241
- testServerPort,
242
- `/requests/${postQuotesBody.quoteId}`
243
- );
244
-
245
- const postQuoteEndpointMessageReceived = new Promise(resolve => {
246
- postQuoteWsClient.on('message', resolve);
247
- });
248
- const serverRequestEndpointMessageReceived = new Promise(resolve => {
249
- wsClients.requests.on('message', resolve);
250
- });
251
- const serverRootEndpointMessageReceived = new Promise(resolve => {
252
- wsClients.root.on('message', resolve);
253
- });
254
-
255
- // get the callback function that the test server subscribed with, and mock the cache by
256
- // calling the callback when the inbound server sets a key in the cache.
257
- const callback = testServer._wsapi._cache.subscribe.mock.calls[0][1];
258
- inboundServer._api._cache.set = jest.fn(async (key) => await callback(
259
- inboundServer._api._cache.EVENT_SET,
260
- key,
261
- 1,
262
- ));
263
- testServer._wsapi._cache.get = jest.fn(() => ({
264
- data: postQuotesBody,
265
- headers,
266
- }));
267
-
268
- await inboundReq
269
- .post('/quotes')
270
- .send(postQuotesBody)
271
- .set(headers);
272
-
273
- expect(inboundServer._api._cache.set).toHaveBeenCalledTimes(4);
274
- expect(inboundServer._api._cache.set).toHaveBeenCalledWith(
275
- `${testServer._wsapi._cache.REQUEST_PREFIX}${postQuotesBody.quoteId}`,
276
- {
277
- data: postQuotesBody,
278
- headers: expect.objectContaining(headers),
279
- }
280
- );
281
-
282
- expect(testServer._wsapi._cache.get).toHaveBeenCalledTimes(1);
283
- expect(testServer._wsapi._cache.get).toHaveBeenCalledWith(
284
- `${testServer._wsapi._cache.REQUEST_PREFIX}${postQuotesBody.quoteId}`
285
- );
286
-
287
- const expectedMessage = {
288
- data: postQuotesBody,
289
- headers: expect.objectContaining(headers),
290
- id: postQuotesBody.quoteId,
291
- };
292
-
293
- // Expect the client websockets to receive a message containing the callback headers and
294
- // body
295
- const callbackClientResult = JSON.parse(await serverRequestEndpointMessageReceived);
296
- expect(callbackClientResult).toEqual(expectedMessage);
297
- const rootClientResult = JSON.parse(await serverRootEndpointMessageReceived);
298
- expect(rootClientResult).toEqual(expectedMessage);
299
- const postQuoteClientResult = JSON.parse(await postQuoteEndpointMessageReceived);
300
- expect(postQuoteClientResult).toEqual(expectedMessage);
301
- });
302
-
303
- test('Websocket / endpoint receives both callbacks and requests', async () => {
304
- const quoteRequestHeaders = {
305
- ...commonHttpHeaders,
306
- 'content-type': 'application/vnd.interoperability.quotes+json;version=1.1',
307
- 'fspiop-http-method': 'POST',
308
- 'fspiop-uri': '/quotes',
309
- 'date': new Date().toISOString(),
310
- };
311
-
312
- const serverRootEndpointMessageReceived = new Promise(resolve => {
313
- wsClients.root.on('message', resolve);
314
- });
315
-
316
- // get the callback function that the test server subscribed with, and mock the cache by
317
- // calling the callback when the inbound server sets a key in the cache.
318
- const callback = testServer._wsapi._cache.subscribe.mock.calls[0][1];
319
- inboundServer._api._cache.set = jest.fn(async (key) => await callback(
320
- inboundServer._api._cache.EVENT_SET,
321
- key,
322
- 1,
323
- ));
324
- testServer._wsapi._cache.get = jest.fn(() => ({
325
- data: postQuotesBody,
326
- headers: quoteRequestHeaders,
327
- }));
328
-
329
- await inboundReq
330
- .post('/quotes')
331
- .send(postQuotesBody)
332
- .set(quoteRequestHeaders);
333
-
334
- expect(inboundServer._api._cache.set).toHaveBeenCalledTimes(4);
335
- expect(inboundServer._api._cache.set).toHaveBeenCalledWith(
336
- `${testServer._wsapi._cache.REQUEST_PREFIX}${postQuotesBody.quoteId}`,
337
- {
338
- data: postQuotesBody,
339
- headers: expect.objectContaining(quoteRequestHeaders),
340
- }
341
- );
342
-
343
- expect(testServer._wsapi._cache.get).toHaveBeenCalledTimes(1);
344
- expect(testServer._wsapi._cache.get).toHaveBeenCalledWith(
345
- `${testServer._wsapi._cache.REQUEST_PREFIX}${postQuotesBody.quoteId}`
346
- );
347
-
348
- const expectedMessage = {
349
- data: postQuotesBody,
350
- headers: expect.objectContaining(quoteRequestHeaders),
351
- id: postQuotesBody.quoteId,
352
- };
353
-
354
- // Expect the client websockets to receive a message containing the callback
355
- // quoteRequestHeaders and body
356
- const rootEndpointResult = JSON.parse(await serverRootEndpointMessageReceived);
357
- expect(rootEndpointResult).toEqual(expectedMessage);
358
-
359
- const participantId = '00000000-0000-1000-a000-000000000002';
360
-
361
- const putParticipantsHeaders = {
362
- ...commonHttpHeaders,
363
- 'content-type': 'application/vnd.interoperability.participants+json;version=1.1',
364
- 'fspiop-http-method': 'PUT',
365
- 'fspiop-uri': `/participants/${participantId}`,
366
- 'date': new Date().toISOString(),
367
- };
368
-
369
- await inboundReq
370
- .put(`/participants/${participantId}`)
371
- .send(putParticipantsBody)
372
- .set(putParticipantsHeaders);
373
-
374
- // Called thrice for the quote request earlier in this test, another time now for the put
375
- // participants request
376
- expect(inboundServer._api._cache.set).toHaveBeenCalledTimes(5);
377
- expect(inboundServer._api._cache.set.mock.calls[4]).toEqual([
378
- `${testServer._wsapi._cache.CALLBACK_PREFIX}${participantId}`,
379
- {
380
- data: putParticipantsBody,
381
- headers: expect.objectContaining(putParticipantsHeaders),
382
- }
383
- ]);
384
-
385
- // Called once for the quote request earlier in this test, another time now for the
386
- // participants callback
387
- expect(testServer._wsapi._cache.get).toHaveBeenCalledTimes(2);
388
- expect(testServer._wsapi._cache.get.mock.calls[1]).toEqual([
389
- `${testServer._wsapi._cache.CALLBACK_PREFIX}${participantId}`
390
- ]);
391
- });
392
- });
@@ -1,128 +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 redis = require('redis');
17
- const uuidv4 = require('uuidv4');
18
- const {createValidators, createTestServers, destroyTestServers} = require('../utils');
19
- const {createPostAccountsTester} = require('./utils');
20
-
21
- const defaultConfig = require('../../data/defaultConfig');
22
-
23
- // Accounts
24
- const postAccountsSuccessResponse = require('./data/postAccountsSuccessResponse');
25
- const postAccountsSuccessResponseWithError1 = require('./data/postAccountsSuccessResponseWithError1');
26
- const postAccountsSuccessResponseWithError2 = require('./data/postAccountsSuccessResponseWithError2');
27
- const postAccountsErrorTimeoutResponse = require('./data/postAccountsErrorTimeoutResponse');
28
- const postAccountsErrorMojaloopResponse = require('./data/postAccountsErrorMojaloopResponse');
29
-
30
- describe('Outbound Accounts API', () => {
31
- let testPostAccounts;
32
- let validatorsInfo;
33
- let serversInfo;
34
- let redisClient;
35
-
36
- beforeAll(async () => {
37
- validatorsInfo = await createValidators();
38
- redisClient = redis.createClient(defaultConfig);
39
- });
40
-
41
- beforeEach(async () => {
42
- serversInfo = await createTestServers(defaultConfig);
43
- testPostAccounts = createPostAccountsTester({
44
- reqInbound: serversInfo.reqInbound,
45
- reqOutbound: serversInfo.reqOutbound,
46
- apiSpecsOutbound: validatorsInfo.apiSpecsOutbound,
47
- });
48
- });
49
-
50
- afterEach(async () => {
51
- await destroyTestServers(serversInfo);
52
- });
53
-
54
- afterAll(async () => {
55
- // redisClient.end();
56
- });
57
-
58
- describe('POST /accounts', () => {
59
- beforeEach(() => {
60
- uuidv4.__reset();
61
- redisClient.flushdb();
62
- });
63
-
64
- test('should return success response', () => {
65
- const putBodyFn = (body) => ({
66
- partyList: body.partyList.map(party => ({
67
- partyId: party,
68
- })),
69
- currency: body.currency,
70
- });
71
- return testPostAccounts(putBodyFn, 200,
72
- postAccountsSuccessResponse);
73
- });
74
-
75
- test(
76
- 'should return success response with error info on invalid currency (1)',
77
- () => {
78
- const putBodyFn = (body) => ({
79
- partyList: body.partyList.map(party => ({
80
- partyId: party,
81
- })),
82
- currency: undefined,
83
- });
84
- return testPostAccounts(putBodyFn, 200,
85
- postAccountsSuccessResponseWithError1);
86
- });
87
-
88
- test(
89
- 'should return success response with error info on errorInformation presence (2)',
90
- () => {
91
- const putBodyFn = (body) => ({
92
- partyList: body.partyList.map(party => ({
93
- partyId: party,
94
- errorInformation: {
95
- errorCode: '3204',
96
- errorDescription: 'Party not found',
97
- },
98
- })),
99
- currency: 'USD',
100
- });
101
- return testPostAccounts(putBodyFn, 200,
102
- postAccountsSuccessResponseWithError2);
103
- });
104
-
105
- test('should return timeout error response', () => {
106
- const putBodyFn = (body) => new Promise(
107
- resolve => setTimeout(() => resolve({
108
- partyList: body.partyList.map(party => ({
109
- partyId: party,
110
- })),
111
- currency: body.currency,
112
- }), 3000));
113
- return testPostAccounts(putBodyFn, 504,
114
- postAccountsErrorTimeoutResponse);
115
- });
116
-
117
- test('should return mojaloop error response', () => {
118
- const putBodyFn = () => ({
119
- errorInformation: {
120
- errorCode: '3204',
121
- errorDescription: 'Party not found',
122
- },
123
- });
124
- return testPostAccounts(putBodyFn, 500,
125
- postAccountsErrorMojaloopResponse);
126
- });
127
- });
128
- });
@@ -1,7 +0,0 @@
1
- [
2
- {
3
- "idType": "MSISDN",
4
- "idValue": "123456789",
5
- "currency": "USD"
6
- }
7
- ]
@@ -1,33 +0,0 @@
1
- {
2
- "message": "Got an error response creating accounts: {\n errorInformation: { errorCode: '3204', errorDescription: 'Party not found' }\n}",
3
- "statusCode": "3204",
4
- "executionState": {
5
- "postAccountsResponse": {
6
- "body": {
7
- "errorInformation": {
8
- "errorCode": "3204",
9
- "errorDescription": "Party not found"
10
- }
11
- }
12
- },
13
- "accounts": [
14
- {
15
- "currency": "USD",
16
- "idType": "MSISDN",
17
- "idValue": "123456789"
18
- }
19
- ],
20
- "currentState": "ERROR_OCCURRED",
21
- "lastError": {
22
- "httpStatusCode": 500,
23
- "mojaloopError": {
24
- "errorInformation": {
25
- "errorCode": "3204",
26
- "errorDescription": "Party not found"
27
- }
28
- }
29
- },
30
- "modelId": "00000000-0000-1000-8000-000000000001",
31
- "response": []
32
- }
33
- }
@@ -1,19 +0,0 @@
1
- {
2
- "executionState": {
3
- "accounts": [
4
- {
5
- "currency": "USD",
6
- "idType": "MSISDN",
7
- "idValue": "123456789"
8
- }
9
- ],
10
- "currentState": "ERROR_OCCURRED",
11
- "lastError": {
12
- "httpStatusCode": 504
13
- },
14
- "modelId": "00000000-0000-1000-8000-000000000001",
15
- "response": []
16
- },
17
- "message": "Timeout waiting for response to account creation request 00000000-0000-1000-8000-000000000002",
18
- "statusCode": "504"
19
- }
@@ -1,31 +0,0 @@
1
- {
2
- "accounts": [
3
- {
4
- "currency": "USD",
5
- "idType": "MSISDN",
6
- "idValue": "123456789"
7
- }
8
- ],
9
- "currentState": "COMPLETED",
10
- "modelId": "00000000-0000-1000-8000-000000000001",
11
- "postAccountsResponse": {
12
- "body": {
13
- "currency": "USD",
14
- "partyList": [
15
- {
16
- "partyId": {
17
- "fspId": "mojaloop-sdk",
18
- "partyIdType": "MSISDN",
19
- "partyIdentifier": "123456789"
20
- }
21
- }
22
- ]
23
- }
24
- },
25
- "response": [
26
- {
27
- "idType": "MSISDN",
28
- "idValue": "123456789"
29
- }
30
- ]
31
- }
@@ -1,34 +0,0 @@
1
- {
2
- "accounts": [
3
- {
4
- "currency": "USD",
5
- "idType": "MSISDN",
6
- "idValue": "123456789"
7
- }
8
- ],
9
- "currentState": "COMPLETED",
10
- "modelId": "00000000-0000-1000-8000-000000000001",
11
- "postAccountsResponse": {
12
- "body": {
13
- "partyList": [
14
- {
15
- "partyId": {
16
- "fspId": "mojaloop-sdk",
17
- "partyIdType": "MSISDN",
18
- "partyIdentifier": "123456789"
19
- }
20
- }
21
- ]
22
- }
23
- },
24
- "response": [
25
- {
26
- "error": {
27
- "message": "Provided currency not supported",
28
- "statusCode": "3000"
29
- },
30
- "idType": "MSISDN",
31
- "idValue": "123456789"
32
- }
33
- ]
34
- }
@@ -1,39 +0,0 @@
1
- {
2
- "accounts": [
3
- {
4
- "currency": "USD",
5
- "idType": "MSISDN",
6
- "idValue": "123456789"
7
- }
8
- ],
9
- "currentState": "COMPLETED",
10
- "modelId": "00000000-0000-1000-8000-000000000001",
11
- "postAccountsResponse": {
12
- "body": {
13
- "currency": "USD",
14
- "partyList": [
15
- {
16
- "errorInformation": {
17
- "errorCode": "3204",
18
- "errorDescription": "Party not found"
19
- },
20
- "partyId": {
21
- "fspId": "mojaloop-sdk",
22
- "partyIdType": "MSISDN",
23
- "partyIdentifier": "123456789"
24
- }
25
- }
26
- ]
27
- }
28
- },
29
- "response": [
30
- {
31
- "error": {
32
- "message": "Party not found",
33
- "statusCode": "3204"
34
- },
35
- "idType": "MSISDN",
36
- "idValue": "123456789"
37
- }
38
- ]
39
- }