@mojaloop/sdk-scheme-adapter 15.0.0 → 17.0.0

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 (47) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/audit-resolve.json +43 -542
  3. package/docs/dfspInboundApi.yaml +11 -0
  4. package/package.json +27 -25
  5. package/src/ControlAgent/index.js +8 -11
  6. package/src/ControlServer/index.js +13 -13
  7. package/src/InboundServer/index.js +16 -63
  8. package/src/InboundServer/middlewares.js +12 -4
  9. package/src/OAuthTestServer/index.js +0 -13
  10. package/src/OutboundServer/index.js +13 -55
  11. package/src/OutboundServer/middlewares.js +6 -2
  12. package/src/TestServer/index.js +10 -35
  13. package/src/config.js +1 -4
  14. package/src/index.js +163 -146
  15. package/src/lib/cache.js +93 -186
  16. package/src/lib/metrics.js +1 -3
  17. package/src/lib/model/InboundTransfersModel.js +10 -6
  18. package/src/lib/model/OutboundTransfersModel.js +1 -1
  19. package/src/lib/router.js +3 -1
  20. package/src/lib/validate.js +10 -1
  21. package/test/__mocks__/redis.js +51 -26
  22. package/test/config/integration.env +1 -2
  23. package/test/integration/lib/cache.test.js +1 -2
  24. package/test/integration/testEnv.js +1 -4
  25. package/test/unit/ControlClient.test.js +1 -45
  26. package/test/unit/ControlServer/index.js +18 -22
  27. package/test/unit/ControlServer.test.js +0 -60
  28. package/test/unit/InboundServer.test.js +8 -8
  29. package/test/unit/TestServer.test.js +1 -1
  30. package/test/unit/api/accounts/accounts.test.js +2 -2
  31. package/test/unit/api/transfers/transfers.test.js +1 -1
  32. package/test/unit/api/utils.js +12 -4
  33. package/test/unit/config.test.js +1 -2
  34. package/test/unit/data/defaultConfig.json +1 -5
  35. package/test/unit/index.test.js +5 -64
  36. package/test/unit/lib/cache.test.js +5 -6
  37. package/test/unit/lib/model/AccountsModel.test.js +3 -4
  38. package/test/unit/lib/model/InboundTransfersModel.test.js +55 -16
  39. package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +3 -4
  40. package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +1 -2
  41. package/test/unit/lib/model/OutboundRequestToPayModel.test.js +3 -4
  42. package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +3 -4
  43. package/test/unit/lib/model/OutboundTransfersModel.test.js +2 -3
  44. package/test/unit/lib/model/common/PersistentStateMachine.test.js +3 -4
  45. package/test/unit/lib/model/data/defaultConfig.json +1 -4
  46. package/test/unit/lib/model/data/notificationAbortedToPayee.json +10 -0
  47. package/test/unit/lib/model/data/notificationReservedToPayee.json +10 -0
@@ -28,6 +28,8 @@ const getTransfersMojaloopResponse = require('./data/getTransfersMojaloopRespons
28
28
  const getBulkTransfersBackendResponse = require('./data/getBulkTransfersBackendResponse');
29
29
  const getBulkTransfersMojaloopResponse = require('./data/getBulkTransfersMojaloopResponse');
30
30
  const notificationToPayee = require('./data/notificationToPayee');
31
+ const notificationAbortedToPayee = require('./data/notificationAbortedToPayee');
32
+ const notificationReservedToPayee = require('./data/notificationReservedToPayee');
31
33
 
32
34
  describe('inboundModel', () => {
33
35
  let config;
@@ -63,8 +65,7 @@ describe('inboundModel', () => {
63
65
  }));
64
66
 
65
67
  cache = new Cache({
66
- host: 'dummycachehost',
67
- port: 1234,
68
+ cacheUrl: 'redis://dummy:1234',
68
69
  logger,
69
70
  });
70
71
  await cache.connect();
@@ -132,8 +133,7 @@ describe('inboundModel', () => {
132
133
  BackendRequests.__postBulkQuotes = jest.fn().mockReturnValue(Promise.resolve(mockArgs.internalBulkQuoteResponse));
133
134
 
134
135
  cache = new Cache({
135
- host: 'dummycachehost',
136
- port: 1234,
136
+ cacheUrl: 'redis://dummy:1234',
137
137
  logger,
138
138
  });
139
139
  await cache.connect();
@@ -189,8 +189,7 @@ describe('inboundModel', () => {
189
189
  BackendRequests.__postTransactionRequests = jest.fn().mockReturnValue(Promise.resolve(mockTxnReqArgs.internalTransactionRequestResponse));
190
190
 
191
191
  cache = new Cache({
192
- host: 'dummycachehost',
193
- port: 1234,
192
+ cacheUrl: 'redis://dummy:1234',
194
193
  logger,
195
194
  });
196
195
  await cache.connect();
@@ -226,8 +225,7 @@ describe('inboundModel', () => {
226
225
  BackendRequests.__getOTP = jest.fn().mockReturnValue(Promise.resolve(mockArgs.internalGetOTPResponse));
227
226
 
228
227
  cache = new Cache({
229
- host: 'dummycachehost',
230
- port: 1234,
228
+ cacheUrl: 'redis://dummy:1234',
231
229
  logger,
232
230
  });
233
231
  await cache.connect();
@@ -268,8 +266,7 @@ describe('inboundModel', () => {
268
266
  }));
269
267
 
270
268
  cache = new Cache({
271
- host: 'dummycachehost',
272
- port: 1234,
269
+ cacheUrl: 'redis://dummy:1234',
273
270
  logger,
274
271
  });
275
272
  await cache.connect();
@@ -547,8 +544,7 @@ describe('inboundModel', () => {
547
544
  BackendRequests.__postBulkTransfers = jest.fn().mockReturnValue(Promise.resolve({}));
548
545
 
549
546
  cache = new Cache({
550
- host: 'dummycachehost',
551
- port: 1234,
547
+ cacheUrl: 'redis://dummy:1234',
552
548
  logger,
553
549
  });
554
550
  await cache.connect();
@@ -727,8 +723,7 @@ describe('inboundModel', () => {
727
723
 
728
724
  beforeEach(async () => {
729
725
  cache = new Cache({
730
- host: 'dummycachehost',
731
- port: 1234,
726
+ cacheUrl: 'redis://dummy:1234',
732
727
  logger,
733
728
  });
734
729
  await cache.connect();
@@ -759,14 +754,58 @@ describe('inboundModel', () => {
759
754
  expect(call[0]).toEqual(expectedRequest);
760
755
  expect(call[1]).toEqual(transferId);
761
756
  });
757
+
758
+ test('sends ABORTED notification to fsp backend', async () => {
759
+ BackendRequests.__putTransfersNotification = jest.fn().mockReturnValue(Promise.resolve({}));
760
+ const notif = JSON.parse(JSON.stringify(notificationAbortedToPayee));
761
+
762
+ const expectedRequest = {
763
+ currentState: 'ABORTED',
764
+ finalNotification: notif.data,
765
+ };
766
+
767
+ const model = new Model({
768
+ ...config,
769
+ cache,
770
+ logger,
771
+ });
772
+
773
+ await model.sendNotificationToPayee(notif.data, transferId);
774
+ expect(BackendRequests.__putTransfersNotification).toHaveBeenCalledTimes(1);
775
+ const call = BackendRequests.__putTransfersNotification.mock.calls[0];
776
+ expect(call[0]).toEqual(expectedRequest);
777
+ expect(call[1]).toEqual(transferId);
778
+ });
779
+
780
+ test('sends RESERVED notification to fsp backend', async () => {
781
+ BackendRequests.__putTransfersNotification = jest.fn().mockReturnValue(Promise.resolve({}));
782
+ const notif = JSON.parse(JSON.stringify(notificationReservedToPayee));
783
+
784
+ const expectedRequest = {
785
+ finalNotification: notif.data,
786
+ lastError: 'Final notification state not COMMITTED',
787
+ };
788
+
789
+ const model = new Model({
790
+ ...config,
791
+ cache,
792
+ logger,
793
+ });
794
+
795
+ await model.sendNotificationToPayee(notif.data, transferId);
796
+ expect(BackendRequests.__putTransfersNotification).toHaveBeenCalledTimes(1);
797
+ const call = BackendRequests.__putTransfersNotification.mock.calls[0];
798
+ expect(call[0]).toEqual(expectedRequest);
799
+ expect(call[1]).toEqual(transferId);
800
+ });
801
+
762
802
  });
763
803
 
764
804
  describe('error handling:', () => {
765
805
  let cache;
766
806
  beforeEach(async () => {
767
807
  cache = new Cache({
768
- host: 'dummycachehost',
769
- port: 1234,
808
+ cacheUrl: 'redis://dummy:1234',
770
809
  logger,
771
810
  });
772
811
  await cache.connect();
@@ -91,10 +91,9 @@ describe('OutboundBulkQuotesModel', () => {
91
91
  MojaloopRequests.__putBulkQuotesError = jest.fn(() => Promise.resolve());
92
92
 
93
93
  cache = new Cache({
94
- host: 'dummycachehost',
95
- port: 1234,
96
- logger,
97
- });
94
+ cacheUrl: 'redis://dummy:1234',
95
+ logger,
96
+ });
98
97
  await cache.connect();
99
98
  });
100
99
 
@@ -83,8 +83,7 @@ describe('outboundBulkTransferModel', () => {
83
83
  MojaloopRequests.__postBulkTransfers = jest.fn(() => Promise.resolve());
84
84
 
85
85
  cache = new Cache({
86
- host: 'dummycachehost',
87
- port: 1234,
86
+ cacheUrl: 'redis://dummy:1234',
88
87
  logger,
89
88
  });
90
89
  await cache.connect();
@@ -71,10 +71,9 @@ describe('outboundModel', () => {
71
71
  MojaloopRequests.__postTransactionRequests = jest.fn(() => Promise.resolve());
72
72
 
73
73
  cache = new Cache({
74
- host: 'dummycachehost',
75
- port: 1234,
76
- logger,
77
- });
74
+ cacheUrl: 'redis://dummy:1234',
75
+ logger,
76
+ });
78
77
  await cache.connect();
79
78
  });
80
79
 
@@ -71,10 +71,9 @@ describe('outboundRequestToPayTransferModel', () => {
71
71
  MojaloopRequests.__postTransfers = jest.fn(() => Promise.resolve());
72
72
 
73
73
  cache = new Cache({
74
- host: 'dummycachehost',
75
- port: 1234,
76
- logger,
77
- });
74
+ cacheUrl: 'redis://dummy:1234',
75
+ logger,
76
+ });
78
77
  await cache.connect();
79
78
  });
80
79
 
@@ -163,8 +163,7 @@ describe('outboundModel', () => {
163
163
  }
164
164
  }));
165
165
  cache = new Cache({
166
- host: 'dummycachehost',
167
- port: 1234,
166
+ cacheUrl: 'redis://dummy:1234',
168
167
  logger,
169
168
  });
170
169
  await cache.connect();
@@ -1526,7 +1525,7 @@ describe('outboundModel', () => {
1526
1525
  testTlsServer(false));
1527
1526
 
1528
1527
  test('Outbound transfers model should record metrics', async () => {
1529
- const metrics = metricsClient._prometheusRegister.metrics();
1528
+ const metrics = await metricsClient._prometheusRegister.metrics();
1530
1529
  expect(metrics).toBeTruthy();
1531
1530
 
1532
1531
  expect(metrics).toEqual(expect.stringContaining('mojaloop_connector_outbound_party_lookup_request_count'));
@@ -72,10 +72,9 @@ describe('PersistentStateMachine', () => {
72
72
  data = { the: 'data' };
73
73
 
74
74
  cache = new Cache({
75
- host: 'dummycachehost',
76
- port: 1234,
77
- logger,
78
- });
75
+ cacheUrl: 'redis://dummy:1234',
76
+ logger,
77
+ });
79
78
  // mock cache set & get
80
79
  cache.get = jest.fn(async () => data);
81
80
  cache.set = jest.fn(async () => 'cache set replies');
@@ -38,10 +38,7 @@
38
38
  "jwsSignPutParties": false,
39
39
  "jwsSigningKey": "/jwsSigningKey.key",
40
40
  "jwsVerificationKeysDirectory": null,
41
- "cacheConfig": {
42
- "host": "localhost",
43
- "port": 6379
44
- },
41
+ "cacheUrl": "redis://localhost:6379",
45
42
  "enableTestFeatures": false,
46
43
  "oauthTestServer": {
47
44
  "enabled": false,
@@ -0,0 +1,10 @@
1
+ {
2
+ "type": "notificationToPayee",
3
+ "headers": {
4
+ "fspiop-source": "SWITCH"
5
+ },
6
+ "data": {
7
+ "completedTimestamp": "2017-11-15T14:16:09.663+01:00",
8
+ "transferState": "ABORTED"
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "type": "notificationToPayee",
3
+ "headers": {
4
+ "fspiop-source": "SWITCH"
5
+ },
6
+ "data": {
7
+ "completedTimestamp": "2017-11-15T14:16:09.663+01:00",
8
+ "transferState": "RESERVED"
9
+ }
10
+ }