@mojaloop/sdk-scheme-adapter 11.18.8

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 (277) hide show
  1. package/.env.example +140 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +30 -0
  4. package/.nvmrc +1 -0
  5. package/.versionrc +15 -0
  6. package/CHANGELOG.md +118 -0
  7. package/InboundServer/api.yaml +3594 -0
  8. package/InboundServer/api_template.yaml +69 -0
  9. package/InboundServer/handlers.js +940 -0
  10. package/InboundServer/index.js +205 -0
  11. package/InboundServer/middlewares.js +426 -0
  12. package/OAuthTestServer/index.js +66 -0
  13. package/OAuthTestServer/model.js +70 -0
  14. package/OutboundServer/api.yaml +2732 -0
  15. package/OutboundServer/api_interfaces/index.d.ts +117 -0
  16. package/OutboundServer/api_interfaces/openapi.d.ts +1475 -0
  17. package/OutboundServer/api_template/components/parameters/bulkQuoteId.yaml +9 -0
  18. package/OutboundServer/api_template/components/parameters/bulkTransferId.yaml +9 -0
  19. package/OutboundServer/api_template/components/parameters/requestToPayTransactionId.yaml +9 -0
  20. package/OutboundServer/api_template/components/parameters/transferId.yaml +9 -0
  21. package/OutboundServer/api_template/components/responses/accountsCreationCompleted.yaml +5 -0
  22. package/OutboundServer/api_template/components/responses/accountsCreationError.yaml +5 -0
  23. package/OutboundServer/api_template/components/responses/accountsCreationTimeout.yaml +5 -0
  24. package/OutboundServer/api_template/components/responses/authorizationPostSuccess.yaml +5 -0
  25. package/OutboundServer/api_template/components/responses/authorizationsServerError.yaml +5 -0
  26. package/OutboundServer/api_template/components/responses/bulkQuoteBadRequest.yaml +5 -0
  27. package/OutboundServer/api_template/components/responses/bulkQuoteServerError.yaml +5 -0
  28. package/OutboundServer/api_template/components/responses/bulkQuoteSuccess.yaml +5 -0
  29. package/OutboundServer/api_template/components/responses/bulkQuoteTimeout.yaml +5 -0
  30. package/OutboundServer/api_template/components/responses/bulkTransferBadRequest.yaml +5 -0
  31. package/OutboundServer/api_template/components/responses/bulkTransferServerError.yaml +5 -0
  32. package/OutboundServer/api_template/components/responses/bulkTransferSuccess.yaml +5 -0
  33. package/OutboundServer/api_template/components/responses/bulkTransferTimeout.yaml +5 -0
  34. package/OutboundServer/api_template/components/responses/partiesByIdError404.yaml +9 -0
  35. package/OutboundServer/api_template/components/responses/partiesByIdSuccess.yaml +5 -0
  36. package/OutboundServer/api_template/components/responses/quotesPostSuccess.yaml +5 -0
  37. package/OutboundServer/api_template/components/responses/quotesServerError.yaml +5 -0
  38. package/OutboundServer/api_template/components/responses/requestToPaySuccess.yaml +5 -0
  39. package/OutboundServer/api_template/components/responses/requestToPayTransferBadRequest.yaml +5 -0
  40. package/OutboundServer/api_template/components/responses/requestToPayTransferSuccess.yaml +5 -0
  41. package/OutboundServer/api_template/components/responses/simpleTransfersPostSuccess.yaml +5 -0
  42. package/OutboundServer/api_template/components/responses/simpleTransfersServerError.yaml +5 -0
  43. package/OutboundServer/api_template/components/responses/transferBadRequest.yaml +5 -0
  44. package/OutboundServer/api_template/components/responses/transferServerError.yaml +5 -0
  45. package/OutboundServer/api_template/components/responses/transferSuccess.yaml +5 -0
  46. package/OutboundServer/api_template/components/responses/transferTimeout.yaml +5 -0
  47. package/OutboundServer/api_template/components/schemas/accountCreationStatus.yaml +18 -0
  48. package/OutboundServer/api_template/components/schemas/accountsCreationState.yaml +4 -0
  49. package/OutboundServer/api_template/components/schemas/accountsRequest.yaml +20 -0
  50. package/OutboundServer/api_template/components/schemas/accountsResponse.yaml +15 -0
  51. package/OutboundServer/api_template/components/schemas/async2SyncCurrentState.yaml +5 -0
  52. package/OutboundServer/api_template/components/schemas/authorizationsPostRequest.yaml +15 -0
  53. package/OutboundServer/api_template/components/schemas/authorizationsPostResponse.yaml +19 -0
  54. package/OutboundServer/api_template/components/schemas/bulkQuoteErrorResponse.yaml +8 -0
  55. package/OutboundServer/api_template/components/schemas/bulkQuoteRequest.yaml +26 -0
  56. package/OutboundServer/api_template/components/schemas/bulkQuoteResponse.yaml +21 -0
  57. package/OutboundServer/api_template/components/schemas/bulkQuoteStatus.yaml +4 -0
  58. package/OutboundServer/api_template/components/schemas/bulkQuoteStatusResponse.yaml +17 -0
  59. package/OutboundServer/api_template/components/schemas/bulkTransferErrorResponse.yaml +8 -0
  60. package/OutboundServer/api_template/components/schemas/bulkTransferRequest.yaml +26 -0
  61. package/OutboundServer/api_template/components/schemas/bulkTransferResponse.yaml +16 -0
  62. package/OutboundServer/api_template/components/schemas/bulkTransferStatus.yaml +4 -0
  63. package/OutboundServer/api_template/components/schemas/bulkTransferStatusResponse.yaml +17 -0
  64. package/OutboundServer/api_template/components/schemas/errorAccountsResponse.yaml +8 -0
  65. package/OutboundServer/api_template/components/schemas/errorAuthorizationsResponse.yaml +3 -0
  66. package/OutboundServer/api_template/components/schemas/errorQuotesResponse.yaml +9 -0
  67. package/OutboundServer/api_template/components/schemas/errorResponse.yaml +8 -0
  68. package/OutboundServer/api_template/components/schemas/errorSimpleTransfersResponse.yaml +3 -0
  69. package/OutboundServer/api_template/components/schemas/errorTransferResponse.yaml +8 -0
  70. package/OutboundServer/api_template/components/schemas/extensionListEmptiable.yaml +6 -0
  71. package/OutboundServer/api_template/components/schemas/individualQuote.yaml +32 -0
  72. package/OutboundServer/api_template/components/schemas/individualQuoteResult.yaml +28 -0
  73. package/OutboundServer/api_template/components/schemas/individualTransfer.yaml +32 -0
  74. package/OutboundServer/api_template/components/schemas/individualTransferFulfilment.yaml +13 -0
  75. package/OutboundServer/api_template/components/schemas/individualTransferResult.yaml +41 -0
  76. package/OutboundServer/api_template/components/schemas/mojaloopError.yaml +5 -0
  77. package/OutboundServer/api_template/components/schemas/mojaloopTransactionRequestState.yaml +2 -0
  78. package/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml +13 -0
  79. package/OutboundServer/api_template/components/schemas/quote.yaml +3 -0
  80. package/OutboundServer/api_template/components/schemas/quoteError.yaml +16 -0
  81. package/OutboundServer/api_template/components/schemas/quotesPostRequest.yaml +13 -0
  82. package/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml +48 -0
  83. package/OutboundServer/api_template/components/schemas/requestToPayRequest.yaml +39 -0
  84. package/OutboundServer/api_template/components/schemas/requestToPayResponse.yaml +41 -0
  85. package/OutboundServer/api_template/components/schemas/requestToPayTransferRequest.yaml +42 -0
  86. package/OutboundServer/api_template/components/schemas/requestToPayTransferResponse.yaml +58 -0
  87. package/OutboundServer/api_template/components/schemas/simpleTransferServerError.yaml +5 -0
  88. package/OutboundServer/api_template/components/schemas/simpleTransfersPostRequest.yaml +12 -0
  89. package/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml +11 -0
  90. package/OutboundServer/api_template/components/schemas/transactionType.yaml +4 -0
  91. package/OutboundServer/api_template/components/schemas/transferContinuationAcceptOTP.yaml +9 -0
  92. package/OutboundServer/api_template/components/schemas/transferContinuationAcceptParty.yaml +8 -0
  93. package/OutboundServer/api_template/components/schemas/transferContinuationAcceptQuote.yaml +9 -0
  94. package/OutboundServer/api_template/components/schemas/transferError.yaml +16 -0
  95. package/OutboundServer/api_template/components/schemas/transferFulfilment.yaml +3 -0
  96. package/OutboundServer/api_template/components/schemas/transferParty.yaml +40 -0
  97. package/OutboundServer/api_template/components/schemas/transferRequest.yaml +37 -0
  98. package/OutboundServer/api_template/components/schemas/transferResponse.yaml +58 -0
  99. package/OutboundServer/api_template/components/schemas/transferStatus.yaml +6 -0
  100. package/OutboundServer/api_template/components/schemas/transferStatusResponse.yaml +13 -0
  101. package/OutboundServer/api_template/health.yaml +12 -0
  102. package/OutboundServer/api_template/openapi.yaml +55 -0
  103. package/OutboundServer/api_template/paths/accounts.yaml +26 -0
  104. package/OutboundServer/api_template/paths/authorizations.yaml +19 -0
  105. package/OutboundServer/api_template/paths/bulkQuotes.yaml +23 -0
  106. package/OutboundServer/api_template/paths/bulkQuotes_bulkQuoteId.yaml +24 -0
  107. package/OutboundServer/api_template/paths/bulkTransfers.yaml +23 -0
  108. package/OutboundServer/api_template/paths/bulkTransfers_bulkTransferId.yaml +24 -0
  109. package/OutboundServer/api_template/paths/parties_Type_ID.yaml +20 -0
  110. package/OutboundServer/api_template/paths/parties_Type_ID_SubId.yaml +22 -0
  111. package/OutboundServer/api_template/paths/quotes.yaml +20 -0
  112. package/OutboundServer/api_template/paths/requestToPay.yaml +22 -0
  113. package/OutboundServer/api_template/paths/requestToPayTransfer.yaml +57 -0
  114. package/OutboundServer/api_template/paths/requestToPayTransfer_requestToPayTransactionId.yaml +34 -0
  115. package/OutboundServer/api_template/paths/simpleTransfers.yaml +19 -0
  116. package/OutboundServer/api_template/paths/transfers.yaml +55 -0
  117. package/OutboundServer/api_template/paths/transfers_transferId.yaml +58 -0
  118. package/OutboundServer/handlers.js +622 -0
  119. package/OutboundServer/index.js +137 -0
  120. package/OutboundServer/middlewares.js +67 -0
  121. package/TestServer/api.yaml +62 -0
  122. package/TestServer/handlers.js +63 -0
  123. package/TestServer/index.js +215 -0
  124. package/audit-resolve.json +65 -0
  125. package/babel.config.js +3 -0
  126. package/config.js +158 -0
  127. package/index.d.ts +1 -0
  128. package/index.js +149 -0
  129. package/jest.config.js +15 -0
  130. package/lib/api/index.js +12 -0
  131. package/lib/cache.js +352 -0
  132. package/lib/check.js +25 -0
  133. package/lib/model/AccountsModel.js +396 -0
  134. package/lib/model/Async2SyncModel.js +283 -0
  135. package/lib/model/AuthorizationsModel.js +86 -0
  136. package/lib/model/InboundTransfersModel.js +730 -0
  137. package/lib/model/OutboundBulkQuotesModel.js +485 -0
  138. package/lib/model/OutboundBulkTransfersModel.js +479 -0
  139. package/lib/model/OutboundRequestToPayModel.js +517 -0
  140. package/lib/model/OutboundRequestToPayTransferModel.js +893 -0
  141. package/lib/model/OutboundTransfersModel.js +823 -0
  142. package/lib/model/PartiesModel.js +70 -0
  143. package/lib/model/ProxyModel/MatchRules/Expression.js +48 -0
  144. package/lib/model/ProxyModel/MatchRules/Headers.js +65 -0
  145. package/lib/model/ProxyModel/MatchRules/MatchRule.js +27 -0
  146. package/lib/model/ProxyModel/MatchRules/Path.js +36 -0
  147. package/lib/model/ProxyModel/MatchRules/Query.js +65 -0
  148. package/lib/model/ProxyModel/MatchRules/index.js +19 -0
  149. package/lib/model/ProxyModel/Route.js +82 -0
  150. package/lib/model/ProxyModel/configSchema.json +118 -0
  151. package/lib/model/ProxyModel/index.js +138 -0
  152. package/lib/model/QuotesModel.js +94 -0
  153. package/lib/model/TransfersModel.js +81 -0
  154. package/lib/model/common/BackendError.js +26 -0
  155. package/lib/model/common/PersistentStateMachine.js +93 -0
  156. package/lib/model/common/index.js +18 -0
  157. package/lib/model/index.js +43 -0
  158. package/lib/model/lib/deferredJob.js +113 -0
  159. package/lib/model/lib/index.js +9 -0
  160. package/lib/model/lib/requests/backendRequests.js +227 -0
  161. package/lib/model/lib/requests/common.js +76 -0
  162. package/lib/model/lib/requests/index.js +19 -0
  163. package/lib/model/lib/shared.js +468 -0
  164. package/lib/randomphrase/index.js +21 -0
  165. package/lib/randomphrase/words.json +3397 -0
  166. package/lib/router.js +28 -0
  167. package/lib/validate.js +205 -0
  168. package/package.json +102 -0
  169. package/test/__mocks__/@mojaloop/sdk-standard-components.js +152 -0
  170. package/test/__mocks__/javascript-state-machine.js +21 -0
  171. package/test/__mocks__/redis.js +49 -0
  172. package/test/__mocks__/uuidv4.js +16 -0
  173. package/test/config/integration.env +136 -0
  174. package/test/integration/lib/Outbound/authorizations.test.js +58 -0
  175. package/test/integration/lib/Outbound/data/authorizationsPostRequest.json +43 -0
  176. package/test/integration/lib/Outbound/data/quotesPostRequest.json +52 -0
  177. package/test/integration/lib/Outbound/data/transfersPostRequest.json +24 -0
  178. package/test/integration/lib/Outbound/parties.test.js +28 -0
  179. package/test/integration/lib/Outbound/quotes.test.js +58 -0
  180. package/test/integration/lib/Outbound/simpleTransfers.test.js +67 -0
  181. package/test/integration/lib/cache.test.js +80 -0
  182. package/test/integration/testEnv.js +7 -0
  183. package/test/unit/InboundServer.test.js +443 -0
  184. package/test/unit/TestServer.test.js +394 -0
  185. package/test/unit/api/accounts/accounts.test.js +128 -0
  186. package/test/unit/api/accounts/data/postAccountsBody.json +7 -0
  187. package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +25 -0
  188. package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +19 -0
  189. package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +17 -0
  190. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +21 -0
  191. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +21 -0
  192. package/test/unit/api/accounts/utils.js +65 -0
  193. package/test/unit/api/proxy/data/proxyConfig.yaml +82 -0
  194. package/test/unit/api/proxy/data/requestBody.json +22 -0
  195. package/test/unit/api/proxy/data/requestHeaders.json +5 -0
  196. package/test/unit/api/proxy/data/requestQuery.json +6 -0
  197. package/test/unit/api/proxy/data/responseBody.json +21 -0
  198. package/test/unit/api/proxy/data/responseHeaders.json +5 -0
  199. package/test/unit/api/proxy/proxy.test.js +220 -0
  200. package/test/unit/api/proxy/utils.js +79 -0
  201. package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +21 -0
  202. package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +17 -0
  203. package/test/unit/api/transfers/data/postQuotesBody.json +52 -0
  204. package/test/unit/api/transfers/data/postTransfersBadBody.json +17 -0
  205. package/test/unit/api/transfers/data/postTransfersBody.json +24 -0
  206. package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +53 -0
  207. package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +47 -0
  208. package/test/unit/api/transfers/data/postTransfersSimpleBody.json +26 -0
  209. package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +101 -0
  210. package/test/unit/api/transfers/data/putPartiesBody.json +20 -0
  211. package/test/unit/api/transfers/data/putQuotesBody.json +37 -0
  212. package/test/unit/api/transfers/data/putTransfersBody.json +17 -0
  213. package/test/unit/api/transfers/transfers.test.js +191 -0
  214. package/test/unit/api/transfers/utils.js +183 -0
  215. package/test/unit/api/utils.js +75 -0
  216. package/test/unit/config.test.js +119 -0
  217. package/test/unit/data/commonHttpHeaders.json +6 -0
  218. package/test/unit/data/defaultConfig.json +58 -0
  219. package/test/unit/data/postQuotesBody.json +52 -0
  220. package/test/unit/data/putParticipantsBody.json +12 -0
  221. package/test/unit/data/putPartiesBody.json +20 -0
  222. package/test/unit/data/testFile.json +29 -0
  223. package/test/unit/data/testFile.yaml +14 -0
  224. package/test/unit/inboundApi/data/mockArguments.json +117 -0
  225. package/test/unit/inboundApi/data/mockTransactionRequest.json +42 -0
  226. package/test/unit/inboundApi/handlers.test.js +799 -0
  227. package/test/unit/index.test.js +55 -0
  228. package/test/unit/lib/cache.test.js +146 -0
  229. package/test/unit/lib/model/AccountsModel.test.js +121 -0
  230. package/test/unit/lib/model/AuthorizationsModel.test.js +460 -0
  231. package/test/unit/lib/model/InboundTransfersModel.test.js +628 -0
  232. package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +249 -0
  233. package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +244 -0
  234. package/test/unit/lib/model/OutboundRequestToPayModel.test.js +166 -0
  235. package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +245 -0
  236. package/test/unit/lib/model/OutboundTransfersModel.test.js +836 -0
  237. package/test/unit/lib/model/PartiesModel.test.js +468 -0
  238. package/test/unit/lib/model/QuotesModel.test.js +470 -0
  239. package/test/unit/lib/model/TransfersModel.test.js +474 -0
  240. package/test/unit/lib/model/common/PersistentStateMachine.test.js +179 -0
  241. package/test/unit/lib/model/data/authorizationsResponse.json +13 -0
  242. package/test/unit/lib/model/data/bulkQuoteRequest.json +27 -0
  243. package/test/unit/lib/model/data/bulkQuoteResponse.json +35 -0
  244. package/test/unit/lib/model/data/bulkTransferFulfil.json +13 -0
  245. package/test/unit/lib/model/data/bulkTransferRequest.json +29 -0
  246. package/test/unit/lib/model/data/defaultConfig.json +47 -0
  247. package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +42 -0
  248. package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +22 -0
  249. package/test/unit/lib/model/data/getTransfersBackendResponse.json +34 -0
  250. package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +17 -0
  251. package/test/unit/lib/model/data/mockArguments.json +131 -0
  252. package/test/unit/lib/model/data/mockTxnRequestsArguments.json +63 -0
  253. package/test/unit/lib/model/data/notificationToPayee.json +10 -0
  254. package/test/unit/lib/model/data/payeeParty.json +16 -0
  255. package/test/unit/lib/model/data/putAuthorizationsResponse.json +10 -0
  256. package/test/unit/lib/model/data/putQuotesResponse.json +33 -0
  257. package/test/unit/lib/model/data/putTransfersResponse.json +5 -0
  258. package/test/unit/lib/model/data/quoteResponse.json +31 -0
  259. package/test/unit/lib/model/data/requestToPayRequest.json +20 -0
  260. package/test/unit/lib/model/data/requestToPayTransferRequest.json +27 -0
  261. package/test/unit/lib/model/data/transactionRequestResponse.json +18 -0
  262. package/test/unit/lib/model/data/transferFulfil.json +8 -0
  263. package/test/unit/lib/model/data/transferRequest.json +26 -0
  264. package/test/unit/lib/model/mockedLibRequests.js +74 -0
  265. package/test/unit/mockLogger.js +39 -0
  266. package/test/unit/outboundApi/data/bulkQuoteRequest.json +28 -0
  267. package/test/unit/outboundApi/data/bulkTransferRequest.json +28 -0
  268. package/test/unit/outboundApi/data/mockBulkQuoteError.json +45 -0
  269. package/test/unit/outboundApi/data/mockBulkTransferError.json +48 -0
  270. package/test/unit/outboundApi/data/mockError.json +41 -0
  271. package/test/unit/outboundApi/data/mockGetPartiesError.json +4 -0
  272. package/test/unit/outboundApi/data/mockRequestToPayError.json +32 -0
  273. package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +39 -0
  274. package/test/unit/outboundApi/data/requestToPay.json +21 -0
  275. package/test/unit/outboundApi/data/requestToPayTransferRequest.json +20 -0
  276. package/test/unit/outboundApi/data/transferRequest.json +21 -0
  277. package/test/unit/outboundApi/handlers.test.js +986 -0
@@ -0,0 +1,42 @@
1
+ {
2
+ "transactionRequest": {
3
+ "transactionRequestId": "fake-transactionrequest-id",
4
+ "amount": {
5
+ "currency": "XOF",
6
+ "amount": 10
7
+ },
8
+ "expiration": "2019-06-04T04:02:10.378Z",
9
+ "payer": {
10
+ "partyIdInfo": {
11
+ "partyIdType": "MSISDN",
12
+ "partyIdentifier": "17855501914",
13
+ "fspId": "mojaloop-sdk"
14
+ },
15
+ "personalInfo": {
16
+ "complexName": {
17
+ "firstName": "Murthy",
18
+ "lastName": "Kakarlamudi"
19
+ },
20
+ "dateOfBirth": "2010-10-10"
21
+ },
22
+ "name": "Murthy Kakarlamudi",
23
+ "merchantClassificationCode": "123"
24
+ },
25
+ "payee": {
26
+ "partyIdInfo": {
27
+ "partyIdType": "MSISDN",
28
+ "partyIdentifier": "17855501914",
29
+ "fspId": "mojaloop-sdk"
30
+ },
31
+ "personalInfo": {
32
+ "complexName": {
33
+ "firstName": "Bob",
34
+ "lastName": "Dylan"
35
+ },
36
+ "dateOfBirth": "2010-10-10"
37
+ },
38
+ "name": "Murthy Kakarlamudi",
39
+ "merchantClassificationCode": "123"
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,799 @@
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
+ * Vassilis Barzokas - vassilis.barzokas@modusbox.com *
9
+ **************************************************************************/
10
+
11
+ 'use strict';
12
+
13
+ jest.mock('../../../lib/model');
14
+
15
+ const handlers = require('../../../InboundServer/handlers');
16
+ const Model = require('../../../lib/model').InboundTransfersModel;
17
+ const QuotesModel = require('../../../lib/model').QuotesModel;
18
+ const PartiesModel = require('../../../lib/model').PartiesModel;
19
+ const TransfersModel = require('../../../lib/model').TransfersModel;
20
+ const AuthorizationsModel = require('../../../lib/model').AuthorizationsModel;
21
+
22
+ const mockArguments = require('./data/mockArguments');
23
+ const mockTransactionRequestData = require('./data/mockTransactionRequest');
24
+ const { Logger } = require('@mojaloop/sdk-standard-components');
25
+
26
+ describe('Inbound API handlers:', () => {
27
+ let mockArgs;
28
+ let mockTransactionRequest;
29
+
30
+ beforeEach(() => {
31
+ mockArgs = JSON.parse(JSON.stringify(mockArguments));
32
+ mockTransactionRequest = JSON.parse(JSON.stringify(mockTransactionRequestData));
33
+ });
34
+
35
+ describe('POST /quotes', () => {
36
+
37
+ let mockContext;
38
+
39
+ beforeEach(() => {
40
+ mockContext = {
41
+ request: {
42
+ body: mockArgs.quoteRequest,
43
+ headers: {
44
+ 'fspiop-source': 'foo'
45
+ }
46
+ },
47
+ response: {},
48
+ state: {
49
+ conf: {},
50
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
51
+ }
52
+ };
53
+
54
+ });
55
+
56
+ test('calls `model.quoteRequest` with the expected arguments.', async () => {
57
+ const quoteRequestSpy = jest.spyOn(Model.prototype, 'quoteRequest');
58
+
59
+ await expect(handlers['/quotes'].post(mockContext)).resolves.toBe(undefined);
60
+
61
+ expect(quoteRequestSpy).toHaveBeenCalledTimes(1);
62
+ expect(quoteRequestSpy.mock.calls[0][0]).toBe(mockContext.request.body);
63
+ expect(quoteRequestSpy.mock.calls[0][1]).toBe(mockContext.request.headers['fspiop-source']);
64
+ });
65
+
66
+
67
+ });
68
+
69
+ describe('GET /quotes', () => {
70
+
71
+ let mockContext;
72
+
73
+ beforeEach(() => {
74
+ mockContext = {
75
+ request: {
76
+ headers: {
77
+ 'fspiop-source': 'foo'
78
+ }
79
+ },
80
+ response: {},
81
+ state: {
82
+ conf: {},
83
+ path: {
84
+ params: {
85
+ 'ID': '1234567890'
86
+ }
87
+ },
88
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
89
+ }
90
+ };
91
+
92
+ });
93
+
94
+ test('calls `model.getQuoteRequest` with the expected arguments.', async () => {
95
+ const getQuoteRequestSpy = jest.spyOn(Model.prototype, 'getQuoteRequest');
96
+
97
+ await expect(handlers['/quotes/{ID}'].get(mockContext)).resolves.toBe(undefined);
98
+
99
+ expect(getQuoteRequestSpy).toHaveBeenCalledTimes(1);
100
+ expect(getQuoteRequestSpy.mock.calls[0][1]).toBe(mockContext.request.headers['fspiop-source']);
101
+
102
+ });
103
+ });
104
+
105
+ describe('PUT /quotes', () => {
106
+
107
+ let mockContext;
108
+
109
+ beforeEach(() => {
110
+ mockContext = {
111
+ request: {
112
+ body: { the: 'mocked-body' },
113
+ headers: {
114
+ 'fspiop-source': 'foo'
115
+ }
116
+ },
117
+ response: {},
118
+ state: {
119
+ conf: {},
120
+ path: {
121
+ params: {
122
+ 'ID': '1234567890'
123
+ }
124
+ },
125
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
126
+ cache: {
127
+ publish: jest.fn(() => Promise.resolve(true))
128
+ }
129
+ }
130
+ };
131
+
132
+ });
133
+
134
+ test('calls `QuotesModel.triggerDeferredJobSpy` with the expected arguments.', async () => {
135
+ const triggerDeferredJobSpy = jest.spyOn(QuotesModel, 'triggerDeferredJob');
136
+
137
+ await expect(handlers['/quotes/{ID}'].put(mockContext)).resolves.toBe(undefined);
138
+
139
+ expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
140
+ expect(triggerDeferredJobSpy).toBeCalledWith({
141
+ cache: mockContext.state.cache,
142
+ message: mockContext.request.body,
143
+ args: {
144
+ quoteId: mockContext.state.path.params.ID
145
+ }
146
+ });
147
+ });
148
+ });
149
+
150
+ describe('POST /bulkQuotes', () => {
151
+
152
+ let mockContext;
153
+
154
+ beforeEach(() => {
155
+ mockContext = {
156
+ request: {
157
+ body: mockArgs.bulkQuoteRequest,
158
+ headers: {
159
+ 'fspiop-source': 'foo'
160
+ }
161
+ },
162
+ response: {},
163
+ state: {
164
+ conf: {},
165
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
166
+ }
167
+ };
168
+
169
+ });
170
+
171
+ test('calls `model.bulkQuoteRequest` with the expected arguments.', async () => {
172
+ const bulkQuoteRequestSpy = jest.spyOn(Model.prototype, 'bulkQuoteRequest');
173
+
174
+ await expect(handlers['/bulkQuotes'].post(mockContext)).resolves.toBe(undefined);
175
+
176
+ expect(bulkQuoteRequestSpy).toHaveBeenCalledTimes(1);
177
+ expect(bulkQuoteRequestSpy.mock.calls[0][0]).toBe(mockContext.request.body);
178
+ expect(bulkQuoteRequestSpy.mock.calls[0][1]).toBe(mockContext.request.headers['fspiop-source']);
179
+ });
180
+ });
181
+
182
+ describe('PUT /bulkQuotes/{ID}', () => {
183
+
184
+ let mockContext;
185
+
186
+ beforeEach(() => {
187
+
188
+ mockContext = {
189
+ request: {
190
+ body: mockArgs.bulkQuotePutRequest,
191
+ headers: {
192
+ 'fspiop-source': 'foo'
193
+ }
194
+ },
195
+ response: {},
196
+ state: {
197
+ conf: {},
198
+ path: {
199
+ params: {
200
+ 'ID': '1234567890'
201
+ }
202
+ },
203
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
204
+ cache: {
205
+ publish: async () => Promise.resolve(true)
206
+ }
207
+ }
208
+ };
209
+ });
210
+
211
+ test('calls `ctx.state.cache.publish` with the expected arguments.', async () => {
212
+ const bulkQuotesSpy = jest.spyOn(mockContext.state.cache, 'publish');
213
+
214
+ await expect(handlers['/bulkQuotes/{ID}'].put(mockContext)).resolves.toBe(undefined);
215
+ expect(mockContext.response.status).toBe(200);
216
+ expect(bulkQuotesSpy).toHaveBeenCalledTimes(1);
217
+ expect(bulkQuotesSpy.mock.calls[0][1]).toMatchObject({
218
+ type: 'bulkQuoteResponse',
219
+ data: mockContext.request.body,
220
+ headers: mockContext.request.headers
221
+ });
222
+ });
223
+ });
224
+
225
+ describe('PUT /bulkQuotes/{ID}/error', () => {
226
+
227
+ let mockContext;
228
+
229
+ beforeEach(() => {
230
+
231
+ mockContext = {
232
+ request: {
233
+ body: {
234
+ errorInformation: {
235
+ errorCode: '5100',
236
+ errorDescription: 'Fake error'
237
+ }
238
+ },
239
+ headers: {
240
+ 'fspiop-source': 'foo'
241
+ }
242
+ },
243
+ response: {},
244
+ state: {
245
+ conf: {},
246
+ path: {
247
+ params: {
248
+ 'ID': '1234567890'
249
+ }
250
+ },
251
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
252
+ cache: {
253
+ publish: async () => Promise.resolve(true)
254
+ }
255
+ }
256
+ };
257
+ });
258
+
259
+ test('calls `ctx.state.cache.publish` with the expected arguments.', async () => {
260
+ const bulkQuotesSpy = jest.spyOn(mockContext.state.cache, 'publish');
261
+
262
+ await expect(handlers['/bulkQuotes/{ID}/error'].put(mockContext)).resolves.toBe(undefined);
263
+ expect(mockContext.response.status).toBe(200);
264
+ expect(bulkQuotesSpy).toHaveBeenCalledTimes(1);
265
+ expect(bulkQuotesSpy.mock.calls[0][1]).toMatchObject({
266
+ type: 'bulkQuoteResponseError',
267
+ data: mockContext.request.body
268
+ });
269
+ });
270
+ });
271
+
272
+ describe('GET /bulkQuotes/{ID}', () => {
273
+
274
+ let mockContext;
275
+
276
+ beforeEach(() => {
277
+
278
+ mockContext = {
279
+ request: {
280
+ headers: {
281
+ 'fspiop-source': 'foo'
282
+ }
283
+ },
284
+ response: {},
285
+ state: {
286
+ conf: {},
287
+ path: {
288
+ params: {
289
+ 'ID': '1234567890'
290
+ }
291
+ },
292
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
293
+ }
294
+ };
295
+ });
296
+
297
+ test('calls `model.getBulkQuote` with the expected arguments.', async () => {
298
+ const bulkQuotesSpy = jest.spyOn(Model.prototype, 'getBulkQuote');
299
+
300
+ await expect(handlers['/bulkQuotes/{ID}'].get(mockContext)).resolves.toBe(undefined);
301
+
302
+ expect(bulkQuotesSpy).toHaveBeenCalledTimes(1);
303
+ expect(bulkQuotesSpy.mock.calls[0][1]).toBe(mockContext.request.headers['fspiop-source']);
304
+ });
305
+ });
306
+
307
+ describe('POST /bulkTransfers', () => {
308
+
309
+ let mockContext;
310
+
311
+ beforeEach(() => {
312
+ mockContext = {
313
+ request: {
314
+ body: mockArgs.bulkTransferRequest,
315
+ headers: {
316
+ 'fspiop-source': 'foo'
317
+ }
318
+ },
319
+ response: {},
320
+ state: {
321
+ conf: {},
322
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
323
+ }
324
+ };
325
+
326
+ });
327
+
328
+ test('calls `model.prepareBulkTransfer` with the expected arguments.', async () => {
329
+ const bulkTransferRequestSpy = jest.spyOn(Model.prototype, 'prepareBulkTransfer');
330
+
331
+ await expect(handlers['/bulkTransfers'].post(mockContext)).resolves.toBe(undefined);
332
+
333
+ expect(bulkTransferRequestSpy).toHaveBeenCalledTimes(1);
334
+ expect(bulkTransferRequestSpy.mock.calls[0][0]).toBe(mockContext.request.body);
335
+ expect(bulkTransferRequestSpy.mock.calls[0][1]).toBe(mockContext.request.headers['fspiop-source']);
336
+ });
337
+ });
338
+
339
+ describe('PUT /bulkTransfers/{ID}', () => {
340
+
341
+ let mockContext;
342
+
343
+ beforeEach(() => {
344
+
345
+ mockContext = {
346
+ request: {
347
+ body: mockArgs.bulkTransferPutRequest,
348
+ headers: {
349
+ 'fspiop-source': 'foo'
350
+ }
351
+ },
352
+ response: {},
353
+ state: {
354
+ conf: {},
355
+ path: {
356
+ params: {
357
+ 'ID': '1234567890'
358
+ }
359
+ },
360
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
361
+ cache: {
362
+ publish: async () => Promise.resolve(true)
363
+ }
364
+ }
365
+ };
366
+ });
367
+
368
+ test('calls `ctx.state.cache.publish` with the expected arguments.', async () => {
369
+ const bulkTransfersSpy = jest.spyOn(mockContext.state.cache, 'publish');
370
+
371
+ await expect(handlers['/bulkTransfers/{ID}'].put(mockContext)).resolves.toBe(undefined);
372
+ expect(mockContext.response.status).toBe(200);
373
+ expect(bulkTransfersSpy).toHaveBeenCalledTimes(1);
374
+ expect(bulkTransfersSpy.mock.calls[0][1]).toMatchObject({
375
+ type: 'bulkTransferResponse',
376
+ data: mockContext.request.body,
377
+ headers: mockContext.request.headers
378
+ });
379
+ });
380
+ });
381
+
382
+ describe('PUT /bulkTransfers/{ID}/error', () => {
383
+
384
+ let mockContext;
385
+
386
+ beforeEach(() => {
387
+
388
+ mockContext = {
389
+ request: {
390
+ body: {
391
+ errorInformation: {
392
+ errorCode: '5100',
393
+ errorDescription: 'Fake error'
394
+ }
395
+ },
396
+ headers: {
397
+ 'fspiop-source': 'foo'
398
+ }
399
+ },
400
+ response: {},
401
+ state: {
402
+ conf: {},
403
+ path: {
404
+ params: {
405
+ 'ID': '1234567890'
406
+ }
407
+ },
408
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
409
+ cache: {
410
+ publish: async () => Promise.resolve(true)
411
+ }
412
+ }
413
+ };
414
+ });
415
+
416
+ test('calls `ctx.state.cache.publish` with the expected arguments.', async () => {
417
+ const bulkTransfersSpy = jest.spyOn(mockContext.state.cache, 'publish');
418
+
419
+ await expect(handlers['/bulkTransfers/{ID}/error'].put(mockContext)).resolves.toBe(undefined);
420
+ expect(mockContext.response.status).toBe(200);
421
+ expect(bulkTransfersSpy).toHaveBeenCalledTimes(1);
422
+ expect(bulkTransfersSpy.mock.calls[0][1]).toMatchObject({
423
+ type: 'bulkTransferResponseError',
424
+ data: mockContext.request.body
425
+ });
426
+ });
427
+ });
428
+
429
+ describe('GET /bulkTransfers/{ID}', () => {
430
+
431
+ let mockContext;
432
+
433
+ beforeEach(() => {
434
+
435
+ mockContext = {
436
+ request: {
437
+ headers: {
438
+ 'fspiop-source': 'foo'
439
+ }
440
+ },
441
+ response: {},
442
+ state: {
443
+ conf: {},
444
+ path: {
445
+ params: {
446
+ 'ID': '1234567890'
447
+ }
448
+ },
449
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
450
+ }
451
+ };
452
+ });
453
+
454
+ test('calls `model.getBulkTransfer` with the expected arguments.', async () => {
455
+ const bulkTransfersSpy = jest.spyOn(Model.prototype, 'getBulkTransfer');
456
+
457
+ await expect(handlers['/bulkTransfers/{ID}'].get(mockContext)).resolves.toBe(undefined);
458
+
459
+ expect(bulkTransfersSpy).toHaveBeenCalledTimes(1);
460
+ expect(bulkTransfersSpy.mock.calls[0][1]).toBe(mockContext.request.headers['fspiop-source']);
461
+ });
462
+ });
463
+
464
+ describe('POST /transactionRequests', () => {
465
+
466
+ let mockTransactionReqContext;
467
+
468
+ beforeEach(() => {
469
+ mockTransactionReqContext = {
470
+ request: {
471
+ body: mockTransactionRequest.transactionRequest,
472
+ headers: {
473
+ 'fspiop-source': 'foo'
474
+ }
475
+ },
476
+ response: {},
477
+ state: {
478
+ conf: {},
479
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
480
+ }
481
+ };
482
+ });
483
+
484
+ test('calls `model.transactionRequest` with the expected arguments.', async () => {
485
+ const transactionRequestSpy = jest.spyOn(Model.prototype, 'transactionRequest');
486
+
487
+ await expect(handlers['/transactionRequests'].post(mockTransactionReqContext)).resolves.toBe(undefined);
488
+
489
+ expect(transactionRequestSpy).toHaveBeenCalledTimes(1);
490
+ expect(transactionRequestSpy.mock.calls[0][0]).toBe(mockTransactionReqContext.request.body);
491
+ expect(transactionRequestSpy.mock.calls[0][1]).toBe(mockTransactionReqContext.request.headers['fspiop-source']);
492
+ });
493
+ });
494
+
495
+ describe('GET /authorizations', () => {
496
+
497
+ let mockAuthorizationContext;
498
+
499
+ beforeEach(() => {
500
+
501
+ mockAuthorizationContext = {
502
+ request: {
503
+ headers: {
504
+ 'fspiop-source': 'foo'
505
+ }
506
+ },
507
+ response: {},
508
+ state: {
509
+ conf: {},
510
+ path : {
511
+ params : {
512
+ 'ID': '1234'
513
+ }
514
+ },
515
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
516
+ }
517
+ };
518
+ });
519
+
520
+ test('calls `model.authorizations` with the expected arguments.', async () => {
521
+ const authorizationsSpy = jest.spyOn(Model.prototype, 'getAuthorizations');
522
+
523
+ await expect(handlers['/authorizations/{ID}'].get(mockAuthorizationContext)).resolves.toBe(undefined);
524
+
525
+ expect(authorizationsSpy).toHaveBeenCalledTimes(1);
526
+ expect(authorizationsSpy.mock.calls[0][1]).toBe(mockAuthorizationContext.request.headers['fspiop-source']);
527
+ });
528
+ });
529
+
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
+ describe('PATCH /transfers/{ID}', () => {
576
+ let mockNotificationMessage;
577
+
578
+ beforeEach(() => {
579
+ mockNotificationMessage = {
580
+ request: {
581
+ headers: {
582
+
583
+ },
584
+ body: {
585
+ transferState: 'COMMITTED',
586
+ completedTimestamp: '2020-08-18T09:39:33.552Z'
587
+ }
588
+ },
589
+ response: {},
590
+ state: {
591
+ conf: {},
592
+ path: {
593
+ params: {
594
+ 'ID': '1234'
595
+ }
596
+ },
597
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
598
+ }
599
+ };
600
+ });
601
+
602
+ test('calls `model.sendNotificationToPayee with expected arguments', async () => {
603
+ const notificationSpy = jest.spyOn(Model.prototype, 'sendNotificationToPayee');
604
+
605
+ await expect(handlers['/transfers/{ID}'].patch(mockNotificationMessage)).resolves.toBe(undefined);
606
+ expect(notificationSpy).toHaveBeenCalledTimes(1);
607
+ expect(notificationSpy.mock.calls[0][1]).toBe(mockNotificationMessage.state.path.params.ID);
608
+ });
609
+
610
+ });
611
+
612
+ describe('PUT /parties/{Type}/{ID}[/{SubId}]', () => {
613
+
614
+ let mockContext;
615
+
616
+ beforeEach(() => {
617
+ mockContext = {
618
+ request: {
619
+ body: { the: 'mocked-body' },
620
+ headers: {
621
+ 'fspiop-source': 'foo'
622
+ }
623
+ },
624
+ response: {},
625
+ state: {
626
+ conf: {},
627
+ path: {
628
+ params: {
629
+ 'Type': 'MSISDN',
630
+ 'ID': '1234567890'
631
+ }
632
+ },
633
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
634
+ cache: {
635
+ publish: jest.fn(() => Promise.resolve(true))
636
+ }
637
+ }
638
+ };
639
+
640
+ });
641
+
642
+ test('calls `PartiesModel.triggerDeferredJobSpy` with the expected arguments.', async () => {
643
+ const triggerDeferredJobSpy = jest.spyOn(PartiesModel, 'triggerDeferredJob');
644
+
645
+ await expect(handlers['/parties/{Type}/{ID}'].put(mockContext)).resolves.toBe(undefined);
646
+
647
+ expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
648
+ expect(triggerDeferredJobSpy).toBeCalledWith({
649
+ cache: mockContext.state.cache,
650
+ message: mockContext.request.body,
651
+ args: {
652
+ type: mockContext.state.path.params.Type,
653
+ id: mockContext.state.path.params.ID
654
+ }
655
+ });
656
+ });
657
+
658
+ test('calls `PartiesModel.triggerDeferredJobSpy` with the expected arguments when SubId param specified.', async () => {
659
+ const triggerDeferredJobSpy = jest.spyOn(PartiesModel, 'triggerDeferredJob');
660
+
661
+ // add extra parameter
662
+ mockContext.state.path.params.SubId = 'sub-id';
663
+
664
+ await expect(handlers['/parties/{Type}/{ID}/{SubId}'].put(mockContext)).resolves.toBe(undefined);
665
+
666
+ expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
667
+ expect(triggerDeferredJobSpy).toBeCalledWith({
668
+ cache: mockContext.state.cache,
669
+ message: mockContext.request.body,
670
+ args: {
671
+ type: mockContext.state.path.params.Type,
672
+ id: mockContext.state.path.params.ID,
673
+ subId: mockContext.state.path.params.SubId
674
+ }
675
+ });
676
+ });
677
+ });
678
+
679
+ describe('PUT /transfers/{ID}', () => {
680
+
681
+ let mockContext;
682
+
683
+ beforeEach(() => {
684
+ mockContext = {
685
+ request: {
686
+ body: { the: 'mocked-body' },
687
+ headers: {
688
+ 'fspiop-source': 'foo'
689
+ }
690
+ },
691
+ response: {},
692
+ state: {
693
+ conf: {},
694
+ path: {
695
+ params: {
696
+ 'ID': '1234567890'
697
+ }
698
+ },
699
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
700
+ cache: {
701
+ publish: jest.fn(() => Promise.resolve(true))
702
+ }
703
+ }
704
+ };
705
+
706
+ });
707
+
708
+ test('calls `TransfersModel.triggerDeferredJobSpy` with the expected arguments.', async () => {
709
+ const triggerDeferredJobSpy = jest.spyOn(TransfersModel, 'triggerDeferredJob');
710
+
711
+ await expect(handlers['/transfers/{ID}'].put(mockContext)).resolves.toBe(undefined);
712
+
713
+ expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
714
+ expect(triggerDeferredJobSpy).toBeCalledWith({
715
+ cache: mockContext.state.cache,
716
+ message: mockContext.request.body,
717
+ args: {
718
+ transferId: mockContext.state.path.params.ID
719
+ }
720
+ });
721
+ });
722
+
723
+ test('calls `TransfersModel.triggerDeferredJobSpy` with the expected arguments when SubId param specified.', async () => {
724
+ const triggerDeferredJobSpy = jest.spyOn(TransfersModel, 'triggerDeferredJob');
725
+
726
+ await expect(handlers['/transfers/{ID}'].put(mockContext)).resolves.toBe(undefined);
727
+
728
+ expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
729
+ expect(triggerDeferredJobSpy).toBeCalledWith({
730
+ cache: mockContext.state.cache,
731
+ message: mockContext.request.body,
732
+ args: {
733
+ transferId: mockContext.state.path.params.ID,
734
+ }
735
+ });
736
+ });
737
+ });
738
+
739
+ describe('PUT /transfers/{ID}/error', () => {
740
+
741
+ let mockContext;
742
+
743
+ beforeEach(() => {
744
+ mockContext = {
745
+ request: {
746
+ body: { the: 'mocked-body' },
747
+ headers: {
748
+ 'fspiop-source': 'foo'
749
+ }
750
+ },
751
+ response: {},
752
+ state: {
753
+ conf: {},
754
+ path: {
755
+ params: {
756
+ 'Type': 'MSISDN',
757
+ 'ID': '1234567890'
758
+ }
759
+ },
760
+ logger: new Logger.Logger({ context: { app: 'inbound-handlers-unit-test' }, stringify: () => '' }),
761
+ cache: {
762
+ publish: jest.fn(() => Promise.resolve(true))
763
+ }
764
+ }
765
+ };
766
+
767
+ });
768
+
769
+ test('calls `TransfersModel.triggerDeferredJobSpy` with the expected arguments.', async () => {
770
+ const triggerDeferredJobSpy = jest.spyOn(TransfersModel, 'triggerDeferredJob');
771
+
772
+ await expect(handlers['/transfers/{ID}'].put(mockContext)).resolves.toBe(undefined);
773
+
774
+ expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
775
+ expect(triggerDeferredJobSpy).toBeCalledWith({
776
+ cache: mockContext.state.cache,
777
+ message: mockContext.request.body,
778
+ args: {
779
+ transferId: mockContext.state.path.params.ID
780
+ }
781
+ });
782
+ });
783
+
784
+ test('calls `TransfersModel.triggerDeferredJobSpy` with the expected arguments when SubId param specified.', async () => {
785
+ const triggerDeferredJobSpy = jest.spyOn(TransfersModel, 'triggerDeferredJob');
786
+
787
+ await expect(handlers['/transfers/{ID}/error'].put(mockContext)).resolves.toBe(undefined);
788
+
789
+ expect(triggerDeferredJobSpy).toHaveBeenCalledTimes(1);
790
+ expect(triggerDeferredJobSpy).toBeCalledWith({
791
+ cache: mockContext.state.cache,
792
+ message: mockContext.request.body,
793
+ args: {
794
+ transferId: mockContext.state.path.params.ID,
795
+ }
796
+ });
797
+ });
798
+ });
799
+ });