@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.
Files changed (119) hide show
  1. package/.dockerignore +18 -0
  2. package/.eslintignore +2 -0
  3. package/.ncurc.yaml +7 -0
  4. package/CHANGELOG.md +20 -0
  5. package/CODEOWNERS +31 -1
  6. package/README.md +1 -0
  7. package/audit-resolve.json +35 -0
  8. package/package.json +13 -13
  9. package/test/__mocks__/@mojaloop/sdk-standard-components.js +0 -151
  10. package/test/__mocks__/javascript-state-machine.js +0 -21
  11. package/test/__mocks__/redis.js +0 -78
  12. package/test/__mocks__/uuidv4.js +0 -16
  13. package/test/config/integration.env +0 -146
  14. package/test/integration/lib/Outbound/data/quotesPostRequest.json +0 -52
  15. package/test/integration/lib/Outbound/data/transfersPostRequest.json +0 -24
  16. package/test/integration/lib/Outbound/parties.test.js +0 -31
  17. package/test/integration/lib/Outbound/quotes.test.js +0 -62
  18. package/test/integration/lib/Outbound/simpleTransfers.test.js +0 -70
  19. package/test/integration/lib/cache.test.js +0 -79
  20. package/test/integration/testEnv.js +0 -4
  21. package/test/unit/ControlClient.test.js +0 -69
  22. package/test/unit/ControlServer/events.js +0 -41
  23. package/test/unit/ControlServer/index.js +0 -227
  24. package/test/unit/ControlServer.test.js +0 -66
  25. package/test/unit/InboundServer.test.js +0 -443
  26. package/test/unit/TestServer.test.js +0 -392
  27. package/test/unit/api/accounts/accounts.test.js +0 -128
  28. package/test/unit/api/accounts/data/postAccountsBody.json +0 -7
  29. package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +0 -33
  30. package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +0 -19
  31. package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +0 -31
  32. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +0 -34
  33. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +0 -39
  34. package/test/unit/api/accounts/utils.js +0 -79
  35. package/test/unit/api/proxy/data/proxyConfig.yaml +0 -82
  36. package/test/unit/api/proxy/data/requestBody.json +0 -22
  37. package/test/unit/api/proxy/data/requestHeaders.json +0 -5
  38. package/test/unit/api/proxy/data/requestQuery.json +0 -6
  39. package/test/unit/api/proxy/data/responseBody.json +0 -21
  40. package/test/unit/api/proxy/data/responseHeaders.json +0 -5
  41. package/test/unit/api/proxy/proxy.test.js +0 -220
  42. package/test/unit/api/proxy/utils.js +0 -79
  43. package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +0 -24
  44. package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +0 -18
  45. package/test/unit/api/transfers/data/postQuotesBody.json +0 -52
  46. package/test/unit/api/transfers/data/postTransfersBadBody.json +0 -17
  47. package/test/unit/api/transfers/data/postTransfersBody.json +0 -24
  48. package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +0 -62
  49. package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +0 -48
  50. package/test/unit/api/transfers/data/postTransfersSimpleBody.json +0 -26
  51. package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +0 -128
  52. package/test/unit/api/transfers/data/putPartiesBody.json +0 -20
  53. package/test/unit/api/transfers/data/putQuotesBody.json +0 -37
  54. package/test/unit/api/transfers/data/putTransfersBody.json +0 -17
  55. package/test/unit/api/transfers/transfers.test.js +0 -191
  56. package/test/unit/api/transfers/utils.js +0 -264
  57. package/test/unit/api/utils.js +0 -86
  58. package/test/unit/config.test.js +0 -119
  59. package/test/unit/data/commonHttpHeaders.json +0 -7
  60. package/test/unit/data/defaultConfig.json +0 -70
  61. package/test/unit/data/postQuotesBody.json +0 -52
  62. package/test/unit/data/putParticipantsBody.json +0 -12
  63. package/test/unit/data/putPartiesBody.json +0 -20
  64. package/test/unit/data/testFile.json +0 -29
  65. package/test/unit/data/testFile.yaml +0 -14
  66. package/test/unit/inboundApi/data/mockArguments.json +0 -117
  67. package/test/unit/inboundApi/data/mockTransactionRequest.json +0 -42
  68. package/test/unit/inboundApi/handlers.test.js +0 -786
  69. package/test/unit/index.test.js +0 -88
  70. package/test/unit/lib/cache.test.js +0 -145
  71. package/test/unit/lib/model/AccountsModel.test.js +0 -124
  72. package/test/unit/lib/model/InboundTransfersModel.test.js +0 -889
  73. package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +0 -253
  74. package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +0 -247
  75. package/test/unit/lib/model/OutboundRequestToPayModel.test.js +0 -166
  76. package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +0 -245
  77. package/test/unit/lib/model/OutboundTransfersModel.test.js +0 -1579
  78. package/test/unit/lib/model/PartiesModel.test.js +0 -478
  79. package/test/unit/lib/model/QuotesModel.test.js +0 -477
  80. package/test/unit/lib/model/TransfersModel.test.js +0 -481
  81. package/test/unit/lib/model/common/PersistentStateMachine.test.js +0 -178
  82. package/test/unit/lib/model/data/authorizationsResponse.json +0 -13
  83. package/test/unit/lib/model/data/bulkQuoteRequest.json +0 -27
  84. package/test/unit/lib/model/data/bulkQuoteResponse.json +0 -35
  85. package/test/unit/lib/model/data/bulkTransferFulfil.json +0 -13
  86. package/test/unit/lib/model/data/bulkTransferRequest.json +0 -29
  87. package/test/unit/lib/model/data/defaultConfig.json +0 -59
  88. package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +0 -42
  89. package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +0 -22
  90. package/test/unit/lib/model/data/getTransfersBackendResponse.json +0 -34
  91. package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +0 -17
  92. package/test/unit/lib/model/data/mockArguments.json +0 -188
  93. package/test/unit/lib/model/data/mockTxnRequestsArguments.json +0 -63
  94. package/test/unit/lib/model/data/notificationAbortedToPayee.json +0 -10
  95. package/test/unit/lib/model/data/notificationReservedToPayee.json +0 -10
  96. package/test/unit/lib/model/data/notificationToPayee.json +0 -10
  97. package/test/unit/lib/model/data/payeeParty.json +0 -18
  98. package/test/unit/lib/model/data/putQuotesResponse.json +0 -33
  99. package/test/unit/lib/model/data/putTransfersResponse.json +0 -5
  100. package/test/unit/lib/model/data/quoteResponse.json +0 -42
  101. package/test/unit/lib/model/data/requestToPayRequest.json +0 -20
  102. package/test/unit/lib/model/data/requestToPayTransferRequest.json +0 -27
  103. package/test/unit/lib/model/data/transactionRequestResponse.json +0 -18
  104. package/test/unit/lib/model/data/transferFulfil.json +0 -10
  105. package/test/unit/lib/model/data/transferRequest.json +0 -26
  106. package/test/unit/lib/model/mockedLibRequests.js +0 -74
  107. package/test/unit/mockLogger.js +0 -39
  108. package/test/unit/outboundApi/data/bulkQuoteRequest.json +0 -28
  109. package/test/unit/outboundApi/data/bulkTransferRequest.json +0 -28
  110. package/test/unit/outboundApi/data/mockBulkQuoteError.json +0 -45
  111. package/test/unit/outboundApi/data/mockBulkTransferError.json +0 -48
  112. package/test/unit/outboundApi/data/mockError.json +0 -41
  113. package/test/unit/outboundApi/data/mockGetPartiesError.json +0 -4
  114. package/test/unit/outboundApi/data/mockRequestToPayError.json +0 -32
  115. package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +0 -39
  116. package/test/unit/outboundApi/data/requestToPay.json +0 -21
  117. package/test/unit/outboundApi/data/requestToPayTransferRequest.json +0 -20
  118. package/test/unit/outboundApi/data/transferRequest.json +0 -21
  119. package/test/unit/outboundApi/handlers.test.js +0 -887
@@ -1,887 +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 mockError = require('./data/mockError');
14
- const mockBulkQuoteError = require('./data/mockBulkQuoteError');
15
- const mockBulkTransferError = require('./data/mockBulkTransferError');
16
- const mockRequestToPayError = require('./data/mockRequestToPayError');
17
- const mockRequestToPayTransferError = require('./data/mockRequestToPayTransferError');
18
- const mockGetPartiesError = require('./data/mockGetPartiesError');
19
- const transferRequest = require('./data/transferRequest');
20
- const bulkTransferRequest = require('./data/bulkTransferRequest');
21
- const bulkQuoteRequest = require('./data/bulkQuoteRequest');
22
- const requestToPayPayload = require('./data/requestToPay');
23
- const requestToPayTransferRequest = require('./data/requestToPayTransferRequest');
24
- const mockLogger = require('../mockLogger');
25
- const { uuid } = require('uuidv4');
26
-
27
- jest.mock('~/lib/model');
28
-
29
- const handlers = require('~/OutboundServer/handlers');
30
- const {
31
- OutboundTransfersModel,
32
- OutboundBulkTransfersModel,
33
- OutboundBulkQuotesModel,
34
- OutboundRequestToPayTransferModel,
35
- OutboundRequestToPayModel,
36
- PartiesModel,
37
- QuotesModel,
38
- TransfersModel
39
- } = require('~/lib/model');
40
-
41
- /**
42
- * Mock the outbound transfer model to simulate throwing errors
43
- */
44
- OutboundTransfersModel.mockImplementation(() => {
45
- return {
46
- run: async () => {
47
- // throw the mockError object when the model is run
48
- throw mockError;
49
- },
50
- initialize: async () => {
51
- // nothing needed here
52
- return;
53
- },
54
- load: async () => {
55
- // nothing needed here
56
- return;
57
- }
58
- };
59
- });
60
-
61
- /**
62
- * Mock the outbound bulk transfers model to simulate throwing errors
63
- */
64
- OutboundBulkTransfersModel.mockImplementation(() => {
65
- return {
66
- run: async () => {
67
- throw mockBulkTransferError;
68
- },
69
- initialize: async () => {
70
- return;
71
- },
72
- load: async () => {
73
- return;
74
- }
75
- };
76
- });
77
-
78
- /**
79
- * Mock the outbound bulk quotes model to simulate throwing errors
80
- */
81
- OutboundBulkQuotesModel.mockImplementation(() => {
82
- return {
83
- run: async () => {
84
- throw mockBulkQuoteError;
85
- },
86
- initialize: async () => {
87
- return;
88
- },
89
- load: async () => {
90
- return;
91
- }
92
- };
93
- });
94
-
95
- /**
96
- * Mock the outbound transfer model to simulate throwing errors
97
- */
98
- OutboundRequestToPayTransferModel.mockImplementation(() => {
99
- return {
100
- run: async () => {
101
- // throw the mockError object when the model is run
102
- throw mockRequestToPayTransferError;
103
- },
104
- initialize: async () => {
105
- // nothing needed here
106
- return;
107
- },
108
- load: async () => {
109
- // nothing needed here
110
- return;
111
- }
112
- };
113
- });
114
-
115
- /**
116
- * Mock the outbound request to pay model to simulate throwing errors
117
- */
118
- OutboundRequestToPayModel.mockImplementation(() => {
119
- return {
120
- run: async () => {
121
- // throw the mockError object when the model is run
122
- throw mockRequestToPayError;
123
- },
124
- initialize: async () => {
125
- // nothing needed here
126
- return;
127
- },
128
- load: async () => {
129
- // nothing needed here
130
- return;
131
- }
132
- };
133
- });
134
-
135
-
136
- describe('Outbound API handlers:', () => {
137
- describe('POST /transfers', () => {
138
- test('returns correct error response body when model throws mojaloop error', async () => {
139
- const mockContext = {
140
- request: {
141
- body: transferRequest,
142
- headers: {
143
- 'fspiop-source': 'foo'
144
- }
145
- },
146
- response: {},
147
- state: {
148
- conf: {},
149
- logger: { log: () => {} },
150
- }
151
- };
152
-
153
- await handlers['/transfers'].post(mockContext);
154
-
155
- // check response is correct
156
- expect(mockContext.response.status).toEqual(500);
157
- expect(mockContext.response.body).toBeTruthy();
158
- expect(mockContext.response.body.message).toEqual('Mock error');
159
- expect(mockContext.response.body.statusCode)
160
- .toEqual(mockError.transferState.lastError.mojaloopError.errorInformation.errorCode);
161
- expect(mockContext.response.body.transferState).toEqual(mockError.transferState);
162
- });
163
-
164
- test('uses correct extension list error code for response body statusCode when configured to do so', async () => {
165
- const mockContext = {
166
- request: {
167
- body: transferRequest,
168
- headers: {
169
- 'fspiop-source': 'foo'
170
- }
171
- },
172
- response: {},
173
- state: {
174
- conf: {
175
- outboundErrorStatusCodeExtensionKey: 'extErrorKey' // <- tell the handler to use this extensionList item as source of statusCode
176
- },
177
- logger: { log: () => {} },
178
- }
179
- };
180
-
181
- await handlers['/transfers'].post(mockContext);
182
-
183
- // check response is correct
184
- expect(mockContext.response.status).toEqual(500);
185
- expect(mockContext.response.body).toBeTruthy();
186
- expect(mockContext.response.body.message).toEqual('Mock error');
187
-
188
- // in this case, where we have set outboundErrorExtensionKey config we expect the error body statusCode
189
- // property to come from the extensionList item with the corresponding key 'extErrorKey'
190
- expect(mockContext.response.body.statusCode).toEqual('9999');
191
- expect(mockContext.response.body.transferState).toEqual(mockError.transferState);
192
- });
193
- });
194
-
195
- describe('PUT /transfers', () => {
196
- test('returns correct error response body when model throws mojaloop error', async () => {
197
- const mockContext = {
198
- request: {
199
- body: {
200
- acceptQuote: true
201
- },
202
- headers: {
203
- 'fspiop-source': 'foo'
204
- }
205
- },
206
- response: {},
207
- state: {
208
- conf: {},
209
- logger: { log: () => {} },
210
- path: {
211
- params: {
212
- transferId: '12345'
213
- }
214
- }
215
- }
216
- };
217
-
218
- await handlers['/transfers/{transferId}'].put(mockContext);
219
-
220
- // check response is correct
221
- expect(mockContext.response.status).toEqual(500);
222
- expect(mockContext.response.body).toBeTruthy();
223
- expect(mockContext.response.body.message).toEqual('Mock error');
224
- expect(mockContext.response.body.statusCode).toEqual('3204');
225
- expect(mockContext.response.body.transferState).toEqual(mockError.transferState);
226
- });
227
- });
228
-
229
- describe('POST /bulkTransfers', () => {
230
- test('returns correct error response body when model throws mojaloop error', async () => {
231
- const mockContext = {
232
- request: {
233
- body: bulkTransferRequest,
234
- headers: {
235
- 'fspiop-source': 'foo'
236
- }
237
- },
238
- response: {},
239
- state: {
240
- conf: {},
241
- logger: { log: () => {} },
242
- }
243
- };
244
-
245
- await handlers['/bulkTransfers'].post(mockContext);
246
-
247
- // check response is correct
248
- expect(mockContext.response.status).toEqual(500);
249
- expect(mockContext.response.body).toBeTruthy();
250
- expect(mockContext.response.body.message).toEqual('Mock error');
251
- expect(mockContext.response.body.statusCode)
252
- .toEqual(mockBulkTransferError.bulkTransferState.lastError.mojaloopError.errorInformation.errorCode);
253
- expect(mockContext.response.body.bulkTransferState).toEqual(mockBulkTransferError.bulkTransferState);
254
- });
255
-
256
- test('uses correct extension list error code for response body statusCode when configured to do so', async () => {
257
- const mockContext = {
258
- request: {
259
- body: bulkTransferRequest,
260
- headers: {
261
- 'fspiop-source': 'foo'
262
- }
263
- },
264
- response: {},
265
- state: {
266
- conf: {
267
- outboundErrorStatusCodeExtensionKey: 'extErrorKey' // <- tell the handler to use this extensionList item as source of statusCode
268
- },
269
- logger: { log: () => {} },
270
- }
271
- };
272
-
273
- await handlers['/bulkTransfers'].post(mockContext);
274
-
275
- // check response is correct
276
- expect(mockContext.response.status).toEqual(500);
277
- expect(mockContext.response.body).toBeTruthy();
278
- expect(mockContext.response.body.message).toEqual('Mock error');
279
-
280
- // in this case, where we have set outboundErrorExtensionKey config we expect the error body statusCode
281
- // property to come from the extensionList item with the corresponding key 'extErrorKey'
282
- expect(mockContext.response.body.statusCode).toEqual('9999');
283
- expect(mockContext.response.body.bulkTransferState).toEqual(mockBulkTransferError.bulkTransferState);
284
- });
285
- });
286
-
287
- describe('POST /bulkQuotes', () => {
288
- test('returns correct error response body when model throws mojaloop error', async () => {
289
- const mockContext = {
290
- request: {
291
- body: bulkQuoteRequest,
292
- headers: {
293
- 'fspiop-source': 'foo'
294
- }
295
- },
296
- response: {},
297
- state: {
298
- conf: {},
299
- logger: { log: () => {} },
300
- }
301
- };
302
-
303
- await handlers['/bulkQuotes'].post(mockContext);
304
-
305
- // check response is correct
306
- expect(mockContext.response.status).toEqual(500);
307
- expect(mockContext.response.body).toBeTruthy();
308
- expect(mockContext.response.body.message).toEqual('Mock error');
309
- expect(mockContext.response.body.statusCode)
310
- .toEqual(mockBulkQuoteError.bulkQuoteState.lastError.mojaloopError.errorInformation.errorCode);
311
- expect(mockContext.response.body.bulkQuoteState).toEqual(mockBulkQuoteError.bulkQuoteState);
312
- });
313
-
314
- test('uses correct extension list error code for response body statusCode when configured to do so', async () => {
315
- const mockContext = {
316
- request: {
317
- body: bulkQuoteRequest,
318
- headers: {
319
- 'fspiop-source': 'foo'
320
- }
321
- },
322
- response: {},
323
- state: {
324
- conf: {
325
- outboundErrorStatusCodeExtensionKey: 'extErrorKey' // <- tell the handler to use this extensionList item as source of statusCode
326
- },
327
- logger: { log: () => {} },
328
- }
329
- };
330
-
331
- await handlers['/bulkQuotes'].post(mockContext);
332
-
333
- // check response is correct
334
- expect(mockContext.response.status).toEqual(500);
335
- expect(mockContext.response.body).toBeTruthy();
336
- expect(mockContext.response.body.message).toEqual('Mock error');
337
-
338
- // in this case, where we have set outboundErrorExtensionKey config we expect the error body statusCode
339
- // property to come from the extensionList item with the corresponding key 'extErrorKey'
340
- expect(mockContext.response.body.statusCode).toEqual('9999');
341
- expect(mockContext.response.body.bulkQuoteState).toEqual(mockBulkQuoteError.bulkQuoteState);
342
- });
343
- });
344
-
345
- describe('POST /requestToPayTransfer', () => {
346
- test('returns correct error response body when model throws mojaloop error', async () => {
347
- const mockContext = {
348
- request: {
349
- body: requestToPayTransferRequest,
350
- headers: {
351
- 'fspiop-source': 'foo'
352
- }
353
- },
354
- response: {},
355
- state: {
356
- conf: {},
357
- logger: { log: () => {} },
358
- }
359
- };
360
-
361
- await handlers['/requestToPayTransfer'].post(mockContext);
362
- // check response is correct
363
- expect(mockContext.response.status).toEqual(500);
364
- expect(mockContext.response.body).toBeTruthy();
365
- expect(mockContext.response.body.message).toEqual('Mock error');
366
- expect(mockContext.response.body.statusCode)
367
- .toEqual(mockRequestToPayTransferError.requestToPayTransferState.lastError.mojaloopError.errorInformation.errorCode);
368
- expect(mockContext.response.body.requestToPayTransferState).toEqual(mockRequestToPayTransferError.requestToPayTransferState);
369
- });
370
- });
371
-
372
- describe('POST /requestToPay', () => {
373
- test('returns correct error response body when model throws mojaloop error', async () => {
374
- const mockContext = {
375
- request: {
376
- body: requestToPayPayload,
377
- headers: {
378
- 'fspiop-source': 'foo'
379
- }
380
- },
381
- response: {},
382
- state: {
383
- conf: {},
384
- logger: { log: () => {} }
385
- }
386
- };
387
-
388
- await handlers['/requestToPay'].post(mockContext);
389
-
390
- // check response is correct
391
- expect(mockContext.response.status).toEqual(500);
392
- expect(mockContext.response.body).toBeTruthy();
393
- expect(mockContext.response.body.message).toEqual('Mock error');
394
- expect(mockContext.response.body.statusCode).toEqual('3204');
395
- expect(mockContext.response.body.requestToPayState).toEqual(mockRequestToPayError.requestToPayState);
396
- });
397
- });
398
-
399
- describe('GET /parties/{Type}/{ID}/{SubId}', () => {
400
- test('happy flow', async() => {
401
-
402
- const mockContext = {
403
- request: {},
404
- response: {},
405
- state: {
406
- conf: {},
407
- wso2Auth: 'mocked wso2Auth',
408
- logger: mockLogger({ app: 'outbound-api-handlers-test'}),
409
- cache: { the: 'mocked cache' },
410
- path: {
411
- params: {
412
- 'Type': 'MSISDN',
413
- 'ID': '1234567890',
414
- 'SubId': 'abcdefgh'
415
- },
416
- },
417
- },
418
- };
419
-
420
- // mock state machine
421
- const mockedPSM = {
422
- run: jest.fn(async () => ({ the: 'run response' }))
423
- };
424
-
425
- const createSpy = jest.spyOn(PartiesModel, 'create')
426
- .mockImplementationOnce(async () => mockedPSM);
427
-
428
- // invoke handler
429
- await handlers['/parties/{Type}/{ID}/{SubId}'].get(mockContext);
430
-
431
- // PSM model creation
432
- const state = mockContext.state;
433
- const cacheKey = PartiesModel.channelName({
434
- type: 'MSISDN',
435
- id: '1234567890',
436
- subId: 'abcdefgh'
437
- });
438
- const expectedConfig = {
439
- cache: state.cache,
440
- logger: state.logger,
441
- wso2Auth: state.wso2Auth
442
- };
443
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
444
-
445
- // run workflow
446
- expect(mockedPSM.run).toBeCalledWith({
447
- type: 'MSISDN',
448
- id: '1234567890',
449
- subId: 'abcdefgh'
450
- });
451
-
452
- // response
453
- expect(mockContext.response.status).toBe(200);
454
- expect(mockContext.response.body).toEqual({ the: 'run response' });
455
- });
456
-
457
- test('error flow', async() => {
458
- const mockContext = {
459
- request: {},
460
- response: {},
461
- state: {
462
- conf: {},
463
- wso2Auth: 'mocked wso2Auth',
464
- logger: mockLogger({ app: 'outbound-api-handlers-test'}),
465
- cache: { the: 'mocked cache' },
466
- path: {
467
- params: {
468
- 'Type': 'MSISDN',
469
- 'ID': '1234567890',
470
- 'SubId': 'abcdefgh'
471
- },
472
- },
473
- },
474
- };
475
-
476
- // mock state machine
477
- const mockedPSM = {
478
- run: jest.fn(async () => ({ errorInformation: { Iam: 'the-error'} }))
479
- };
480
-
481
- const createSpy = jest.spyOn(PartiesModel, 'create')
482
- .mockImplementationOnce(async () => mockedPSM);
483
-
484
- // invoke handler
485
- await handlers['/parties/{Type}/{ID}/{SubId}'].get(mockContext);
486
-
487
- // PSM model creation
488
- const state = mockContext.state;
489
- const cacheKey = PartiesModel.channelName({
490
- type: 'MSISDN',
491
- id: '1234567890',
492
- subId: 'abcdefgh'
493
- });
494
- const expectedConfig = {
495
- cache: state.cache,
496
- logger: state.logger,
497
- wso2Auth: state.wso2Auth
498
- };
499
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
500
-
501
- // run workflow
502
- expect(mockedPSM.run).toBeCalledWith({
503
- type: 'MSISDN',
504
- id: '1234567890',
505
- subId: 'abcdefgh'
506
- });
507
-
508
- // response
509
- expect(mockContext.response.status).toBe(404);
510
- expect(mockContext.response.body).toEqual({ errorInformation: { Iam: 'the-error'} });
511
- });
512
- });
513
- describe('GET /parties/{Type}/{ID}', () => {
514
- const mockContext = {
515
- request: {},
516
- response: {},
517
- state: {
518
- conf: {},
519
- wso2Auth: 'mocked wso2Auth',
520
- logger: mockLogger({ app: 'outbound-api-handlers-test'}),
521
- cache: {
522
- subscribe: jest.fn(() => Promise.resolve())
523
- },
524
- path: {
525
- params: {
526
- 'Type': 'MSISDN',
527
- 'ID': '1234567890'
528
- },
529
- },
530
- },
531
- };
532
- test('happy flow', async() => {
533
-
534
-
535
- // mock state machine
536
- const mockedPSM = {
537
- run: jest.fn(async () => ({ the: 'run response' }))
538
- };
539
-
540
- const createSpy = jest.spyOn(PartiesModel, 'create')
541
- .mockImplementationOnce(async () => mockedPSM);
542
-
543
- // invoke handler
544
- await handlers['/parties/{Type}/{ID}'].get(mockContext);
545
-
546
- // PSM model creation
547
- const state = mockContext.state;
548
- const cacheKey = PartiesModel.channelName({
549
- type: 'MSISDN',
550
- id: '1234567890'
551
- });
552
- const expectedConfig = {
553
- cache: state.cache,
554
- logger: state.logger,
555
- wso2Auth: state.wso2Auth
556
- };
557
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
558
-
559
- // run workflow
560
- expect(mockedPSM.run).toBeCalledWith({ type: 'MSISDN', id: '1234567890', subId: undefined });
561
-
562
- // response
563
- expect(mockContext.response.status).toBe(200);
564
- expect(mockContext.response.body).toEqual({ the: 'run response' });
565
- });
566
-
567
- test('not found error flow', async() => {
568
-
569
- // mock state machine
570
- const mockedPSM = {
571
- run: jest.fn(async () => ({ errorInformation: { Iam: 'the-error'} }))
572
- };
573
-
574
- const createSpy = jest.spyOn(PartiesModel, 'create')
575
- .mockImplementationOnce(async () => mockedPSM);
576
-
577
- // invoke handler
578
- await handlers['/parties/{Type}/{ID}'].get(mockContext);
579
-
580
- // PSM model creation
581
- const state = mockContext.state;
582
- const cacheKey = PartiesModel.channelName({
583
- type: 'MSISDN',
584
- id: '1234567890'
585
- });
586
- const expectedConfig = {
587
- cache: state.cache,
588
- logger: state.logger,
589
- wso2Auth: state.wso2Auth
590
- };
591
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
592
-
593
- // run workflow
594
- expect(mockedPSM.run).toBeCalledWith({
595
- type: 'MSISDN',
596
- id: '1234567890',
597
- subId: undefined
598
- });
599
-
600
- // response
601
- expect(mockContext.response.status).toBe(404);
602
- expect(mockContext.response.body).toEqual({ errorInformation: { Iam: 'the-error'} });
603
- });
604
-
605
- test('mojaloop error propagation for /parties/{Type}/{ID}', async() => {
606
-
607
- // mock state machine
608
- const mockedPSM = {
609
- run: jest.fn(async () => { throw mockGetPartiesError; })
610
- };
611
-
612
- const createSpy = jest.spyOn(PartiesModel, 'create')
613
- .mockImplementationOnce(async () => mockedPSM);
614
-
615
- // invoke handler
616
- await handlers['/parties/{Type}/{ID}'].get(mockContext);
617
-
618
- // PSM model creation
619
- const state = mockContext.state;
620
- const cacheKey = PartiesModel.channelName({
621
- type: 'MSISDN',
622
- id: '1234567890'
623
- });
624
- const expectedConfig = {
625
- cache: state.cache,
626
- logger: state.logger,
627
- wso2Auth: state.wso2Auth
628
- };
629
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
630
-
631
- // run workflow
632
- expect(mockedPSM.run).toBeCalledWith({
633
- type: 'MSISDN',
634
- id: '1234567890',
635
- subId: undefined
636
- });
637
-
638
- // response
639
- expect(mockContext.response.status).toBe(500);
640
- expect(mockContext.response.body).toEqual({
641
- message: 'Mock error',
642
- statusCode: '500',
643
- requestPartiesInformationState: {}
644
- });
645
- });
646
- test('mojaloop error propagation for /parties/{Type}/{ID}/{SubId}', async() => {
647
-
648
- // mock state machine
649
- const mockedPSM = {
650
- run: jest.fn(async () => { throw mockGetPartiesError; })
651
- };
652
-
653
- const createSpy = jest.spyOn(PartiesModel, 'create')
654
- .mockImplementationOnce(async () => mockedPSM);
655
-
656
- // invoke handler
657
- await handlers['/parties/{Type}/{ID}/{SubId}'].get(mockContext);
658
-
659
- // PSM model creation
660
- const state = mockContext.state;
661
- const cacheKey = PartiesModel.channelName({
662
- type: 'MSISDN',
663
- id: '1234567890'
664
- });
665
- const expectedConfig = {
666
- cache: state.cache,
667
- logger: state.logger,
668
- wso2Auth: state.wso2Auth
669
- };
670
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
671
-
672
- // run workflow
673
- expect(mockedPSM.run).toBeCalledWith({
674
- type: 'MSISDN',
675
- id: '1234567890',
676
- subId: undefined
677
- });
678
-
679
- // response
680
- expect(mockContext.response.status).toBe(500);
681
- expect(mockContext.response.body).toEqual({
682
- message: 'Mock error',
683
- statusCode: '500',
684
- requestPartiesInformationState: {}
685
- });
686
- });
687
- });
688
-
689
- describe('POST /quotes', () => {
690
- const mockContext = {
691
- request: {
692
- body: {
693
- fspId: uuid(),
694
- quotesPostRequest: {
695
- quoteId: uuid()
696
- }
697
- }
698
- },
699
- response: {},
700
- state: {
701
- conf: {},
702
- wso2Auth: 'mocked wso2Auth',
703
- logger: mockLogger({ app: 'outbound-api-handlers-test' }),
704
- cache: {
705
- subscribe: jest.fn(() => Promise.resolve())
706
- }
707
- },
708
- };
709
- test('happy flow', async () => {
710
-
711
-
712
- // mock state machine
713
- const mockedPSM = {
714
- run: jest.fn(async () => ({ the: 'run response' }))
715
- };
716
-
717
- const createSpy = jest.spyOn(QuotesModel, 'create')
718
- .mockImplementationOnce(async () => mockedPSM);
719
-
720
- // invoke handler
721
- await handlers['/quotes'].post(mockContext);
722
-
723
- // PSM model creation
724
- const state = mockContext.state;
725
- const cacheKey = QuotesModel.channelName({
726
- quoteId: mockContext.request.body.quotesPostRequest.quoteId
727
- });
728
- const expectedConfig = {
729
- cache: state.cache,
730
- logger: state.logger,
731
- wso2Auth: state.wso2Auth
732
- };
733
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
734
-
735
- // run workflow
736
- expect(mockedPSM.run).toBeCalledWith({
737
- quoteId: mockContext.request.body.quotesPostRequest.quoteId,
738
- fspId: mockContext.request.body.fspId,
739
- quote: mockContext.request.body.quotesPostRequest
740
- });
741
-
742
- // response
743
- expect(mockContext.response.status).toBe(200);
744
- expect(mockContext.response.body).toEqual({ the: 'run response' });
745
- });
746
-
747
- test('mojaloop error propagation for /parties/{Type}/{ID}', async() => {
748
-
749
- // mock state machine
750
- const mockedPSM = {
751
- run: jest.fn(async () => { throw { mocked: 'error' }; })
752
- };
753
-
754
- const createSpy = jest.spyOn(QuotesModel, 'create')
755
- .mockImplementationOnce(async () => mockedPSM);
756
-
757
- // invoke handler
758
- await handlers['/quotes'].post(mockContext);
759
-
760
- // PSM model creation
761
- const state = mockContext.state;
762
- const cacheKey = QuotesModel.channelName({
763
- quoteId: mockContext.request.body.quotesPostRequest.quoteId
764
- });
765
- const expectedConfig = {
766
- cache: state.cache,
767
- logger: state.logger,
768
- wso2Auth: state.wso2Auth
769
- };
770
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
771
-
772
- // run workflow
773
- expect(mockedPSM.run).toBeCalledWith({
774
- quoteId: mockContext.request.body.quotesPostRequest.quoteId,
775
- fspId: mockContext.request.body.fspId,
776
- quote: mockContext.request.body.quotesPostRequest
777
- });
778
-
779
- // response
780
- expect(mockContext.response.status).toBe(500);
781
- expect(mockContext.response.body).toEqual({
782
- message: 'Unspecified error',
783
- requestQuotesInformationState: {},
784
- statusCode: '500',
785
- });
786
- });
787
- });
788
- describe('POST /simpleTransfers', () => {
789
- const mockContext = {
790
- request: {
791
- body: {
792
- fspId: uuid(),
793
- transfersPostRequest: {
794
- transferId: uuid()
795
- }
796
- }
797
- },
798
- response: {},
799
- state: {
800
- conf: {},
801
- wso2Auth: 'mocked wso2Auth',
802
- logger: mockLogger({ app: 'outbound-api-handlers-test' }),
803
- cache: {
804
- subscribe: jest.fn(() => Promise.resolve())
805
- }
806
- },
807
- };
808
- test('happy flow', async () => {
809
-
810
-
811
- // mock state machine
812
- const mockedPSM = {
813
- run: jest.fn(async () => ({ the: 'run response' }))
814
- };
815
-
816
- const createSpy = jest.spyOn(TransfersModel, 'create')
817
- .mockImplementationOnce(async () => mockedPSM);
818
-
819
- // invoke handler
820
- await handlers['/simpleTransfers'].post(mockContext);
821
-
822
- // PSM model creation
823
- const state = mockContext.state;
824
- const cacheKey = TransfersModel.channelName({
825
- transferId: mockContext.request.body.transfersPostRequest.transferId
826
- });
827
- const expectedConfig = {
828
- cache: state.cache,
829
- logger: state.logger,
830
- wso2Auth: state.wso2Auth
831
- };
832
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
833
-
834
- // run workflow
835
- expect(mockedPSM.run).toBeCalledWith({
836
- transferId: mockContext.request.body.transfersPostRequest.transferId,
837
- fspId: mockContext.request.body.fspId,
838
- transfer: mockContext.request.body.transfersPostRequest
839
- });
840
-
841
- // response
842
- expect(mockContext.response.status).toBe(200);
843
- expect(mockContext.response.body).toEqual({ the: 'run response' });
844
- });
845
-
846
- test('mojaloop error propagation for /simpleTransfers', async() => {
847
-
848
- // mock state machine
849
- const mockedPSM = {
850
- run: jest.fn(async () => { throw { mocked: 'error' }; })
851
- };
852
-
853
- const createSpy = jest.spyOn(TransfersModel, 'create')
854
- .mockImplementationOnce(async () => mockedPSM);
855
-
856
- // invoke handler
857
- await handlers['/simpleTransfers'].post(mockContext);
858
-
859
- // PSM model creation
860
- const state = mockContext.state;
861
- const cacheKey = TransfersModel.channelName({
862
- transferId: mockContext.request.body.transfersPostRequest.transferId
863
- });
864
- const expectedConfig = {
865
- cache: state.cache,
866
- logger: state.logger,
867
- wso2Auth: state.wso2Auth
868
- };
869
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
870
-
871
- // run workflow
872
- expect(mockedPSM.run).toBeCalledWith({
873
- transferId: mockContext.request.body.transfersPostRequest.transferId,
874
- fspId: mockContext.request.body.fspId,
875
- transfer: mockContext.request.body.transfersPostRequest
876
- });
877
-
878
- // response
879
- expect(mockContext.response.status).toBe(500);
880
- expect(mockContext.response.body).toEqual({
881
- message: 'Unspecified error',
882
- requestSimpleTransfersInformationState: {},
883
- statusCode: '500',
884
- });
885
- });
886
- });
887
- });