@mojaloop/central-ledger 9.2.2 → 15.1.3-snapshot.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 (256) hide show
  1. package/.circleci/config.yml +625 -204
  2. package/.env +3 -2
  3. package/.ncurc.yaml +9 -0
  4. package/.nvmrc +1 -1
  5. package/.versionrc +15 -0
  6. package/CHANGELOG.md +353 -0
  7. package/CODEOWNERS +31 -0
  8. package/Dockerfile +20 -14
  9. package/LICENSE.md +4 -4
  10. package/Onboarding.md +0 -7
  11. package/README.md +99 -22
  12. package/audit-resolve.json +136 -1
  13. package/config/default.json +82 -27
  14. package/docker/central-ledger/default.json +68 -21
  15. package/docker/ml-api-adapter/default.json +10 -1
  16. package/docker/wait-for/wait-for-objstore.sh +1 -6
  17. package/docker/wait-for/wait-for.env +1 -1
  18. package/docker-compose.integration.yml +8 -5
  19. package/docker-compose.yml +73 -16
  20. package/migrations/310203_transferParticipant-indexes.js +38 -0
  21. package/migrations/310503_participantLimit-indexes-composite.js +38 -0
  22. package/migrations/{400401_settlementWindowStateChange-indexes.js → 400401_settlmentWindowStateChange-indexes.js} +0 -0
  23. package/migrations/401301_settlementModel-indexes.js +2 -0
  24. package/migrations/500401_quote-hotfix-2719.js +58 -0
  25. package/migrations/500501_feature-fixSubIdRef.js +53 -0
  26. package/migrations/500601_party-2480.js +63 -0
  27. package/migrations/501001_quoteExtension-quote-service-174.js +46 -0
  28. package/migrations/501002_quoteExtension-2522.js +61 -0
  29. package/migrations/800101_feature-fixSubIdRef.js +90 -0
  30. package/migrations/910102_hotfix954.js +4 -1
  31. package/migrations/940100_quotePartyIdInfoExtension.js +52 -0
  32. package/migrations/940101_quotePartyIdInfoExtension-2522.js +64 -0
  33. package/migrations/950100_settlementContentAggregation-decimal184.js +40 -0
  34. package/migrations/950101_transferParticipantStateChange.js +46 -0
  35. package/migrations/950102_settlementModel-adjustPosition.js +42 -0
  36. package/migrations/950103_dropTransferParticipantStateChange.js +47 -0
  37. package/migrations/950104_settlementModel-settlementAccountTypeId.js +79 -0
  38. package/migrations/950106_unique_settlement_model_ledger_account_currency.js +38 -0
  39. package/migrations/950107_settlementWindowContent_foreign_settlementModel.js +60 -0
  40. package/package.json +99 -81
  41. package/scripts/_wait4_all.js +146 -0
  42. package/seeds/amountType.js +4 -6
  43. package/seeds/balanceOfPayments.js +4 -6
  44. package/seeds/bulkProcessingState.js +4 -6
  45. package/seeds/bulkTransferState.js +4 -6
  46. package/seeds/currency.js +4 -6
  47. package/seeds/endpointType.js +128 -7
  48. package/seeds/ledgerAccountType.js +11 -10
  49. package/seeds/ledgerEntryType.js +5 -7
  50. package/seeds/participant.js +4 -6
  51. package/seeds/participantLimitType.js +4 -6
  52. package/seeds/partyIdentifierType.js +4 -6
  53. package/seeds/partyType.js +4 -6
  54. package/seeds/settlementDelay.js +4 -6
  55. package/seeds/settlementGranularity.js +4 -6
  56. package/seeds/settlementInterchange.js +4 -6
  57. package/seeds/settlementState.js +4 -6
  58. package/seeds/settlementWindow1State.js +4 -6
  59. package/seeds/transactionInitiator.js +4 -6
  60. package/seeds/transactionInitiatorType.js +4 -6
  61. package/seeds/transactionScenario.js +4 -6
  62. package/seeds/transferParticipantRoleType.js +4 -6
  63. package/seeds/transferState.js +9 -6
  64. package/src/api/interface/swagger.json +728 -948
  65. package/src/api/ledgerAccountTypes/handler.js +55 -0
  66. package/src/api/ledgerAccountTypes/routes.js +63 -0
  67. package/src/api/metrics/handler.js +2 -2
  68. package/src/api/metrics/routes.js +1 -1
  69. package/src/api/participants/handler.js +43 -35
  70. package/src/api/participants/routes.js +13 -13
  71. package/src/api/root/routes.js +2 -2
  72. package/src/api/settlementModels/handler.js +9 -26
  73. package/src/api/settlementModels/routes.js +4 -4
  74. package/src/api/transactions/handler.js +46 -0
  75. package/src/api/transactions/routes.js +45 -0
  76. package/src/domain/bulkTransfer/index.js +6 -5
  77. package/src/domain/ledgerAccountTypes/index.js +58 -0
  78. package/src/domain/participant/index.js +55 -4
  79. package/src/domain/position/index.js +18 -2
  80. package/src/domain/settlement/index.js +39 -6
  81. package/src/domain/transactions/index.js +61 -0
  82. package/src/domain/transfer/index.js +22 -2
  83. package/src/domain/transfer/transform.js +3 -3
  84. package/src/handlers/admin/handler.js +24 -32
  85. package/src/handlers/bulk/fulfil/handler.js +89 -56
  86. package/src/handlers/bulk/get/handler.js +203 -0
  87. package/src/handlers/bulk/index.js +4 -1
  88. package/src/handlers/bulk/prepare/handler.js +30 -29
  89. package/src/handlers/bulk/processing/handler.js +61 -32
  90. package/src/handlers/bulk/shared/validator.js +13 -1
  91. package/src/handlers/index.js +18 -9
  92. package/src/handlers/positions/handler.js +67 -46
  93. package/src/handlers/register.js +7 -7
  94. package/src/handlers/timeouts/handler.js +9 -4
  95. package/src/handlers/transfers/handler.js +408 -182
  96. package/src/handlers/transfers/validator.js +41 -11
  97. package/src/lib/cache.js +8 -34
  98. package/src/lib/config.js +5 -7
  99. package/src/lib/enum.js +22 -22
  100. package/src/lib/enumCached.js +76 -0
  101. package/src/lib/healthCheck/subServiceHealth.js +2 -2
  102. package/src/lib/requestLogger.js +9 -9
  103. package/src/lib/urlParser.js +1 -1
  104. package/src/models/bulkTransfer/bulkTransfer.js +6 -6
  105. package/src/models/bulkTransfer/bulkTransferAssociation.js +3 -3
  106. package/src/models/bulkTransfer/bulkTransferDuplicateCheck.js +4 -4
  107. package/src/models/bulkTransfer/bulkTransferExtension.js +2 -2
  108. package/src/models/bulkTransfer/bulkTransferFulfilmentDuplicateCheck.js +4 -4
  109. package/src/models/bulkTransfer/bulkTransferStateChange.js +7 -7
  110. package/src/models/bulkTransfer/facade.js +54 -3
  111. package/src/models/bulkTransfer/individualTransfer.js +2 -2
  112. package/src/models/ilpPackets/ilpPacket.js +36 -0
  113. package/src/models/ledgerAccountType/ledgerAccountType.js +139 -3
  114. package/src/models/misc/migrationLock.js +1 -1
  115. package/src/models/misc/segment.js +1 -1
  116. package/src/models/participant/facade.js +226 -76
  117. package/src/models/participant/participant.js +6 -5
  118. package/src/models/participant/participantCached.js +8 -0
  119. package/src/models/participant/participantCurrency.js +7 -7
  120. package/src/models/participant/participantCurrencyCached.js +11 -1
  121. package/src/models/participant/participantLimit.js +13 -13
  122. package/src/models/participant/participantLimitCached.js +124 -0
  123. package/src/models/participant/participantPosition.js +34 -5
  124. package/src/models/participant/participantPositionChange.js +10 -2
  125. package/src/models/position/facade.js +112 -18
  126. package/src/models/position/participantPosition.js +6 -6
  127. package/src/models/settlement/settlementModel.js +92 -17
  128. package/src/models/settlement/settlementModelCached.js +139 -0
  129. package/src/models/transfer/facade.js +97 -32
  130. package/src/models/transfer/ilpPacket.js +4 -4
  131. package/src/models/transfer/transfer.js +7 -7
  132. package/src/models/transfer/transferDuplicateCheck.js +21 -5
  133. package/src/models/transfer/transferError.js +5 -5
  134. package/src/models/transfer/transferErrorDuplicateCheck.js +4 -4
  135. package/src/models/transfer/transferExtension.js +4 -4
  136. package/src/models/transfer/transferFulfilment.js +5 -5
  137. package/src/models/transfer/transferFulfilmentDuplicateCheck.js +4 -4
  138. package/src/models/transfer/transferParticipant.js +3 -3
  139. package/src/models/transfer/transferStateChange.js +11 -11
  140. package/src/models/transfer/transferTimeout.js +5 -5
  141. package/src/schema/bulkTransfer.js +4 -4
  142. package/src/shared/plugins.js +10 -9
  143. package/src/shared/setup.js +69 -46
  144. package/test/integration/domain/participant/index.test.js +2 -0
  145. package/test/integration/handlers/handlers.test.js +605 -166
  146. package/test/integration/handlers/root.test.js +1 -1
  147. package/test/integration/helpers/hubAccounts.js +62 -0
  148. package/test/integration/helpers/ilpPacket.js +1 -1
  149. package/test/integration/helpers/participantFundsInOut.js +80 -0
  150. package/test/integration/helpers/participantLimit.js +6 -1
  151. package/test/integration/helpers/settlementModels.js +88 -0
  152. package/test/integration/helpers/testConsumer.js +163 -0
  153. package/test/integration/helpers/testProducer.js +0 -1
  154. package/test/integration/helpers/transferDuplicateCheck.js +1 -1
  155. package/test/integration/helpers/transferStateChange.js +1 -1
  156. package/test/integration/helpers/transferTestHelper.js +3 -5
  157. package/test/integration/models/transfer/transferStateChange.test.js +6 -0
  158. package/test/unit/api/ledgerAccountTypes/handler.test.js +126 -0
  159. package/test/unit/api/ledgerAccountTypes/routes.test.js +52 -0
  160. package/test/unit/api/participants/handler.test.js +75 -33
  161. package/test/unit/api/root/handler.test.js +1 -1
  162. package/test/unit/api/root/routes.test.js +2 -2
  163. package/test/unit/api/settlementModels/handler.test.js +21 -57
  164. package/test/unit/api/transactions/handler.test.js +108 -0
  165. package/test/unit/api/transactions/routes.test.js +38 -0
  166. package/test/unit/domain/ledgerAccountTypes/index.test.js +197 -0
  167. package/test/unit/domain/participant/index.test.js +115 -2
  168. package/test/unit/domain/settlement/index.test.js +199 -29
  169. package/test/unit/domain/transactions/index.test.js +128 -0
  170. package/test/unit/domain/transfer/index.test.js +1 -0
  171. package/test/unit/domain/transfer/transform.test.js +2 -0
  172. package/test/unit/handlers/admin/handler.test.js +5 -5
  173. package/test/unit/handlers/bulk/get/handler.test.js +401 -0
  174. package/test/unit/handlers/index.test.js +6 -0
  175. package/test/unit/handlers/positions/handler.test.js +26 -0
  176. package/test/unit/handlers/register.test.js +2 -0
  177. package/test/unit/handlers/transfers/handler.test.js +491 -36
  178. package/test/unit/handlers/transfers/validator.test.js +31 -31
  179. package/test/unit/lib/cache.test.js +0 -64
  180. package/test/unit/lib/cachingOfEnums.test.js +121 -0
  181. package/test/unit/lib/config.test.js +34 -0
  182. package/test/unit/lib/enum.test.js +6 -1
  183. package/test/unit/lib/enumCached.test.js +82 -0
  184. package/test/unit/lib/healthCheck/subServiceHealth.test.js +2 -0
  185. package/test/unit/lib/requestLogger.test.js +14 -12
  186. package/test/unit/models/ilpPackets/ilpPacket.test.js +89 -0
  187. package/test/unit/models/ledgerAccountType/ledgerAccountType.test.js +255 -6
  188. package/test/unit/models/misc/migrationLock.test.js +4 -0
  189. package/test/unit/models/misc/segment.test.js +5 -0
  190. package/test/unit/models/participant/facade.test.js +493 -54
  191. package/test/unit/models/participant/participant.test.js +4 -0
  192. package/test/unit/models/participant/participantCurrency.test.js +22 -9
  193. package/test/unit/models/participant/participantCurrencyCached.test.js +1 -1
  194. package/test/unit/models/participant/participantLimit.test.js +97 -0
  195. package/test/unit/models/participant/participantLimitCached.test.js +232 -0
  196. package/test/unit/models/participant/participantPosition.test.js +217 -0
  197. package/test/unit/models/participant/participantPositionChange.test.js +3 -0
  198. package/test/unit/models/position/facade.test.js +318 -29
  199. package/test/unit/models/position/participantPosition.test.js +22 -7
  200. package/test/unit/models/settlement/settlementModel.test.js +18 -37
  201. package/test/unit/models/settlement/settlementModelCached.test.js +171 -0
  202. package/test/unit/models/transfer/facade.test.js +115 -0
  203. package/test/unit/models/transfer/ilpPacket.test.js +28 -11
  204. package/test/unit/models/transfer/transfer.test.js +13 -4
  205. package/test/unit/models/transfer/transferDuplicateCheck.test.js +4 -0
  206. package/test/unit/models/transfer/transferError.test.js +5 -1
  207. package/test/unit/models/transfer/transferErrorDuplicateCheck.test.js +4 -0
  208. package/test/unit/models/transfer/transferExtension.test.js +26 -9
  209. package/test/unit/models/transfer/transferFulfilment.test.js +14 -5
  210. package/test/unit/models/transfer/transferFulfilmentDuplicateCheck.test.js +4 -0
  211. package/test/unit/models/transfer/transferParticipant.test.js +14 -5
  212. package/test/unit/models/transfer/transferStateChange.test.js +3 -0
  213. package/test/unit/models/transfer/transferTimeout.test.js +6 -0
  214. package/test/unit/seeds/amountType.test.js +6 -22
  215. package/test/unit/seeds/balanceOfPayments.test.js +6 -22
  216. package/test/unit/seeds/bulkProcessingState.test.js +84 -0
  217. package/test/unit/{lib/sidecar/nullClient.test.js → seeds/bulkTransferState.test.js} +36 -39
  218. package/test/unit/seeds/currency.test.js +6 -22
  219. package/test/unit/seeds/endpointType.test.js +6 -22
  220. package/test/unit/seeds/ledgerAccountType.test.js +5 -22
  221. package/test/unit/seeds/ledgerEntryType.test.js +6 -22
  222. package/test/unit/seeds/participant.test.js +5 -22
  223. package/test/unit/seeds/participantLimitType.test.js +6 -22
  224. package/test/unit/seeds/partyIdentifierType.test.js +6 -22
  225. package/test/unit/seeds/partyType.test.js +6 -22
  226. package/test/unit/seeds/settlementState.test.js +5 -22
  227. package/test/unit/seeds/settlementWindow1State.test.js +5 -22
  228. package/test/unit/seeds/transactionInitiator.test.js +6 -22
  229. package/test/unit/seeds/transactionInitiatorType.test.js +6 -22
  230. package/test/unit/seeds/transactionScenario.test.js +6 -22
  231. package/test/unit/seeds/transferParticipantRoleType.test.js +6 -22
  232. package/test/unit/seeds/transferState.test.js +6 -22
  233. package/test/unit/shared/plugins.test.js +31 -1
  234. package/test/unit/shared/setup.test.js +25 -36
  235. package/test/util/helpers.js +37 -2
  236. package/test/util/randomTransfers.js +1 -1
  237. package/test/util/scripts/env.sh +6 -5
  238. package/test/util/scripts/populateTestData.sh +204 -181
  239. package/test/util/scripts/populateTestDataForLegacySimulator.sh +261 -0
  240. package/test/util/scripts/restartObjStore.sh +1 -1
  241. package/test-integration.Dockerfile +15 -15
  242. package/test.Dockerfile +12 -12
  243. package/.circleci/_set_up_deploy_envs.sh +0 -47
  244. package/.dockerignore +0 -17
  245. package/.ncurc.json +0 -3
  246. package/server.sh +0 -4
  247. package/sonar-project.properties +0 -17
  248. package/src/lib/sidecar/index.js +0 -47
  249. package/src/lib/sidecar/nullClient.js +0 -18
  250. package/test/.env +0 -8
  251. package/test/integration-config.json +0 -367
  252. package/test/integration-runner.env +0 -31
  253. package/test/integration-runner.sh +0 -264
  254. package/test/spec-runner.sh +0 -132
  255. package/test/unit/lib/sidecar/index.test.js +0 -148
  256. package/test/unit/models/position/participantLimit.test.js +0 -135
@@ -0,0 +1,171 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ * Neal Donnan <neal.donnan@modusbox.com>
22
+ --------------
23
+ ******/
24
+
25
+ 'use strict'
26
+
27
+ const Test = require('tapes')(require('tape'))
28
+ const Sinon = require('sinon')
29
+ const SettlementModelUncached = require('../../../../src/models/settlement/settlementModel')
30
+ const Cache = require('../../../../src/lib/cache')
31
+ const Model = require('../../../../src/models/settlement/settlementModelCached')
32
+
33
+ Test('SettlementModel cached model', async (settlementModelCachedTest) => {
34
+ let sandbox
35
+
36
+ const settlementModelFixtures = [
37
+ {
38
+ settlementModelId: 1,
39
+ name: 'CGS',
40
+ ledgerAccountTypeId: 1
41
+ },
42
+ {
43
+ settlementModelId: 2,
44
+ name: 'InterchangeFee',
45
+ ledgerAccountTypeId: 6
46
+ }
47
+ ]
48
+
49
+ settlementModelCachedTest.beforeEach(t => {
50
+ sandbox = Sinon.createSandbox()
51
+ sandbox.stub(Cache)
52
+ sandbox.stub(SettlementModelUncached)
53
+ SettlementModelUncached.getAll.returns(settlementModelFixtures)
54
+ t.end()
55
+ })
56
+
57
+ settlementModelCachedTest.afterEach(t => {
58
+ sandbox.restore()
59
+ t.end()
60
+ })
61
+
62
+ await settlementModelCachedTest.test('initializes cache correctly', async (test) => {
63
+ const cacheClient = {
64
+ createKey: sandbox.stub().returns({})
65
+ }
66
+ Cache.registerCacheClient.returns(cacheClient)
67
+
68
+ // initialize calls registerCacheClient and createKey
69
+ test.notOk(Cache.registerCacheClient.calledOnce)
70
+ test.notOk(cacheClient.createKey.calledOnce)
71
+ await Model.initialize()
72
+ test.ok(Cache.registerCacheClient.calledOnce)
73
+ test.ok(cacheClient.createKey.calledOnce)
74
+
75
+ test.end()
76
+ })
77
+
78
+ await settlementModelCachedTest.test('calls drop() for invalidateSettlementModelsCache', async (test) => {
79
+ // initialize
80
+ const cacheClient = {
81
+ createKey: sandbox.stub().returns({}),
82
+ drop: sandbox.stub()
83
+ }
84
+ Cache.registerCacheClient.returns(cacheClient)
85
+ await Model.initialize()
86
+
87
+ // check
88
+ test.notOk(cacheClient.drop.calledOnce)
89
+ await Model.invalidateSettlementModelsCache()
90
+ test.ok(cacheClient.drop.calledOnce)
91
+
92
+ test.end()
93
+ })
94
+
95
+ await settlementModelCachedTest.test('getById(), getByName(), getByLedgerAccountTypeId() and getAll() work', async (test) => {
96
+ let cache = null
97
+ const cacheClient = {
98
+ createKey: sandbox.stub().returns({}),
99
+ get: () => cache,
100
+ set: (key, x) => {
101
+ cache = { item: x } // the cache retuns {item: <data>} structure
102
+ }
103
+ }
104
+ Cache.registerCacheClient.returns(cacheClient)
105
+ await Model.initialize()
106
+
107
+ // check getById()
108
+ const settlementModelById = await Model.getById(1)
109
+ test.equal(JSON.stringify(settlementModelById), JSON.stringify(settlementModelFixtures[0]), 'getById() works')
110
+
111
+ // check getByName()
112
+ const settlementModelByName = await Model.getByName(settlementModelFixtures[1].name)
113
+ test.equal(JSON.stringify(settlementModelByName), JSON.stringify(settlementModelFixtures[1]), 'getByName() works')
114
+
115
+ // check getByLedgerAccountTypeId()
116
+ const settlementModelByLedgerAccountTypeId = await Model.getByLedgerAccountTypeId(settlementModelFixtures[1].ledgerAccountTypeId)
117
+ test.equal(JSON.stringify(settlementModelByLedgerAccountTypeId), JSON.stringify(settlementModelFixtures[1]), 'getByLedgerAccountTypeId() works')
118
+
119
+ // check getAll()
120
+ const participantsAll = await Model.getAll()
121
+ test.equal(JSON.stringify(participantsAll), JSON.stringify(settlementModelFixtures), 'getAll() works')
122
+
123
+ test.end()
124
+ })
125
+
126
+ await settlementModelCachedTest.test('getById(), getByName(), getByLedgerAccountTypeId() and getAll() fail when error thrown', async (test) => {
127
+ const cacheClient = {
128
+ createKey: sandbox.stub().returns({}),
129
+ get: () => null
130
+ }
131
+ Cache.registerCacheClient.returns(cacheClient)
132
+ await Model.initialize()
133
+ SettlementModelUncached.getAll.throws(new Error())
134
+
135
+ // check getById()
136
+ try {
137
+ await Model.getById(1)
138
+ test.fail('Error not thrown')
139
+ } catch (err) {
140
+ test.pass('Error thrown')
141
+ }
142
+
143
+ // check getByName()
144
+ try {
145
+ await Model.getByName(settlementModelFixtures[1].name)
146
+ test.fail('Error not thrown')
147
+ } catch (err) {
148
+ test.pass('Error thrown')
149
+ }
150
+
151
+ // check getByLedgerAccountTypeId()
152
+ try {
153
+ await Model.getByLedgerAccountTypeId(settlementModelFixtures[1].ledgerAccountTypeId)
154
+ test.fail('Error not thrown')
155
+ } catch (err) {
156
+ test.pass('Error thrown')
157
+ }
158
+
159
+ // check getAll()
160
+ try {
161
+ await Model.getAll()
162
+ test.fail('Error not thrown')
163
+ } catch (err) {
164
+ test.pass('Error thrown')
165
+ }
166
+
167
+ test.end()
168
+ })
169
+
170
+ await settlementModelCachedTest.end()
171
+ })
@@ -114,6 +114,9 @@ Test('Transfer facade', async (transferFacadeTest) => {
114
114
  Db.participant = {
115
115
  query: sandbox.stub()
116
116
  }
117
+ Db.from = (table) => {
118
+ return Db[table]
119
+ }
117
120
  clock = Sinon.useFakeTimers(now.getTime())
118
121
  sandbox.stub(ParticipantFacade, 'getByNameAndCurrency')
119
122
  t.end()
@@ -961,6 +964,92 @@ Test('Transfer facade', async (transferFacadeTest) => {
961
964
  }
962
965
  })
963
966
 
967
+ await savePayeeTransferResponse.test('return transfer in RECEIVED_ERROR state', async (test) => {
968
+ try {
969
+ action = TransferEventAction.BULK_ABORT
970
+ const record = [{ settlementWindowId: 1 }]
971
+ transferStateChangeRecord.transferStateId = Enum.Transfers.TransferInternalState.RECEIVED_ERROR
972
+ const fspiopError = {
973
+ errorInformation: {
974
+ errorCode: 1000,
975
+ errorDescription: 'descr'
976
+ }
977
+ }
978
+ const payload2 = cloneDeep(fspiopError)
979
+
980
+ sandbox.stub(Db, 'getKnex')
981
+ const trxStub = sandbox.stub()
982
+ trxStub.commit = sandbox.stub()
983
+ const knexStub = sandbox.stub()
984
+ knexStub.transaction = sandbox.stub().callsArgWith(0, trxStub)
985
+ Db.getKnex.returns(knexStub)
986
+
987
+ const builderStub = sandbox.stub()
988
+ const selectStub = sandbox.stub()
989
+ const whereStub = sandbox.stub()
990
+ const orderByStub = sandbox.stub()
991
+ const firstStub = sandbox.stub()
992
+
993
+ builderStub.leftJoin = sandbox.stub()
994
+ Db.settlementWindow.query.callsArgWith(0, builderStub)
995
+ Db.settlementWindow.query.returns(record)
996
+
997
+ builderStub.leftJoin.returns({
998
+ select: selectStub.returns({
999
+ where: whereStub.returns({
1000
+ orderBy: orderByStub.returns({
1001
+ first: firstStub.returns(record)
1002
+ })
1003
+ })
1004
+ })
1005
+ })
1006
+
1007
+ const insertedTransferStateChange = cloneDeep(transferStateChangeRecord)
1008
+ insertedTransferStateChange.transferStateChangeId = 1
1009
+ const transactingStub = sandbox.stub()
1010
+ const insertStub = sandbox.stub()
1011
+ knexStub.returns({
1012
+ transacting: transactingStub.returns({
1013
+ insert: insertStub,
1014
+ where: whereStub.returns({
1015
+ forUpdate: sandbox.stub().returns({
1016
+ first: sandbox.stub().returns({
1017
+ orderBy: sandbox.stub().returns(insertedTransferStateChange)
1018
+ })
1019
+ })
1020
+ })
1021
+ })
1022
+ })
1023
+
1024
+ const expected = cloneDeep(savePayeeTransferResponseResult)
1025
+ delete expected.transferExtensionRecordsList
1026
+ delete expected.transferFulfilmentRecord
1027
+ expected.transferErrorRecord = {
1028
+ transferId,
1029
+ transferStateChangeId: insertedTransferStateChange.transferStateChangeId,
1030
+ errorCode: fspiopError.errorInformation.errorCode,
1031
+ errorDescription: fspiopError.errorInformation.errorDescription,
1032
+ createdDate: insertedTransferStateChange.createdDate
1033
+ }
1034
+ expected.transferStateChangeRecord.reason = fspiopError.errorInformation.errorDescription
1035
+ expected.transferStateChangeRecord.transferStateChangeId = insertedTransferStateChange.transferStateChangeId
1036
+
1037
+ const response = await TransferFacade.savePayeeTransferResponse(transferId, payload2, action, fspiopError)
1038
+ test.deepEqual(response, expected, 'response matches expected result')
1039
+ test.ok(knexStub.withArgs('transferFulfilment').notCalled, 'knex not called with transferFulfilment')
1040
+ test.ok(knexStub.withArgs('transferExtension').notCalled, 'knex not called with transferExtension')
1041
+ test.ok(knexStub.withArgs('transferStateChange').calledTwice, 'knex called with transferStateChange twice')
1042
+ test.ok(transactingStub.withArgs(trxStub).called, 'knex.transacting called with trx')
1043
+ test.ok(insertStub.withArgs(transferFulfilmentRecord).notCalled, 'insert transferFulfilmentRecord not called')
1044
+ test.ok(insertStub.withArgs(transferStateChangeRecord).notCalled, 'insert transferStateChangeRecord not called')
1045
+ test.end()
1046
+ } catch (err) {
1047
+ Logger.error(`savePayeeTransferResponse failed with error - ${err}`)
1048
+ test.fail()
1049
+ test.end()
1050
+ }
1051
+ })
1052
+
964
1053
  await savePayeeTransferResponse.test('throw an error and rollback', async (test) => {
965
1054
  try {
966
1055
  action = TransferEventAction.ABORT
@@ -2520,5 +2609,31 @@ Test('Transfer facade', async (transferFacadeTest) => {
2520
2609
  }
2521
2610
  })
2522
2611
 
2612
+ await transferFacadeTest.test('recordFundsIn should call transfer prepare, reserve and commit functions', async (test) => {
2613
+ const payload = {}
2614
+ const transactionTimestamp = Time.getUTCString(now)
2615
+ const enums = {}
2616
+ try {
2617
+ sandbox.stub(Db, 'getKnex')
2618
+ const knexStub = sandbox.stub()
2619
+ const trxStub = sandbox.stub()
2620
+ trxStub.commit = sandbox.stub()
2621
+ knexStub.transaction = sandbox.stub().callsArgWith(0, trxStub)
2622
+ Db.getKnex.returns(knexStub)
2623
+ sandbox.stub(TransferFacade, 'reconciliationTransferPrepare')
2624
+ sandbox.stub(TransferFacade, 'reconciliationTransferReserve')
2625
+ sandbox.stub(TransferFacade, 'reconciliationTransferCommit')
2626
+
2627
+ await TransferFacade.recordFundsIn(payload, transactionTimestamp, enums)
2628
+ test.ok(TransferFacade.reconciliationTransferPrepare.callsArgWith(0, trxStub))
2629
+ test.ok(TransferFacade.reconciliationTransferReserve.callsArgWith(0, trxStub))
2630
+ test.ok(TransferFacade.reconciliationTransferCommit.callsArgWith(0, trxStub))
2631
+ test.end()
2632
+ } catch (e) {
2633
+ test.fail(`${e} error thrown`)
2634
+ test.end()
2635
+ }
2636
+ })
2637
+
2523
2638
  await transferFacadeTest.end()
2524
2639
  })
@@ -28,7 +28,7 @@
28
28
 
29
29
  'use strict'
30
30
 
31
- const Test = require('tape')
31
+ const Test = require('tapes')(require('tape'))
32
32
  const Sinon = require('sinon')
33
33
  const Db = require('../../../../src/lib/db')
34
34
  const Logger = require('@mojaloop/central-services-logger')
@@ -43,16 +43,33 @@ Test('ilpPacket model', async (ilpTest) => {
43
43
  ]
44
44
  const ilpPacket = ilpPacketTestValues[0]
45
45
 
46
- const sandbox = Sinon.createSandbox()
47
- Db.ilpPacket = {
48
- select: sandbox.stub(),
49
- insert: sandbox.stub(),
50
- update: sandbox.stub(),
51
- findOne: sandbox.stub(),
52
- find: sandbox.stub(),
53
- query: sandbox.stub(),
54
- destroy: sandbox.stub()
55
- }
46
+ let sandbox
47
+
48
+ ilpTest.beforeEach(t => {
49
+ sandbox = Sinon.createSandbox()
50
+
51
+ Db.ilpPacket = {
52
+ select: sandbox.stub(),
53
+ insert: sandbox.stub(),
54
+ update: sandbox.stub(),
55
+ findOne: sandbox.stub(),
56
+ find: sandbox.stub(),
57
+ query: sandbox.stub(),
58
+ destroy: sandbox.stub()
59
+ }
60
+
61
+ Db.from = (table) => {
62
+ return Db[table]
63
+ }
64
+
65
+ t.end()
66
+ })
67
+
68
+ ilpTest.afterEach(t => {
69
+ sandbox.restore()
70
+
71
+ t.end()
72
+ })
56
73
 
57
74
  await ilpTest.test('create false ilpPacket', async (assert) => {
58
75
  const falseIlp = { transferId: '1', value: undefined }
@@ -24,7 +24,7 @@
24
24
 
25
25
  'use strict'
26
26
 
27
- const Test = require('tape')
27
+ const Test = require('tapes')(require('tape'))
28
28
  const Sinon = require('sinon')
29
29
  const Db = require('../../../../src/lib/db')
30
30
  const Logger = require('@mojaloop/central-services-logger')
@@ -42,16 +42,25 @@ Test('Transfer model', async (transfer) => {
42
42
  createdDate: new Date()
43
43
  }
44
44
 
45
- await transfer.test('setup', async (assert) => {
45
+ transfer.beforeEach(beforeTest => {
46
46
  sandbox = Sinon.createSandbox()
47
+ sandbox.stub(Logger, 'isErrorEnabled').value(true)
48
+ sandbox.stub(Logger, 'isDebugEnabled').value(true)
47
49
  Db.transfer = {
48
50
  insert: sandbox.stub(),
49
51
  findOne: sandbox.stub(),
50
52
  destroy: sandbox.stub(),
51
53
  truncate: sandbox.stub()
52
54
  }
53
- assert.pass('setup OK')
54
- assert.end()
55
+ Db.from = (table) => {
56
+ return Db[table]
57
+ }
58
+ beforeTest.end()
59
+ })
60
+
61
+ transfer.afterEach(afterTest => {
62
+ sandbox.restore()
63
+ afterTest.end()
55
64
  })
56
65
 
57
66
  await transfer.test('getById should', async (assert) => {
@@ -39,10 +39,14 @@ Test('TransferDuplicateCheck model', async (TransferDuplicateCheckTest) => {
39
39
  }
40
40
  TransferDuplicateCheckTest.beforeEach(test => {
41
41
  sandbox = Sinon.createSandbox()
42
+ sandbox.stub(Logger, 'isDebugEnabled').value(true)
42
43
  Db.transferDuplicateCheck = {
43
44
  findOne: sandbox.stub(),
44
45
  insert: sandbox.stub()
45
46
  }
47
+ Db.from = (table) => {
48
+ return Db[table]
49
+ }
46
50
  test.end()
47
51
  })
48
52
 
@@ -49,12 +49,16 @@ Test('TransferError model', async (TransferErrorTest) => {
49
49
 
50
50
  TransferErrorTest.beforeEach(test => {
51
51
  sandbox = Sinon.createSandbox()
52
+ sandbox.stub(Logger, 'isErrorEnabled').value(true)
53
+ sandbox.stub(Logger, 'isDebugEnabled').value(true)
52
54
  Db.transferError = {
53
55
  insert: sandbox.stub(),
54
56
  find: sandbox.stub(),
55
57
  query: sandbox.stub()
56
58
  }
57
-
59
+ Db.from = (table) => {
60
+ return Db[table]
61
+ }
58
62
  test.end()
59
63
  })
60
64
 
@@ -40,10 +40,14 @@ Test('TransferErrorDuplicateCheck model', async (TransferErrorDuplicateCheckTest
40
40
  }]
41
41
  TransferErrorDuplicateCheckTest.beforeEach(test => {
42
42
  sandbox = Sinon.createSandbox()
43
+ sandbox.stub(Logger, 'isDebugEnabled').value(true)
43
44
  Db.transferErrorDuplicateCheck = {
44
45
  findOne: sandbox.stub(),
45
46
  insert: sandbox.stub()
46
47
  }
48
+ Db.from = (table) => {
49
+ return Db[table]
50
+ }
47
51
  test.end()
48
52
  })
49
53
 
@@ -27,7 +27,7 @@
27
27
 
28
28
  'use strict'
29
29
 
30
- const Test = require('tape')
30
+ const Test = require('tapes')(require('tape'))
31
31
  const Sinon = require('sinon')
32
32
  const Db = require('../../../../src/lib/db')
33
33
  const Logger = require('@mojaloop/central-services-logger')
@@ -49,14 +49,31 @@ Test('Extension model', async (extensionModelTest) => {
49
49
  }
50
50
  ]
51
51
 
52
- const sandbox = Sinon.createSandbox()
53
- Db.transferExtension = {
54
- insert: sandbox.stub(),
55
- update: sandbox.stub(),
56
- findOne: sandbox.stub(),
57
- find: sandbox.stub(),
58
- destroy: sandbox.stub()
59
- }
52
+ let sandbox
53
+
54
+ extensionModelTest.beforeEach(t => {
55
+ sandbox = Sinon.createSandbox()
56
+
57
+ Db.transferExtension = {
58
+ insert: sandbox.stub(),
59
+ update: sandbox.stub(),
60
+ findOne: sandbox.stub(),
61
+ find: sandbox.stub(),
62
+ destroy: sandbox.stub()
63
+ }
64
+
65
+ Db.from = (table) => {
66
+ return Db[table]
67
+ }
68
+
69
+ t.end()
70
+ })
71
+
72
+ extensionModelTest.afterEach(t => {
73
+ sandbox.restore()
74
+
75
+ t.end()
76
+ })
60
77
 
61
78
  await extensionModelTest.test('create false extension', async (assert) => {
62
79
  Db.transferExtension.insert.withArgs({
@@ -25,7 +25,7 @@
25
25
 
26
26
  'use strict'
27
27
 
28
- const Test = require('tape')
28
+ const Test = require('tapes')(require('tape'))
29
29
  const Sinon = require('sinon')
30
30
  const Db = require('../../../../src/lib/db')
31
31
  const Logger = require('@mojaloop/central-services-logger')
@@ -43,14 +43,23 @@ Test('TransferFulfilment model', async (transferFulfilment) => {
43
43
  createdDate: new Date()
44
44
  }
45
45
 
46
- await transferFulfilment.test('setup', async (assert) => {
46
+ transferFulfilment.beforeEach(beforeTest => {
47
47
  sandbox = Sinon.createSandbox()
48
+ sandbox.stub(Logger, 'isErrorEnabled').value(true)
49
+ sandbox.stub(Logger, 'isDebugEnabled').value(true)
48
50
  Db.transferFulfilment = {
49
51
  insert: sandbox.stub(),
50
52
  find: sandbox.stub()
51
53
  }
52
- assert.pass('setup OK')
53
- assert.end()
54
+ Db.from = (table) => {
55
+ return Db[table]
56
+ }
57
+ beforeTest.end()
58
+ })
59
+
60
+ transferFulfilment.afterEach(afterTest => {
61
+ sandbox.restore()
62
+ afterTest.end()
54
63
  })
55
64
 
56
65
  await transferFulfilment.test('getByTransferId test', async (assert) => {
@@ -108,5 +117,5 @@ Test('TransferFulfilment model', async (transferFulfilment) => {
108
117
  }
109
118
  })
110
119
 
111
- await transferFulfilment.end()
120
+ transferFulfilment.end()
112
121
  })
@@ -39,10 +39,14 @@ Test('TransferFulfilmentDuplicateCheck model', async (TransferFulfilmentDuplicat
39
39
  }]
40
40
  TransferFulfilmentDuplicateCheckTest.beforeEach(test => {
41
41
  sandbox = Sinon.createSandbox()
42
+ sandbox.stub(Logger, 'isDebugEnabled').value(true)
42
43
  Db.transferFulfilmentDuplicateCheck = {
43
44
  findOne: sandbox.stub(),
44
45
  insert: sandbox.stub()
45
46
  }
47
+ Db.from = (table) => {
48
+ return Db[table]
49
+ }
46
50
  test.end()
47
51
  })
48
52
 
@@ -24,7 +24,7 @@
24
24
 
25
25
  'use strict'
26
26
 
27
- const Test = require('tape')
27
+ const Test = require('tapes')(require('tape'))
28
28
  const Sinon = require('sinon')
29
29
  const Db = require('../../../../src/lib/db')
30
30
  const Logger = require('@mojaloop/central-services-logger')
@@ -43,13 +43,22 @@ Test('TransferParticipant model', async (transferParticipant) => {
43
43
  expirationDate: new Date()
44
44
  }
45
45
 
46
- await transferParticipant.test('setup', async (assert) => {
46
+ transferParticipant.beforeEach(beforeTest => {
47
47
  sandbox = Sinon.createSandbox()
48
+ sandbox.stub(Logger, 'isErrorEnabled').value(true)
49
+ sandbox.stub(Logger, 'isDebugEnabled').value(true)
48
50
  Db.transferParticipant = {
49
51
  insert: sandbox.stub()
50
52
  }
51
- assert.pass('setup OK')
52
- assert.end()
53
+ Db.from = (table) => {
54
+ return Db[table]
55
+ }
56
+ beforeTest.end()
57
+ })
58
+
59
+ transferParticipant.afterEach(afterTest => {
60
+ sandbox.restore()
61
+ afterTest.end()
53
62
  })
54
63
 
55
64
  await transferParticipant.test('saveTransferParticipant test', async (assert) => {
@@ -80,5 +89,5 @@ Test('TransferParticipant model', async (transferParticipant) => {
80
89
  }
81
90
  })
82
91
 
83
- await transferParticipant.end()
92
+ transferParticipant.end()
84
93
  })
@@ -54,6 +54,9 @@ Test('TransferStateChange model', async (transferStateChangeModel) => {
54
54
  truncate: sandbox.stub(),
55
55
  query: sandbox.stub()
56
56
  }
57
+ Db.from = (table) => {
58
+ return Db[table]
59
+ }
57
60
  t.end()
58
61
  })
59
62
 
@@ -28,6 +28,7 @@
28
28
  const Test = require('tapes')(require('tape'))
29
29
  const Sinon = require('sinon')
30
30
  const Db = require('../../../../src/lib/db')
31
+ const Logger = require('@mojaloop/central-services-logger')
31
32
  const Model = require('../../../../src/models/transfer/transferTimeout')
32
33
 
33
34
  Test('Transfer Timeout', async (transferTimeoutTest) => {
@@ -35,9 +36,14 @@ Test('Transfer Timeout', async (transferTimeoutTest) => {
35
36
 
36
37
  transferTimeoutTest.beforeEach(t => {
37
38
  sandbox = Sinon.createSandbox()
39
+ sandbox.stub(Logger, 'isErrorEnabled').value(true)
40
+ sandbox.stub(Logger, 'isDebugEnabled').value(true)
38
41
  Db.transferTimeout = {
39
42
  query: sandbox.stub()
40
43
  }
44
+ Db.from = (table) => {
45
+ return Db[table]
46
+ }
41
47
  t.end()
42
48
  })
43
49
 
@@ -19,6 +19,7 @@
19
19
  - Name Surname <name.surname@gatesfoundation.com>
20
20
 
21
21
  * Georgi Georgiev <georgi.georgiev@modusbox.com>
22
+ * Shashikant Hirugade <shashikant.hirugade@modusbox.com>
22
23
  --------------
23
24
  ******/
24
25
 
@@ -46,7 +47,11 @@ Test('AmountType', async (amountTypeSeedTest) => {
46
47
  await amountTypeSeedTest.test('seed should', async (test) => {
47
48
  const knexStub = sandbox.stub()
48
49
  knexStub.returns({
49
- insert: sandbox.stub().returns(true)
50
+ insert: sandbox.stub().returns({
51
+ onConflict: sandbox.stub().returns({
52
+ ignore: sandbox.stub().returns(true)
53
+ })
54
+ })
50
55
  })
51
56
 
52
57
  try {
@@ -61,27 +66,6 @@ Test('AmountType', async (amountTypeSeedTest) => {
61
66
  }
62
67
  })
63
68
 
64
- await amountTypeSeedTest.test('seed should', async (test) => {
65
- function DuplicateEntryError (message) {
66
- this.name = 'DuplicateEntryError'
67
- this.message = message || ''
68
- this.code = 'ER_DUP_ENTRY'
69
- }
70
- DuplicateEntryError.prototype = Error.prototype
71
-
72
- const knexStub = sandbox.stub()
73
- knexStub.throws(new DuplicateEntryError())
74
- try {
75
- const result = await Model.seed(knexStub)
76
- test.equal(result, -1001, 'Duplicate error intercepted and ignored')
77
- test.end()
78
- } catch (err) {
79
- Logger.error(`amountType seed failed with error - ${err}`)
80
- test.fail()
81
- test.end()
82
- }
83
- })
84
-
85
69
  await amountTypeSeedTest.test('seed should', async (test) => {
86
70
  const knexStub = sandbox.stub()
87
71
  knexStub.returns({