@mojaloop/sdk-scheme-adapter 11.18.8 → 11.18.12

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 (31) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/InboundServer/api.yaml +2 -0
  3. package/InboundServer/handlers.js +0 -38
  4. package/OutboundServer/api.yaml +23 -270
  5. package/OutboundServer/api_interfaces/openapi.d.ts +10 -127
  6. package/OutboundServer/api_template/openapi.yaml +0 -3
  7. package/OutboundServer/handlers.js +2 -40
  8. package/audit-resolve.json +214 -0
  9. package/config.js +6 -1
  10. package/lib/model/InboundTransfersModel.js +16 -9
  11. package/lib/model/OutboundBulkQuotesModel.js +1 -0
  12. package/lib/model/OutboundBulkTransfersModel.js +1 -0
  13. package/lib/model/OutboundTransfersModel.js +1 -0
  14. package/lib/model/index.js +1 -3
  15. package/package.json +2 -2
  16. package/test/__mocks__/@mojaloop/sdk-standard-components.js +0 -2
  17. package/test/config/integration.env +0 -3
  18. package/test/unit/inboundApi/handlers.test.js +0 -46
  19. package/test/unit/lib/model/InboundTransfersModel.test.js +42 -4
  20. package/test/unit/outboundApi/handlers.test.js +1 -100
  21. package/OutboundServer/api_template/components/responses/authorizationPostSuccess.yaml +0 -5
  22. package/OutboundServer/api_template/components/responses/authorizationsServerError.yaml +0 -5
  23. package/OutboundServer/api_template/components/schemas/authorizationsPostRequest.yaml +0 -15
  24. package/OutboundServer/api_template/components/schemas/authorizationsPostResponse.yaml +0 -19
  25. package/OutboundServer/api_template/components/schemas/errorAuthorizationsResponse.yaml +0 -3
  26. package/OutboundServer/api_template/paths/authorizations.yaml +0 -19
  27. package/lib/model/AuthorizationsModel.js +0 -86
  28. package/test/integration/lib/Outbound/authorizations.test.js +0 -58
  29. package/test/integration/lib/Outbound/data/authorizationsPostRequest.json +0 -43
  30. package/test/unit/lib/model/AuthorizationsModel.test.js +0 -460
  31. package/test/unit/lib/model/data/putAuthorizationsResponse.json +0 -10
@@ -58,6 +58,220 @@
58
58
  "1781|@mojaloop/event-sdk>grpc>@mapbox/node-pre-gyp>tar": {
59
59
  "decision": "fix",
60
60
  "madeAt": 1631785230676
61
+ },
62
+ "1002401|@mojaloop/event-sdk>@grpc/proto-loader>yargs>string-width>strip-ansi>ansi-regex": {
63
+ "decision": "ignore",
64
+ "madeAt": 1634716056413,
65
+ "expiresAt": 1637308004771
66
+ },
67
+ "1002401|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>string-width>strip-ansi>ansi-regex": {
68
+ "decision": "ignore",
69
+ "madeAt": 1634716056413,
70
+ "expiresAt": 1637308004771
71
+ },
72
+ "1002401|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
73
+ "decision": "ignore",
74
+ "madeAt": 1634716056413,
75
+ "expiresAt": 1637308004771
76
+ },
77
+ "1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
78
+ "decision": "ignore",
79
+ "madeAt": 1634716056413,
80
+ "expiresAt": 1637308004771
81
+ },
82
+ "1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
83
+ "decision": "ignore",
84
+ "madeAt": 1634716056413,
85
+ "expiresAt": 1637308004771
86
+ },
87
+ "1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>wrap-ansi>string-width>strip-ansi>ansi-regex": {
88
+ "decision": "ignore",
89
+ "madeAt": 1634716056413,
90
+ "expiresAt": 1637308004771
91
+ },
92
+ "1002401|@mojaloop/event-sdk>@grpc/proto-loader>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
93
+ "decision": "ignore",
94
+ "madeAt": 1634716056413,
95
+ "expiresAt": 1637308004771
96
+ },
97
+ "1002401|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
98
+ "decision": "ignore",
99
+ "madeAt": 1634716056413,
100
+ "expiresAt": 1637308004771
101
+ },
102
+ "1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
103
+ "decision": "ignore",
104
+ "madeAt": 1634716056413,
105
+ "expiresAt": 1637308004771
106
+ },
107
+ "1002401|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
108
+ "decision": "ignore",
109
+ "madeAt": 1634716056413,
110
+ "expiresAt": 1637308004771
111
+ },
112
+ "1002401|@mojaloop/event-sdk>@grpc/proto-loader>yargs>cliui>strip-ansi>ansi-regex": {
113
+ "decision": "ignore",
114
+ "madeAt": 1634716056413,
115
+ "expiresAt": 1637308004771
116
+ },
117
+ "1002401|@mojaloop/central-services-shared>widdershins>yargs>string-width>strip-ansi>ansi-regex": {
118
+ "decision": "ignore",
119
+ "madeAt": 1634716073663,
120
+ "expiresAt": 1637308004771
121
+ },
122
+ "1002401|@mojaloop/central-services-shared>widdershins>yargs>cliui>string-width>strip-ansi>ansi-regex": {
123
+ "decision": "ignore",
124
+ "madeAt": 1634716073664,
125
+ "expiresAt": 1637308004771
126
+ },
127
+ "1002865|@mojaloop/central-services-shared>shins>sanitize-html": {
128
+ "decision": "ignore",
129
+ "madeAt": 1634716077764,
130
+ "expiresAt": 1637308004771
131
+ },
132
+ "1002866|@mojaloop/central-services-shared>shins>sanitize-html": {
133
+ "decision": "ignore",
134
+ "madeAt": 1634716077764,
135
+ "expiresAt": 1637308004771
136
+ },
137
+ "1003019|@mojaloop/central-services-shared>widdershins>yargs>yargs-parser": {
138
+ "decision": "ignore",
139
+ "madeAt": 1634716081521,
140
+ "expiresAt": 1637308004771
141
+ },
142
+ "1004946|@mojaloop/event-sdk>@grpc/proto-loader>yargs>string-width>strip-ansi>ansi-regex": {
143
+ "decision": "ignore",
144
+ "madeAt": 1644879175753,
145
+ "expiresAt": 1647471172307
146
+ },
147
+ "1004946|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>string-width>strip-ansi>ansi-regex": {
148
+ "decision": "ignore",
149
+ "madeAt": 1644879175753,
150
+ "expiresAt": 1647471172307
151
+ },
152
+ "1004946|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
153
+ "decision": "ignore",
154
+ "madeAt": 1644879175753,
155
+ "expiresAt": 1647471172307
156
+ },
157
+ "1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
158
+ "decision": "ignore",
159
+ "madeAt": 1644879175753,
160
+ "expiresAt": 1647471172307
161
+ },
162
+ "1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
163
+ "decision": "ignore",
164
+ "madeAt": 1644879175754,
165
+ "expiresAt": 1647471172307
166
+ },
167
+ "1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>wrap-ansi>string-width>strip-ansi>ansi-regex": {
168
+ "decision": "ignore",
169
+ "madeAt": 1644879175754,
170
+ "expiresAt": 1647471172307
171
+ },
172
+ "1004946|@mojaloop/event-sdk>@grpc/proto-loader>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
173
+ "decision": "ignore",
174
+ "madeAt": 1644879175754,
175
+ "expiresAt": 1647471172307
176
+ },
177
+ "1004946|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
178
+ "decision": "ignore",
179
+ "madeAt": 1644879175754,
180
+ "expiresAt": 1647471172307
181
+ },
182
+ "1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
183
+ "decision": "ignore",
184
+ "madeAt": 1644879175754,
185
+ "expiresAt": 1647471172307
186
+ },
187
+ "1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
188
+ "decision": "ignore",
189
+ "madeAt": 1644879175754,
190
+ "expiresAt": 1647471172307
191
+ },
192
+ "1004946|@mojaloop/event-sdk>@grpc/proto-loader>yargs>cliui>strip-ansi>ansi-regex": {
193
+ "decision": "ignore",
194
+ "madeAt": 1644879175754,
195
+ "expiresAt": 1647471172307
196
+ },
197
+ "1004854|@mojaloop/central-services-shared>widdershins>openapi-sampler>json-pointer": {
198
+ "decision": "ignore",
199
+ "madeAt": 1644879153322,
200
+ "expiresAt": 1647471110577
201
+ },
202
+ "1004869|@mojaloop/central-services-shared>widdershins>swagger2openapi>better-ajv-errors>jsonpointer": {
203
+ "decision": "ignore",
204
+ "madeAt": 1644879154472,
205
+ "expiresAt": 1647471110577
206
+ },
207
+ "1004869|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>better-ajv-errors>jsonpointer": {
208
+ "decision": "ignore",
209
+ "madeAt": 1644879154472,
210
+ "expiresAt": 1647471110577
211
+ },
212
+ "1004946|@mojaloop/central-services-shared>widdershins>yargs>string-width>strip-ansi>ansi-regex": {
213
+ "decision": "ignore",
214
+ "madeAt": 1644879155619,
215
+ "expiresAt": 1647471110577
216
+ },
217
+ "1004946|@mojaloop/central-services-shared>widdershins>yargs>cliui>string-width>strip-ansi>ansi-regex": {
218
+ "decision": "ignore",
219
+ "madeAt": 1644879155619,
220
+ "expiresAt": 1647471110577
221
+ },
222
+ "1005383|@mojaloop/central-services-shared>shins>sanitize-html": {
223
+ "decision": "ignore",
224
+ "madeAt": 1644879156746,
225
+ "expiresAt": 1647471110577
226
+ },
227
+ "1005384|@mojaloop/central-services-shared>shins>sanitize-html": {
228
+ "decision": "ignore",
229
+ "madeAt": 1644879156746,
230
+ "expiresAt": 1647471110577
231
+ },
232
+ "1005534|@mojaloop/central-services-shared>widdershins>yargs>yargs-parser": {
233
+ "decision": "ignore",
234
+ "madeAt": 1644879157837,
235
+ "expiresAt": 1647471110577
236
+ },
237
+ "1006865|axios>follow-redirects": {
238
+ "decision": "fix",
239
+ "madeAt": 1644879138577
240
+ },
241
+ "1006865|@mojaloop/central-services-shared>axios>follow-redirects": {
242
+ "decision": "fix",
243
+ "madeAt": 1644879138577
244
+ },
245
+ "1007023|axios>follow-redirects": {
246
+ "decision": "fix",
247
+ "madeAt": 1644879138577
248
+ },
249
+ "1007023|@mojaloop/central-services-shared>axios>follow-redirects": {
250
+ "decision": "fix",
251
+ "madeAt": 1644879138577
252
+ },
253
+ "1006899|@mojaloop/central-services-shared>widdershins>node-fetch": {
254
+ "decision": "fix",
255
+ "madeAt": 1644879149946
256
+ },
257
+ "1006899|@mojaloop/event-sdk>grpc>@mapbox/node-pre-gyp>node-fetch": {
258
+ "decision": "fix",
259
+ "madeAt": 1644879149946
260
+ },
261
+ "1006846|@mojaloop/central-services-shared>shins>sanitize-html>postcss": {
262
+ "decision": "ignore",
263
+ "madeAt": 1644879158938,
264
+ "expiresAt": 1647471110577
265
+ },
266
+ "1006886|@mojaloop/central-services-shared>shins>markdown-it": {
267
+ "decision": "ignore",
268
+ "madeAt": 1644879160175,
269
+ "expiresAt": 1647471110577
270
+ },
271
+ "1007017|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>ajv": {
272
+ "decision": "ignore",
273
+ "madeAt": 1644879161354,
274
+ "expiresAt": 1647471110577
61
275
  }
62
276
  },
63
277
  "rules": {},
package/config.js CHANGED
@@ -154,5 +154,10 @@ module.exports = {
154
154
  proxyConfig: env.get('PROXY_CONFIG_PATH').asYamlConfig(),
155
155
  reserveNotification: env.get('RESERVE_NOTIFICATION').default('false').asBool(),
156
156
  // resourceVersions config should be string in format: "resouceOneName=1.0,resourceTwoName=1.1"
157
- resourceVersions: env.get('RESOURCE_VERSIONS').default('').asResourceVersions()
157
+ resourceVersions: env.get('RESOURCE_VERSIONS').default('').asResourceVersions(),
158
+
159
+ // in 3PPI DFSP's generate their own `transferId` which is associated with
160
+ // a transactionRequestId. this option decodes the ilp packet for
161
+ // the `transactionId` to retrieve the quote from cache
162
+ allowDifferentTransferTransactionId: env.get('ALLOW_DIFFERENT_TRANSFER_TRANSACTION_ID').default('false').asBool(),
158
163
  };
@@ -34,6 +34,7 @@ class InboundTransfersModel {
34
34
  this._rejectTransfersOnExpiredQuotes = config.rejectTransfersOnExpiredQuotes;
35
35
  this._allowTransferWithoutQuote = config.allowTransferWithoutQuote;
36
36
  this._reserveNotification = config.reserveNotification;
37
+ this._allowDifferentTransferTransactionId = config.allowDifferentTransferTransactionId;
37
38
 
38
39
  this._mojaloopRequests = new MojaloopRequests({
39
40
  logger: this._logger,
@@ -175,7 +176,7 @@ class InboundTransfersModel {
175
176
  response.expiration = new Date(expiration).toISOString();
176
177
  }
177
178
 
178
- // project our internal quote reponse into mojaloop quote response form
179
+ // project our internal quote response into mojaloop quote response form
179
180
  const mojaloopResponse = shared.internalQuoteResponseToMojaloop(response);
180
181
 
181
182
  // create our ILP packet and condition and tag them on to our internal quote response
@@ -193,7 +194,7 @@ class InboundTransfersModel {
193
194
  fulfilment: fulfilment
194
195
  });
195
196
 
196
- // now store the quoteRespnse data against the quoteId in our cache to be sent as a response to GET /quotes/{ID}
197
+ // now store the quoteResponse data against the quoteId in our cache to be sent as a response to GET /quotes/{ID}
197
198
  await this._cache.set(`quoteResponse_${quoteRequest.quoteId}`, mojaloopResponse);
198
199
 
199
200
  // make a callback to the source fsp with the quote response
@@ -209,21 +210,21 @@ class InboundTransfersModel {
209
210
  }
210
211
 
211
212
  /**
212
- * This is executed as when GET /quotes/{ID} request is made to get the response of a previous POST /quotes request.
213
+ * This is executed as when GET /quotes/{ID} request is made to get the response of a previous POST /quotes request.
213
214
  * Gets the quoteResponse from the cache and makes a callback to the originator with result
214
215
  */
215
216
  async getQuoteRequest(quoteId, sourceFspId) {
216
217
  try {
217
218
  // Get the quoteRespnse data for the quoteId from the cache to be sent as a response to GET /quotes/{ID}
218
219
  const quoteResponse = await this._cache.get(`quoteResponse_${quoteId}`);
219
-
220
+
220
221
  // If no quoteResponse is found in the cache, make an error callback to the source fsp
221
222
  if (!quoteResponse) {
222
223
  const err = new Error('Quote Id not found');
223
224
  const mojaloopError = await this._handleError(err, Errors.MojaloopApiErrorCodes.QUOTE_ID_NOT_FOUND);
224
225
  this._logger.push({ mojaloopError }).log(`Sending error response to ${sourceFspId}`);
225
226
  return await this._mojaloopRequests.putQuotesError(quoteId,
226
- mojaloopError, sourceFspId);
227
+ mojaloopError, sourceFspId);
227
228
  }
228
229
  // Make a PUT /quotes/{ID} callback to the source fsp with the quote response
229
230
  return this._mojaloopRequests.putQuotes(quoteId, quoteResponse, sourceFspId);
@@ -270,14 +271,20 @@ class InboundTransfersModel {
270
271
 
271
272
 
272
273
  /**
273
- * Validates an incoming transfer prepare request and makes a callback to the originator with
274
+ * Validates an incoming transfer prepare request and makes a callback to the originator with
274
275
  * the result
275
276
  */
276
277
  async prepareTransfer(prepareRequest, sourceFspId) {
277
278
  try {
278
-
279
279
  // retrieve our quote data
280
- const quote = await this._cache.get(`quote_${prepareRequest.transferId}`);
280
+ let quote;
281
+
282
+ if (this._allowDifferentTransferTransactionId) {
283
+ const transactionId = this._ilp.getTransactionObject(prepareRequest.ilpPacket).transactionId;
284
+ quote = await this._cache.get(`quote_${transactionId}`);
285
+ } else {
286
+ quote = await this._cache.get(`quote_${prepareRequest.transferId}`);
287
+ }
281
288
 
282
289
  if(!quote) {
283
290
  // Check whether to allow transfers without a previous quote.
@@ -703,7 +710,7 @@ class InboundTransfersModel {
703
710
  }
704
711
 
705
712
  /**
706
- * Forwards Switch notification for fulfiled transfer to the DFSP backend, when acting as a payee
713
+ * Forwards Switch notification for fulfiled transfer to the DFSP backend, when acting as a payee
707
714
  */
708
715
  async sendNotificationToPayee(body, transferId) {
709
716
  try {
@@ -44,6 +44,7 @@ class OutboundBulkQuotesModel {
44
44
  jwsSign: config.jwsSign,
45
45
  jwsSigningKey: config.jwsSigningKey,
46
46
  wso2: config.wso2,
47
+ resourceVersions: config.resourceVersions,
47
48
  });
48
49
  }
49
50
 
@@ -43,6 +43,7 @@ class OutboundBulkTransfersModel {
43
43
  jwsSignPutParties: config.jwsSignPutParties,
44
44
  jwsSigningKey: config.jwsSigningKey,
45
45
  wso2: config.wso2,
46
+ resourceVersions: config.resourceVersions,
46
47
  });
47
48
  }
48
49
 
@@ -56,6 +56,7 @@ class OutboundTransfersModel {
56
56
  jwsSignPutParties: config.jwsSignPutParties,
57
57
  jwsSigningKey: config.jwsSigningKey,
58
58
  wso2: config.wso2,
59
+ resourceVersions: config.resourceVersions,
59
60
  });
60
61
 
61
62
  this._ilp = new Ilp({
@@ -23,7 +23,6 @@ const { BackendError, PersistentStateMachine } = require('./common');
23
23
  const PartiesModel = require('./PartiesModel');
24
24
  const QuotesModel = require('./QuotesModel');
25
25
  const TransfersModel = require('./TransfersModel');
26
- const AuthorizationsModel = require('./AuthorizationsModel');
27
26
 
28
27
  module.exports = {
29
28
  AccountsModel,
@@ -38,6 +37,5 @@ module.exports = {
38
37
  PersistentStateMachine,
39
38
  PartiesModel,
40
39
  QuotesModel,
41
- TransfersModel,
42
- AuthorizationsModel
40
+ TransfersModel
43
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter",
3
- "version": "11.18.8",
3
+ "version": "11.18.12",
4
4
  "description": "An adapter for connecting to Mojaloop API enabled switches.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -79,7 +79,7 @@
79
79
  "devDependencies": {
80
80
  "@babel/core": "^7.15.5",
81
81
  "@babel/preset-env": "^7.15.6",
82
- "@mojaloop/api-snippets": "^12.6.6",
82
+ "@mojaloop/api-snippets": "^13.0.3",
83
83
  "@redocly/openapi-cli": "^1.0.0-beta.59",
84
84
  "@types/jest": "^27.0.1",
85
85
  "babel-jest": "^27.2.0",
@@ -26,7 +26,6 @@ class MockMojaloopRequests extends MojaloopRequests {
26
26
  this.putQuotes = MockMojaloopRequests.__putQuotes;
27
27
  this.putQuotesError = MockMojaloopRequests.__putQuotesError;
28
28
  this.getAuthorizations = MockMojaloopRequests.__getAuthorizations;
29
- this.postAuthorizations = MockMojaloopRequests.__postAuthorizations;
30
29
  this.putAuthorizations = MockMojaloopRequests.__putAuthorizations;
31
30
  this.getTransfers = MockMojaloopRequests.__getTransfers;
32
31
  this.putTransactionRequests = MockMojaloopRequests.__putTransactionRequests;
@@ -50,7 +49,6 @@ MockMojaloopRequests.__postQuotes = jest.fn(() => Promise.resolve());
50
49
  MockMojaloopRequests.__putQuotes = jest.fn(() => Promise.resolve());
51
50
  MockMojaloopRequests.__putQuotesError = jest.fn(() => Promise.resolve());
52
51
  MockMojaloopRequests.__getAuthorizations = jest.fn(() => Promise.resolve());
53
- MockMojaloopRequests.__postAuthorizations = jest.fn(() => Promise.resolve());
54
52
  MockMojaloopRequests.__putAuthorizations = jest.fn(() => Promise.resolve());
55
53
  MockMojaloopRequests.__getTransfers = jest.fn(() => Promise.resolve());
56
54
  MockMojaloopRequests.__putTransactionRequests = jest.fn(() => Promise.resolve());
@@ -127,9 +127,6 @@ QUOTES_ENDPOINT=ml-testing-toolkit:5000
127
127
  # TRANSFERS_ENDPOINT
128
128
  TRANSFERS_ENDPOINT=ml-testing-toolkit:5000
129
129
 
130
- # Authorizations_ENDPOINT
131
- TRANSACTION_REQUESTS_ENDPOINT=ml-testing-toolkit:5000
132
-
133
130
  # To allow transfer without a previous quote request, set this value to true.
134
131
  # The incoming transfer request should consists of an ILP packet and a matching condition in this case.
135
132
  # The fulfilment will be generated from the provided ILP packet, and must hash to the provided condition.
@@ -17,7 +17,6 @@ const Model = require('../../../lib/model').InboundTransfersModel;
17
17
  const QuotesModel = require('../../../lib/model').QuotesModel;
18
18
  const PartiesModel = require('../../../lib/model').PartiesModel;
19
19
  const TransfersModel = require('../../../lib/model').TransfersModel;
20
- const AuthorizationsModel = require('../../../lib/model').AuthorizationsModel;
21
20
 
22
21
  const mockArguments = require('./data/mockArguments');
23
22
  const mockTransactionRequestData = require('./data/mockTransactionRequest');
@@ -527,51 +526,6 @@ describe('Inbound API handlers:', () => {
527
526
  });
528
527
  });
529
528
 
530
- describe('PUT /authorizations', () => {
531
-
532
- let mockContext;
533
-
534
- beforeEach(() => {
535
- mockContext = {
536
- request: {
537
- body: { the: 'mocked-body' },
538
- headers: {
539
- 'fspiop-source': 'foo'
540
- }
541
- },
542
- response: {},
543
- state: {
544
- conf: {},
545
- path: {
546
- params: {
547
- 'ID': '1234'
548
- }
549
- },
550
- logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
551
- cache: {
552
- publish: jest.fn(() => Promise.resolve(true))
553
- }
554
- }
555
- };
556
-
557
- });
558
-
559
- test('calls `AuthorizationsModel.triggerDeferredJobSpy` with the expected arguments.', async () => {
560
- const triggerDeferredJobSpy = jest.spyOn(AuthorizationsModel, 'triggerDeferredJob');
561
-
562
- await expect(handlers['/authorizations/{ID}'].put(mockContext)).resolves.toBe(undefined);
563
-
564
- expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
565
- expect(triggerDeferredJobSpy).toBeCalledWith({
566
- cache: mockContext.state.cache,
567
- message: mockContext.request.body,
568
- args: {
569
- transactionRequestId: mockContext.state.path.params.ID
570
- }
571
- });
572
- });
573
- });
574
-
575
529
  describe('PATCH /transfers/{ID}', () => {
576
530
  let mockNotificationMessage;
577
531
 
@@ -21,6 +21,7 @@ const mockTxnReqquestsArguments = require('./data/mockTxnRequestsArguments');
21
21
  const { MojaloopRequests, Ilp, Logger } = require('@mojaloop/sdk-standard-components');
22
22
  const { BackendRequests, HTTPResponseError } = require('../../../../lib/model/lib/requests');
23
23
  const Cache = require('../../../../lib/cache');
24
+ const shared = require('../../../../lib/model/lib/shared');
24
25
 
25
26
  const getTransfersBackendResponse = require('./data/getTransfersBackendResponse');
26
27
  const getTransfersMojaloopResponse = require('./data/getTransfersMojaloopResponse');
@@ -232,9 +233,9 @@ describe('inboundModel', () => {
232
233
 
233
234
  test('calls `mojaloopRequests.putAuthorizations` with the expected arguments.', async () => {
234
235
  await model.getAuthorizations('123456', mockTxnReqArgs.fspId);
235
-
236
+
236
237
  expect(MojaloopRequests.__putAuthorizations).toHaveBeenCalledTimes(1);
237
-
238
+
238
239
  });
239
240
 
240
241
 
@@ -406,6 +407,43 @@ describe('inboundModel', () => {
406
407
  expect(BackendRequests.__postTransfers).toHaveBeenCalledTimes(1);
407
408
  expect(MojaloopRequests.__putTransfers).toHaveBeenCalledTimes(1);
408
409
  });
410
+
411
+ test('allow different transfer and transaction id', async () => {
412
+ const transactionId = 'mockTransactionId';
413
+ const TRANSFER_ID = 'transfer-id';
414
+ shared.mojaloopPrepareToInternalTransfer = jest.fn().mockReturnValueOnce({});
415
+
416
+ cache.set(`quote_${transactionId}`, {
417
+ fulfilment: '',
418
+ mojaloopResponse: {
419
+ response: ''
420
+ }
421
+ });
422
+
423
+ const args = {
424
+ transferId: TRANSFER_ID,
425
+ amount: {
426
+ currency: 'USD',
427
+ amount: 20.13
428
+ },
429
+ ilpPacket: 'mockIlpPacket',
430
+ condition: 'mockGeneratedCondition'
431
+ };
432
+
433
+ const model = new Model({
434
+ ...config,
435
+ cache,
436
+ logger,
437
+ allowDifferentTransferTransactionId: true,
438
+ checkIlp: false,
439
+ });
440
+
441
+ await model.prepareTransfer(args, mockArgs.fspId);
442
+
443
+ expect(MojaloopRequests.__putTransfersError).toHaveBeenCalledTimes(0);
444
+ expect(BackendRequests.__postTransfers).toHaveBeenCalledTimes(1);
445
+ expect(MojaloopRequests.__putTransfers).toHaveBeenCalledTimes(1);
446
+ });
409
447
  });
410
448
 
411
449
  describe('prepareBulkTransfer:', () => {
@@ -574,7 +612,7 @@ describe('inboundModel', () => {
574
612
  }
575
613
  ]
576
614
  };
577
-
615
+
578
616
  const model = new Model({
579
617
  ...config,
580
618
  cache,
@@ -595,7 +633,7 @@ describe('inboundModel', () => {
595
633
  const transferId = '1234';
596
634
  let cache;
597
635
 
598
- beforeEach(async () => {
636
+ beforeEach(async () => {
599
637
  cache = new Cache({
600
638
  host: 'dummycachehost',
601
639
  port: 1234,
@@ -35,8 +35,7 @@ const {
35
35
  OutboundRequestToPayModel,
36
36
  PartiesModel,
37
37
  QuotesModel,
38
- TransfersModel,
39
- AuthorizationsModel
38
+ TransfersModel
40
39
  } = require('../../../lib/model');
41
40
 
42
41
  /**
@@ -885,102 +884,4 @@ describe('Outbound API handlers:', () => {
885
884
  });
886
885
  });
887
886
  });
888
- describe('POST /authorizations', () => {
889
- const mockContext = {
890
- request: {
891
- body: {
892
- fspId: uuid(),
893
- authorizationsPostRequest: {
894
- transactionRequestId: uuid()
895
- }
896
- }
897
- },
898
- response: {},
899
- state: {
900
- conf: {},
901
- wso2Auth: 'mocked wso2Auth',
902
- logger: mockLogger({ app: 'outbound-api-handlers-test' }),
903
- cache: {
904
- subscribe: jest.fn(() => Promise.resolve())
905
- }
906
- },
907
- };
908
- test('happy flow', async () => {
909
-
910
- // mock state machine
911
- const mockedPSM = {
912
- run: jest.fn(async () => ({ the: 'run response' }))
913
- };
914
-
915
- const createSpy = jest.spyOn(AuthorizationsModel, 'create')
916
- .mockImplementationOnce(async () => mockedPSM);
917
-
918
- // invoke handler
919
- await handlers['/authorizations'].post(mockContext);
920
-
921
- // PSM model creation
922
- const state = mockContext.state;
923
- const cacheKey = AuthorizationsModel.channelName({
924
- transactionRequestId: mockContext.request.body.authorizationsPostRequest.transactionRequestId
925
- });
926
- const expectedConfig = {
927
- cache: state.cache,
928
- logger: state.logger,
929
- wso2Auth: state.wso2Auth
930
- };
931
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
932
-
933
- // run workflow
934
- expect(mockedPSM.run).toBeCalledWith({
935
- transactionRequestId: mockContext.request.body.authorizationsPostRequest.transactionRequestId,
936
- fspId: mockContext.request.body.fspId,
937
- authorization: mockContext.request.body.authorizationsPostRequest
938
- });
939
-
940
- // response
941
- expect(mockContext.response.status).toBe(200);
942
- expect(mockContext.response.body).toEqual({ the: 'run response' });
943
- });
944
-
945
- test('mojaloop error propagation for /authorizations/{ID}', async() => {
946
-
947
- // mock state machine
948
- const mockedPSM = {
949
- run: jest.fn(async () => { throw { mocked: 'error' }; })
950
- };
951
-
952
- const createSpy = jest.spyOn(AuthorizationsModel, 'create')
953
- .mockImplementationOnce(async () => mockedPSM);
954
-
955
- // invoke handler
956
- await handlers['/authorizations'].post(mockContext);
957
-
958
- // PSM model creation
959
- const state = mockContext.state;
960
- const cacheKey = AuthorizationsModel.channelName({
961
- transactionRequestId: mockContext.request.body.authorizationsPostRequest.transactionRequestId
962
- });
963
- const expectedConfig = {
964
- cache: state.cache,
965
- logger: state.logger,
966
- wso2Auth: state.wso2Auth
967
- };
968
- expect(createSpy).toBeCalledWith({}, cacheKey, expectedConfig);
969
-
970
- // run workflow
971
- expect(mockedPSM.run).toBeCalledWith({
972
- transactionRequestId: mockContext.request.body.authorizationsPostRequest.transactionRequestId,
973
- fspId: mockContext.request.body.fspId,
974
- authorization: mockContext.request.body.authorizationsPostRequest
975
- });
976
-
977
- // response
978
- expect(mockContext.response.status).toBe(500);
979
- expect(mockContext.response.body).toEqual({
980
- message: 'Unspecified error',
981
- requestAuthorizationsInformationState: {},
982
- statusCode: '500',
983
- });
984
- });
985
- });
986
887
  });
@@ -1,5 +0,0 @@
1
- description: Sync response from POST /authorizations
2
- content:
3
- application/json:
4
- schema:
5
- $ref: ../schemas/authorizationsPostResponse.yaml