@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.
- package/.circleci/config.yml +625 -204
- package/.env +3 -2
- package/.ncurc.yaml +9 -0
- package/.nvmrc +1 -1
- package/.versionrc +15 -0
- package/CHANGELOG.md +353 -0
- package/CODEOWNERS +31 -0
- package/Dockerfile +20 -14
- package/LICENSE.md +4 -4
- package/Onboarding.md +0 -7
- package/README.md +99 -22
- package/audit-resolve.json +136 -1
- package/config/default.json +82 -27
- package/docker/central-ledger/default.json +68 -21
- package/docker/ml-api-adapter/default.json +10 -1
- package/docker/wait-for/wait-for-objstore.sh +1 -6
- package/docker/wait-for/wait-for.env +1 -1
- package/docker-compose.integration.yml +8 -5
- package/docker-compose.yml +73 -16
- package/migrations/310203_transferParticipant-indexes.js +38 -0
- package/migrations/310503_participantLimit-indexes-composite.js +38 -0
- package/migrations/{400401_settlementWindowStateChange-indexes.js → 400401_settlmentWindowStateChange-indexes.js} +0 -0
- package/migrations/401301_settlementModel-indexes.js +2 -0
- package/migrations/500401_quote-hotfix-2719.js +58 -0
- package/migrations/500501_feature-fixSubIdRef.js +53 -0
- package/migrations/500601_party-2480.js +63 -0
- package/migrations/501001_quoteExtension-quote-service-174.js +46 -0
- package/migrations/501002_quoteExtension-2522.js +61 -0
- package/migrations/800101_feature-fixSubIdRef.js +90 -0
- package/migrations/910102_hotfix954.js +4 -1
- package/migrations/940100_quotePartyIdInfoExtension.js +52 -0
- package/migrations/940101_quotePartyIdInfoExtension-2522.js +64 -0
- package/migrations/950100_settlementContentAggregation-decimal184.js +40 -0
- package/migrations/950101_transferParticipantStateChange.js +46 -0
- package/migrations/950102_settlementModel-adjustPosition.js +42 -0
- package/migrations/950103_dropTransferParticipantStateChange.js +47 -0
- package/migrations/950104_settlementModel-settlementAccountTypeId.js +79 -0
- package/migrations/950106_unique_settlement_model_ledger_account_currency.js +38 -0
- package/migrations/950107_settlementWindowContent_foreign_settlementModel.js +60 -0
- package/package.json +99 -81
- package/scripts/_wait4_all.js +146 -0
- package/seeds/amountType.js +4 -6
- package/seeds/balanceOfPayments.js +4 -6
- package/seeds/bulkProcessingState.js +4 -6
- package/seeds/bulkTransferState.js +4 -6
- package/seeds/currency.js +4 -6
- package/seeds/endpointType.js +128 -7
- package/seeds/ledgerAccountType.js +11 -10
- package/seeds/ledgerEntryType.js +5 -7
- package/seeds/participant.js +4 -6
- package/seeds/participantLimitType.js +4 -6
- package/seeds/partyIdentifierType.js +4 -6
- package/seeds/partyType.js +4 -6
- package/seeds/settlementDelay.js +4 -6
- package/seeds/settlementGranularity.js +4 -6
- package/seeds/settlementInterchange.js +4 -6
- package/seeds/settlementState.js +4 -6
- package/seeds/settlementWindow1State.js +4 -6
- package/seeds/transactionInitiator.js +4 -6
- package/seeds/transactionInitiatorType.js +4 -6
- package/seeds/transactionScenario.js +4 -6
- package/seeds/transferParticipantRoleType.js +4 -6
- package/seeds/transferState.js +9 -6
- package/src/api/interface/swagger.json +728 -948
- package/src/api/ledgerAccountTypes/handler.js +55 -0
- package/src/api/ledgerAccountTypes/routes.js +63 -0
- package/src/api/metrics/handler.js +2 -2
- package/src/api/metrics/routes.js +1 -1
- package/src/api/participants/handler.js +43 -35
- package/src/api/participants/routes.js +13 -13
- package/src/api/root/routes.js +2 -2
- package/src/api/settlementModels/handler.js +9 -26
- package/src/api/settlementModels/routes.js +4 -4
- package/src/api/transactions/handler.js +46 -0
- package/src/api/transactions/routes.js +45 -0
- package/src/domain/bulkTransfer/index.js +6 -5
- package/src/domain/ledgerAccountTypes/index.js +58 -0
- package/src/domain/participant/index.js +55 -4
- package/src/domain/position/index.js +18 -2
- package/src/domain/settlement/index.js +39 -6
- package/src/domain/transactions/index.js +61 -0
- package/src/domain/transfer/index.js +22 -2
- package/src/domain/transfer/transform.js +3 -3
- package/src/handlers/admin/handler.js +24 -32
- package/src/handlers/bulk/fulfil/handler.js +89 -56
- package/src/handlers/bulk/get/handler.js +203 -0
- package/src/handlers/bulk/index.js +4 -1
- package/src/handlers/bulk/prepare/handler.js +30 -29
- package/src/handlers/bulk/processing/handler.js +61 -32
- package/src/handlers/bulk/shared/validator.js +13 -1
- package/src/handlers/index.js +18 -9
- package/src/handlers/positions/handler.js +67 -46
- package/src/handlers/register.js +7 -7
- package/src/handlers/timeouts/handler.js +9 -4
- package/src/handlers/transfers/handler.js +408 -182
- package/src/handlers/transfers/validator.js +41 -11
- package/src/lib/cache.js +8 -34
- package/src/lib/config.js +5 -7
- package/src/lib/enum.js +22 -22
- package/src/lib/enumCached.js +76 -0
- package/src/lib/healthCheck/subServiceHealth.js +2 -2
- package/src/lib/requestLogger.js +9 -9
- package/src/lib/urlParser.js +1 -1
- package/src/models/bulkTransfer/bulkTransfer.js +6 -6
- package/src/models/bulkTransfer/bulkTransferAssociation.js +3 -3
- package/src/models/bulkTransfer/bulkTransferDuplicateCheck.js +4 -4
- package/src/models/bulkTransfer/bulkTransferExtension.js +2 -2
- package/src/models/bulkTransfer/bulkTransferFulfilmentDuplicateCheck.js +4 -4
- package/src/models/bulkTransfer/bulkTransferStateChange.js +7 -7
- package/src/models/bulkTransfer/facade.js +54 -3
- package/src/models/bulkTransfer/individualTransfer.js +2 -2
- package/src/models/ilpPackets/ilpPacket.js +36 -0
- package/src/models/ledgerAccountType/ledgerAccountType.js +139 -3
- package/src/models/misc/migrationLock.js +1 -1
- package/src/models/misc/segment.js +1 -1
- package/src/models/participant/facade.js +226 -76
- package/src/models/participant/participant.js +6 -5
- package/src/models/participant/participantCached.js +8 -0
- package/src/models/participant/participantCurrency.js +7 -7
- package/src/models/participant/participantCurrencyCached.js +11 -1
- package/src/models/participant/participantLimit.js +13 -13
- package/src/models/participant/participantLimitCached.js +124 -0
- package/src/models/participant/participantPosition.js +34 -5
- package/src/models/participant/participantPositionChange.js +10 -2
- package/src/models/position/facade.js +112 -18
- package/src/models/position/participantPosition.js +6 -6
- package/src/models/settlement/settlementModel.js +92 -17
- package/src/models/settlement/settlementModelCached.js +139 -0
- package/src/models/transfer/facade.js +97 -32
- package/src/models/transfer/ilpPacket.js +4 -4
- package/src/models/transfer/transfer.js +7 -7
- package/src/models/transfer/transferDuplicateCheck.js +21 -5
- package/src/models/transfer/transferError.js +5 -5
- package/src/models/transfer/transferErrorDuplicateCheck.js +4 -4
- package/src/models/transfer/transferExtension.js +4 -4
- package/src/models/transfer/transferFulfilment.js +5 -5
- package/src/models/transfer/transferFulfilmentDuplicateCheck.js +4 -4
- package/src/models/transfer/transferParticipant.js +3 -3
- package/src/models/transfer/transferStateChange.js +11 -11
- package/src/models/transfer/transferTimeout.js +5 -5
- package/src/schema/bulkTransfer.js +4 -4
- package/src/shared/plugins.js +10 -9
- package/src/shared/setup.js +69 -46
- package/test/integration/domain/participant/index.test.js +2 -0
- package/test/integration/handlers/handlers.test.js +605 -166
- package/test/integration/handlers/root.test.js +1 -1
- package/test/integration/helpers/hubAccounts.js +62 -0
- package/test/integration/helpers/ilpPacket.js +1 -1
- package/test/integration/helpers/participantFundsInOut.js +80 -0
- package/test/integration/helpers/participantLimit.js +6 -1
- package/test/integration/helpers/settlementModels.js +88 -0
- package/test/integration/helpers/testConsumer.js +163 -0
- package/test/integration/helpers/testProducer.js +0 -1
- package/test/integration/helpers/transferDuplicateCheck.js +1 -1
- package/test/integration/helpers/transferStateChange.js +1 -1
- package/test/integration/helpers/transferTestHelper.js +3 -5
- package/test/integration/models/transfer/transferStateChange.test.js +6 -0
- package/test/unit/api/ledgerAccountTypes/handler.test.js +126 -0
- package/test/unit/api/ledgerAccountTypes/routes.test.js +52 -0
- package/test/unit/api/participants/handler.test.js +75 -33
- package/test/unit/api/root/handler.test.js +1 -1
- package/test/unit/api/root/routes.test.js +2 -2
- package/test/unit/api/settlementModels/handler.test.js +21 -57
- package/test/unit/api/transactions/handler.test.js +108 -0
- package/test/unit/api/transactions/routes.test.js +38 -0
- package/test/unit/domain/ledgerAccountTypes/index.test.js +197 -0
- package/test/unit/domain/participant/index.test.js +115 -2
- package/test/unit/domain/settlement/index.test.js +199 -29
- package/test/unit/domain/transactions/index.test.js +128 -0
- package/test/unit/domain/transfer/index.test.js +1 -0
- package/test/unit/domain/transfer/transform.test.js +2 -0
- package/test/unit/handlers/admin/handler.test.js +5 -5
- package/test/unit/handlers/bulk/get/handler.test.js +401 -0
- package/test/unit/handlers/index.test.js +6 -0
- package/test/unit/handlers/positions/handler.test.js +26 -0
- package/test/unit/handlers/register.test.js +2 -0
- package/test/unit/handlers/transfers/handler.test.js +491 -36
- package/test/unit/handlers/transfers/validator.test.js +31 -31
- package/test/unit/lib/cache.test.js +0 -64
- package/test/unit/lib/cachingOfEnums.test.js +121 -0
- package/test/unit/lib/config.test.js +34 -0
- package/test/unit/lib/enum.test.js +6 -1
- package/test/unit/lib/enumCached.test.js +82 -0
- package/test/unit/lib/healthCheck/subServiceHealth.test.js +2 -0
- package/test/unit/lib/requestLogger.test.js +14 -12
- package/test/unit/models/ilpPackets/ilpPacket.test.js +89 -0
- package/test/unit/models/ledgerAccountType/ledgerAccountType.test.js +255 -6
- package/test/unit/models/misc/migrationLock.test.js +4 -0
- package/test/unit/models/misc/segment.test.js +5 -0
- package/test/unit/models/participant/facade.test.js +493 -54
- package/test/unit/models/participant/participant.test.js +4 -0
- package/test/unit/models/participant/participantCurrency.test.js +22 -9
- package/test/unit/models/participant/participantCurrencyCached.test.js +1 -1
- package/test/unit/models/participant/participantLimit.test.js +97 -0
- package/test/unit/models/participant/participantLimitCached.test.js +232 -0
- package/test/unit/models/participant/participantPosition.test.js +217 -0
- package/test/unit/models/participant/participantPositionChange.test.js +3 -0
- package/test/unit/models/position/facade.test.js +318 -29
- package/test/unit/models/position/participantPosition.test.js +22 -7
- package/test/unit/models/settlement/settlementModel.test.js +18 -37
- package/test/unit/models/settlement/settlementModelCached.test.js +171 -0
- package/test/unit/models/transfer/facade.test.js +115 -0
- package/test/unit/models/transfer/ilpPacket.test.js +28 -11
- package/test/unit/models/transfer/transfer.test.js +13 -4
- package/test/unit/models/transfer/transferDuplicateCheck.test.js +4 -0
- package/test/unit/models/transfer/transferError.test.js +5 -1
- package/test/unit/models/transfer/transferErrorDuplicateCheck.test.js +4 -0
- package/test/unit/models/transfer/transferExtension.test.js +26 -9
- package/test/unit/models/transfer/transferFulfilment.test.js +14 -5
- package/test/unit/models/transfer/transferFulfilmentDuplicateCheck.test.js +4 -0
- package/test/unit/models/transfer/transferParticipant.test.js +14 -5
- package/test/unit/models/transfer/transferStateChange.test.js +3 -0
- package/test/unit/models/transfer/transferTimeout.test.js +6 -0
- package/test/unit/seeds/amountType.test.js +6 -22
- package/test/unit/seeds/balanceOfPayments.test.js +6 -22
- package/test/unit/seeds/bulkProcessingState.test.js +84 -0
- package/test/unit/{lib/sidecar/nullClient.test.js → seeds/bulkTransferState.test.js} +36 -39
- package/test/unit/seeds/currency.test.js +6 -22
- package/test/unit/seeds/endpointType.test.js +6 -22
- package/test/unit/seeds/ledgerAccountType.test.js +5 -22
- package/test/unit/seeds/ledgerEntryType.test.js +6 -22
- package/test/unit/seeds/participant.test.js +5 -22
- package/test/unit/seeds/participantLimitType.test.js +6 -22
- package/test/unit/seeds/partyIdentifierType.test.js +6 -22
- package/test/unit/seeds/partyType.test.js +6 -22
- package/test/unit/seeds/settlementState.test.js +5 -22
- package/test/unit/seeds/settlementWindow1State.test.js +5 -22
- package/test/unit/seeds/transactionInitiator.test.js +6 -22
- package/test/unit/seeds/transactionInitiatorType.test.js +6 -22
- package/test/unit/seeds/transactionScenario.test.js +6 -22
- package/test/unit/seeds/transferParticipantRoleType.test.js +6 -22
- package/test/unit/seeds/transferState.test.js +6 -22
- package/test/unit/shared/plugins.test.js +31 -1
- package/test/unit/shared/setup.test.js +25 -36
- package/test/util/helpers.js +37 -2
- package/test/util/randomTransfers.js +1 -1
- package/test/util/scripts/env.sh +6 -5
- package/test/util/scripts/populateTestData.sh +204 -181
- package/test/util/scripts/populateTestDataForLegacySimulator.sh +261 -0
- package/test/util/scripts/restartObjStore.sh +1 -1
- package/test-integration.Dockerfile +15 -15
- package/test.Dockerfile +12 -12
- package/.circleci/_set_up_deploy_envs.sh +0 -47
- package/.dockerignore +0 -17
- package/.ncurc.json +0 -3
- package/server.sh +0 -4
- package/sonar-project.properties +0 -17
- package/src/lib/sidecar/index.js +0 -47
- package/src/lib/sidecar/nullClient.js +0 -18
- package/test/.env +0 -8
- package/test/integration-config.json +0 -367
- package/test/integration-runner.env +0 -31
- package/test/integration-runner.sh +0 -264
- package/test/spec-runner.sh +0 -132
- package/test/unit/lib/sidecar/index.test.js +0 -148
- package/test/unit/models/position/participantLimit.test.js +0 -135
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
* ModusBox
|
|
22
|
+
- Claudio Viola <claudio.viola@modusbox.com>
|
|
23
|
+
--------------
|
|
24
|
+
******/
|
|
25
|
+
'use strict'
|
|
26
|
+
|
|
27
|
+
const Test = require('tapes')(require('tape'))
|
|
28
|
+
const Base = require('../../base')
|
|
29
|
+
const AdminRoutes = require('../../../../src/api/routes')
|
|
30
|
+
|
|
31
|
+
Test('/ledgerAccountTypes router ', async ledgerAccountTypesRoutesTest => {
|
|
32
|
+
ledgerAccountTypesRoutesTest.test('should have the routes', async function (test) {
|
|
33
|
+
const server = await Base.setup(AdminRoutes)
|
|
34
|
+
let req = Base.buildRequest({
|
|
35
|
+
url: '/ledgerAccountTypes',
|
|
36
|
+
method: 'POST'
|
|
37
|
+
})
|
|
38
|
+
let res = await server.inject(req)
|
|
39
|
+
test.ok(res.statusCode, 400, 'should have POST /ledgerAccountTypes route')
|
|
40
|
+
req = Base.buildRequest({
|
|
41
|
+
url: '/ledgerAccountTypes',
|
|
42
|
+
method: 'GET'
|
|
43
|
+
})
|
|
44
|
+
res = await server.inject(req)
|
|
45
|
+
test.ok(res.statusCode, 500, 'should have GET /ledgerAccountTypes route')
|
|
46
|
+
|
|
47
|
+
await server.stop()
|
|
48
|
+
test.end()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
ledgerAccountTypesRoutesTest.end()
|
|
52
|
+
})
|
|
@@ -5,11 +5,10 @@ const Sinon = require('sinon')
|
|
|
5
5
|
|
|
6
6
|
const Logger = require('@mojaloop/central-services-logger')
|
|
7
7
|
const Handler = require('../../../../src/api/participants/handler')
|
|
8
|
-
const Sidecar = require('../../../../src/lib/sidecar')
|
|
9
8
|
const Participant = require('../../../../src/domain/participant')
|
|
10
|
-
const
|
|
11
|
-
const Cache = require('../../../../src/lib/cache')
|
|
9
|
+
const EnumCached = require('../../../../src/lib/enumCached')
|
|
12
10
|
const FSPIOPError = require('@mojaloop/central-services-error-handling').Factory.FSPIOPError
|
|
11
|
+
const SettlementModel = require('../../../../src/domain/settlement')
|
|
13
12
|
|
|
14
13
|
const createRequest = ({ payload, params, query }) => {
|
|
15
14
|
const sandbox = Sinon.createSandbox()
|
|
@@ -109,14 +108,31 @@ Test('Participant', participantHandlerTest => {
|
|
|
109
108
|
]
|
|
110
109
|
}
|
|
111
110
|
]
|
|
111
|
+
const settlementModelFixtures = [
|
|
112
|
+
{
|
|
113
|
+
settlementModelId: 1,
|
|
114
|
+
name: 'DEFERREDNET',
|
|
115
|
+
isActive: 1,
|
|
116
|
+
settlementGranularityId: 2,
|
|
117
|
+
settlementInterchangeId: 2,
|
|
118
|
+
settlementDelayId: 2,
|
|
119
|
+
currencyId: null,
|
|
120
|
+
requireLiquidityCheck: 1,
|
|
121
|
+
ledgerAccountTypeId: 1,
|
|
122
|
+
autoPositionReset: 1,
|
|
123
|
+
adjustPosition: 0,
|
|
124
|
+
settlementAccountTypeId: 2
|
|
125
|
+
}
|
|
126
|
+
]
|
|
112
127
|
|
|
113
128
|
participantHandlerTest.beforeEach(test => {
|
|
114
129
|
sandbox = Sinon.createSandbox()
|
|
115
|
-
sandbox.stub(Sidecar)
|
|
116
130
|
sandbox.stub(Logger)
|
|
117
131
|
sandbox.stub(Participant)
|
|
118
|
-
sandbox.stub(
|
|
119
|
-
|
|
132
|
+
sandbox.stub(EnumCached)
|
|
133
|
+
sandbox.stub(SettlementModel, 'getAll')
|
|
134
|
+
EnumCached.getEnums.returns(Promise.resolve({ POSITION: 1, SETTLEMENT: 2, HUB_RECONCILIATION: 3, HUB_MULTILATERAL_SETTLEMENT: 4, HUB_FEE: 5 }))
|
|
135
|
+
Logger.isDebugEnabled = true
|
|
120
136
|
test.end()
|
|
121
137
|
})
|
|
122
138
|
|
|
@@ -210,7 +226,7 @@ Test('Participant', participantHandlerTest => {
|
|
|
210
226
|
}
|
|
211
227
|
})
|
|
212
228
|
|
|
213
|
-
handlerTest.test('create should create and return the new participant', async function (test) {
|
|
229
|
+
handlerTest.test('create should create and return the new participant with settlementModel', async function (test) {
|
|
214
230
|
const payload = {
|
|
215
231
|
name: 'fsp1',
|
|
216
232
|
currency: 'USD'
|
|
@@ -236,6 +252,7 @@ Test('Participant', participantHandlerTest => {
|
|
|
236
252
|
Participant.createParticipantCurrency.withArgs(participant.participantId, payload.currency, 2).returns(Promise.resolve(participantCurrencyId2))
|
|
237
253
|
Participant.getParticipantCurrencyById.withArgs(participantCurrencyId1).returns(Promise.resolve(currencyList1))
|
|
238
254
|
Participant.getParticipantCurrencyById.withArgs(participantCurrencyId2).returns(Promise.resolve(currencyList2))
|
|
255
|
+
SettlementModel.getAll.returns(Promise.resolve(settlementModelFixtures))
|
|
239
256
|
const reply = {
|
|
240
257
|
response: (response) => {
|
|
241
258
|
return {
|
|
@@ -250,6 +267,55 @@ Test('Participant', participantHandlerTest => {
|
|
|
250
267
|
await Handler.create(createRequest({ payload }), reply)
|
|
251
268
|
})
|
|
252
269
|
|
|
270
|
+
handlerTest.test('create should not create new participant without default settlementModel', async function (test) {
|
|
271
|
+
try {
|
|
272
|
+
const payload = {
|
|
273
|
+
name: 'fsp1',
|
|
274
|
+
currency: 'USD'
|
|
275
|
+
}
|
|
276
|
+
const participant = {
|
|
277
|
+
participantId: 1,
|
|
278
|
+
name: 'fsp1',
|
|
279
|
+
currency: 'USD',
|
|
280
|
+
isActive: 1,
|
|
281
|
+
createdDate: '2018-07-17T16:04:24.185Z'
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const participantCurrencyId1 = 1
|
|
285
|
+
const participantCurrencyId2 = 2
|
|
286
|
+
const currencyList1 = { participantCurrencyId: 1, currencyId: 'USD', ledgerAccountTypeId: 1, isActive: 1, createdBy: 'unknown', createdDate: '2018-07-17T16:04:24.185Z' }
|
|
287
|
+
const currencyList2 = { participantCurrencyId: 2, currencyId: 'USD', ledgerAccountTypeId: 2, isActive: 1, createdBy: 'unknown', createdDate: '2018-07-17T16:04:24.185Z' }
|
|
288
|
+
|
|
289
|
+
Participant.hubAccountExists.withArgs(participant.currency).returns(Promise.resolve(true))
|
|
290
|
+
Participant.getByName.withArgs(participantFixtures[0].name).returns(Promise.resolve(null))
|
|
291
|
+
Participant.create.withArgs(payload).returns(Promise.resolve(participant.participantId))
|
|
292
|
+
Participant.getById.withArgs(participant.participantId).returns(Promise.resolve(participant))
|
|
293
|
+
Participant.createParticipantCurrency.withArgs(participant.participantId, payload.currency, 1).returns(Promise.resolve(participantCurrencyId1))
|
|
294
|
+
Participant.createParticipantCurrency.withArgs(participant.participantId, payload.currency, 2).returns(Promise.resolve(participantCurrencyId2))
|
|
295
|
+
Participant.getParticipantCurrencyById.withArgs(participantCurrencyId1).returns(Promise.resolve(currencyList1))
|
|
296
|
+
Participant.getParticipantCurrencyById.withArgs(participantCurrencyId2).returns(Promise.resolve(currencyList2))
|
|
297
|
+
SettlementModel.getAll.returns(Promise.resolve([]))
|
|
298
|
+
const reply = {
|
|
299
|
+
response: (response) => {
|
|
300
|
+
return {
|
|
301
|
+
code: statusCode => {
|
|
302
|
+
test.deepEqual(response, participantResults[0], 'The results match')
|
|
303
|
+
test.equal(statusCode, 201)
|
|
304
|
+
test.end()
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
await Handler.create(createRequest({ payload }), reply)
|
|
310
|
+
test.fail('should have thrown an error')
|
|
311
|
+
test.end()
|
|
312
|
+
} catch (e) {
|
|
313
|
+
test.ok('should throw an error')
|
|
314
|
+
test.equal(e.message, 'Unable to find a matching or default, Settlement Model')
|
|
315
|
+
test.end()
|
|
316
|
+
}
|
|
317
|
+
})
|
|
318
|
+
|
|
253
319
|
handlerTest.test('create should find the participant and create new account', async function (test) {
|
|
254
320
|
const payload = {
|
|
255
321
|
name: 'fsp1',
|
|
@@ -269,6 +335,7 @@ Test('Participant', participantHandlerTest => {
|
|
|
269
335
|
const currencyList1 = { participantCurrencyId: 1, currencyId: 'USD', ledgerAccountTypeId: 1, isActive: 1, createdBy: 'unknown', createdDate: '2018-07-17T16:04:24.185Z' }
|
|
270
336
|
const currencyList2 = { participantCurrencyId: 2, currencyId: 'USD', ledgerAccountTypeId: 2, isActive: 1, createdBy: 'unknown', createdDate: '2018-07-17T16:04:24.185Z' }
|
|
271
337
|
|
|
338
|
+
SettlementModel.getAll.returns(Promise.resolve(settlementModelFixtures))
|
|
272
339
|
Participant.hubAccountExists.withArgs(participant.currency).returns(Promise.resolve(true))
|
|
273
340
|
Participant.getByName.withArgs(participantFixtures[0].name).returns(Promise.resolve(participant))
|
|
274
341
|
Participant.createParticipantCurrency.withArgs(participant.participantId, payload.currency, 1).returns(Promise.resolve(participantCurrencyId1))
|
|
@@ -332,6 +399,7 @@ Test('Participant', participantHandlerTest => {
|
|
|
332
399
|
}
|
|
333
400
|
|
|
334
401
|
Participant.getByName.withArgs(participantFixtures[0].name).returns(Promise.resolve(participant))
|
|
402
|
+
Participant.validateHubAccounts.throws(new Error('Hub reconciliation account for the specified currency does not exist'))
|
|
335
403
|
try {
|
|
336
404
|
await Handler.create(createRequest({ payload }))
|
|
337
405
|
test.fail('Error not thrown')
|
|
@@ -342,32 +410,6 @@ Test('Participant', participantHandlerTest => {
|
|
|
342
410
|
}
|
|
343
411
|
})
|
|
344
412
|
|
|
345
|
-
handlerTest.test('create should fail if hmlns account does not exists', async function (test) {
|
|
346
|
-
const payload = {
|
|
347
|
-
name: 'fsp1',
|
|
348
|
-
currency: 'USD'
|
|
349
|
-
}
|
|
350
|
-
const participant = {
|
|
351
|
-
participantId: 1,
|
|
352
|
-
name: 'fsp1',
|
|
353
|
-
currency: 'USD',
|
|
354
|
-
isActive: 1,
|
|
355
|
-
createdDate: '2018-07-17T16:04:24.185Z',
|
|
356
|
-
currencyList: []
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
Participant.hubAccountExists.withArgs(participant.currency, Enum.Accounts.LedgerAccountType.HUB_RECONCILIATION).returns(Promise.resolve(true))
|
|
360
|
-
Participant.hubAccountExists.withArgs(participant.currency, Enum.Accounts.LedgerAccountType.HUB_MULTILATERAL_SETTLEMENT).returns(Promise.resolve(false))
|
|
361
|
-
try {
|
|
362
|
-
await Handler.create(createRequest({ payload }))
|
|
363
|
-
test.fail('Error not thrown')
|
|
364
|
-
} catch (e) {
|
|
365
|
-
test.ok(e instanceof Error)
|
|
366
|
-
test.equal(e.message, 'Hub multilateral net settlement account for the specified currency does not exist')
|
|
367
|
-
test.end()
|
|
368
|
-
}
|
|
369
|
-
})
|
|
370
|
-
|
|
371
413
|
handlerTest.test('create should fail if the participant exists with different currency', async function (test) {
|
|
372
414
|
const payload = {
|
|
373
415
|
name: 'fsp1',
|
|
@@ -28,7 +28,7 @@ const Test = require('tape')
|
|
|
28
28
|
const Base = require('../../base')
|
|
29
29
|
const AdminRoutes = require('../../../../src/api/routes')
|
|
30
30
|
const Sinon = require('sinon')
|
|
31
|
-
const
|
|
31
|
+
const Enums = require('../../../../src/lib/enumCached')
|
|
32
32
|
|
|
33
33
|
Test('test root routes - health', async function (assert) {
|
|
34
34
|
const req = Base.buildRequest({ url: '/health', method: 'GET' })
|
|
@@ -41,7 +41,7 @@ Test('test root routes - health', async function (assert) {
|
|
|
41
41
|
|
|
42
42
|
Test('test root routes - enums', async function (assert) {
|
|
43
43
|
const sandbox = Sinon.createSandbox()
|
|
44
|
-
sandbox.stub(
|
|
44
|
+
sandbox.stub(Enums, 'getEnums').returns(Promise.resolve({}))
|
|
45
45
|
const req = Base.buildRequest({ url: '/enums', method: 'GET' })
|
|
46
46
|
const server = await Base.setup(AdminRoutes)
|
|
47
47
|
const res = await server.inject(req)
|
|
@@ -29,9 +29,8 @@ const Test = require('tapes')(require('tape'))
|
|
|
29
29
|
const Sinon = require('sinon')
|
|
30
30
|
const Logger = require('@mojaloop/central-services-logger')
|
|
31
31
|
const Handler = require('../../../../src/api/settlementModels/handler')
|
|
32
|
-
const Sidecar = require('../../../../src/lib/sidecar')
|
|
33
32
|
const SettlementService = require('../../../../src/domain/settlement')
|
|
34
|
-
const
|
|
33
|
+
const EnumCached = require('../../../../src/lib/enumCached')
|
|
35
34
|
const FSPIOPError = require('@mojaloop/central-services-error-handling').Factory.FSPIOPError
|
|
36
35
|
|
|
37
36
|
const createRequest = ({ payload, params, query }) => {
|
|
@@ -95,11 +94,10 @@ Test('SettlementModel', settlementModelHandlerTest => {
|
|
|
95
94
|
]
|
|
96
95
|
settlementModelHandlerTest.beforeEach(test => {
|
|
97
96
|
sandbox = Sinon.createSandbox()
|
|
98
|
-
sandbox.stub(Sidecar)
|
|
99
97
|
sandbox.stub(Logger)
|
|
100
98
|
sandbox.stub(SettlementService)
|
|
101
|
-
sandbox.stub(
|
|
102
|
-
|
|
99
|
+
sandbox.stub(EnumCached)
|
|
100
|
+
EnumCached.getEnums.returns(Promise.resolve({ POSITION: 1, SETTLEMENT: 2, HUB_RECONCILIATION: 3, HUB_MULTILATERAL_SETTLEMENT: 4, HUB_FEE: 5 }))
|
|
103
101
|
test.end()
|
|
104
102
|
})
|
|
105
103
|
|
|
@@ -119,8 +117,7 @@ Test('SettlementModel', settlementModelHandlerTest => {
|
|
|
119
117
|
type: 'POSITION',
|
|
120
118
|
autoPositionReset: true
|
|
121
119
|
}
|
|
122
|
-
SettlementService.
|
|
123
|
-
SettlementService.getByName.returns(Promise.resolve(false))
|
|
120
|
+
SettlementService.createSettlementModel.resolves()
|
|
124
121
|
const reply = {
|
|
125
122
|
response: () => {
|
|
126
123
|
return {
|
|
@@ -134,7 +131,7 @@ Test('SettlementModel', settlementModelHandlerTest => {
|
|
|
134
131
|
await Handler.create({ payload }, reply)
|
|
135
132
|
})
|
|
136
133
|
|
|
137
|
-
handlerTest.test('create should fail if the settlement model
|
|
134
|
+
handlerTest.test('create should fail if the settlement model creation fails', async function (test) {
|
|
138
135
|
const payload = {
|
|
139
136
|
name: 'IMMEDIATE_GROSS',
|
|
140
137
|
settlementGranularity: 'GROSS',
|
|
@@ -145,60 +142,12 @@ Test('SettlementModel', settlementModelHandlerTest => {
|
|
|
145
142
|
type: 'POSITION',
|
|
146
143
|
autoPositionReset: true
|
|
147
144
|
}
|
|
148
|
-
SettlementService.
|
|
149
|
-
SettlementService.getByName.returns(Promise.resolve(true))
|
|
150
|
-
try {
|
|
151
|
-
await Handler.create({ payload })
|
|
152
|
-
test.fail('Error not thrown')
|
|
153
|
-
} catch (e) {
|
|
154
|
-
test.ok(e instanceof Error)
|
|
155
|
-
test.equal(e.message, 'This Settlement Model already exists')
|
|
156
|
-
test.end()
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
handlerTest.test('create should fail if account type does not exists', async function (test) {
|
|
161
|
-
const payload = {
|
|
162
|
-
name: 'DEFERRED_NET',
|
|
163
|
-
settlementGranularity: 'NET',
|
|
164
|
-
settlementInterchange: 'MULTILATERAL',
|
|
165
|
-
settlementDelay: 'DEFERRED',
|
|
166
|
-
settlementCurrency: 'USD',
|
|
167
|
-
requireLiquidityCheck: true,
|
|
168
|
-
type: 'POSITION',
|
|
169
|
-
autoPositionReset: true
|
|
170
|
-
}
|
|
171
|
-
SettlementService.getLedgerAccountTypeName.returns(Promise.resolve(false))
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
await Handler.create({ payload })
|
|
175
|
-
test.fail('Error not thrown')
|
|
176
|
-
} catch (e) {
|
|
177
|
-
test.ok(e instanceof Error)
|
|
178
|
-
test.equal(e.message, 'Ledger account type was not found')
|
|
179
|
-
test.end()
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
handlerTest.test('create should fail if definition is not supported', async function (test) {
|
|
184
|
-
const payload = {
|
|
185
|
-
name: 'DEFERRED_NET',
|
|
186
|
-
settlementGranularity: 'GROSS',
|
|
187
|
-
settlementInterchange: 'MULTILATERAL',
|
|
188
|
-
settlementDelay: 'DEFERRED',
|
|
189
|
-
settlementCurrency: 'USD',
|
|
190
|
-
requireLiquidityCheck: true,
|
|
191
|
-
type: 'POSITION',
|
|
192
|
-
autoPositionReset: true
|
|
193
|
-
}
|
|
194
|
-
SettlementService.getLedgerAccountTypeName.returns(Promise.resolve(false))
|
|
195
|
-
|
|
145
|
+
SettlementService.createSettlementModel.throws()
|
|
196
146
|
try {
|
|
197
147
|
await Handler.create({ payload })
|
|
198
148
|
test.fail('Error not thrown')
|
|
199
149
|
} catch (e) {
|
|
200
150
|
test.ok(e instanceof Error)
|
|
201
|
-
test.equal(e.message, 'Invalid settlement model definition - delay-granularity-interchange combination is not supported')
|
|
202
151
|
test.end()
|
|
203
152
|
}
|
|
204
153
|
})
|
|
@@ -261,6 +210,21 @@ Test('SettlementModel', settlementModelHandlerTest => {
|
|
|
261
210
|
}
|
|
262
211
|
})
|
|
263
212
|
|
|
213
|
+
handlerTest.test('update should update, return settlement model if settlement model when inactive and utilize', async function (test) {
|
|
214
|
+
SettlementService.update.withArgs(settlementModel[0].name, { }).returns(Promise.resolve(settlementModelService[0]))
|
|
215
|
+
try {
|
|
216
|
+
const result = await Handler.update(createRequest({
|
|
217
|
+
params: { name: settlementModel[0].name },
|
|
218
|
+
payload: { }
|
|
219
|
+
}))
|
|
220
|
+
test.deepEqual(result, settlementModel[0], 'The results match')
|
|
221
|
+
test.end()
|
|
222
|
+
} catch (err) {
|
|
223
|
+
test.fail('Error thrown')
|
|
224
|
+
test.end()
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
|
|
264
228
|
handlerTest.test('update should throw error', async function (test) {
|
|
265
229
|
SettlementService.update.withArgs(settlementModel[0].name, { isActive: 1 }).throws(new Error('Test error'))
|
|
266
230
|
try {
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
* ModusBox
|
|
22
|
+
- Lazola Lucas <lazola.lucas@modusbox.com>
|
|
23
|
+
--------------
|
|
24
|
+
******/
|
|
25
|
+
'use strict'
|
|
26
|
+
|
|
27
|
+
const Test = require('tapes')(require('tape'))
|
|
28
|
+
const Sinon = require('sinon')
|
|
29
|
+
const Handler = require('../../../../src/api/transactions/handler')
|
|
30
|
+
const TransactionsService = require('../../../../src/domain/transactions')
|
|
31
|
+
|
|
32
|
+
Test('IlpPackets', IlpPacketsHandlerTest => {
|
|
33
|
+
let sandbox
|
|
34
|
+
const ilpPacket = [{
|
|
35
|
+
transferId: '6d3e964e-9a25-4ff5-a365-2cc5af348321',
|
|
36
|
+
value: 'AQAAAAAAAADIEHByaXZhdGUucGF5ZWVmc3CCAiB7InRyYW5zYWN0aW9uSWQiOiIyZGY3NzRlMi1mMWRiLTRmZjctYTQ5NS0yZGRkMzdhZjdjMmMiLCJxdW90ZUlkIjoiMDNhNjA1NTAtNmYyZi00NTU2LThlMDQtMDcwM2UzOWI4N2ZmIiwicGF5ZWUiOnsicGFydHlJZEluZm8iOnsicGFydHlJZFR5cGUiOiJNU0lTRE4iLCJwYXJ0eUlkZW50aWZpZXIiOiIyNzcxMzgwMzkxMyIsImZzcElkIjoicGF5ZWVmc3AifSwicGVyc29uYWxJbmZvIjp7ImNvbXBsZXhOYW1lIjp7fX19LCJwYXllciI6eyJwYXJ0eUlkSW5mbyI6eyJwYXJ0eUlkVHlwZSI6Ik1TSVNETiIsInBhcnR5SWRlbnRpZmllciI6IjI3NzEzODAzOTExIiwiZnNwSWQiOiJwYXllcmZzcCJ9LCJwZXJzb25hbEluZm8iOnsiY29tcGxleE5hbWUiOnt9fX0sImFtb3VudCI6eyJjdXJyZW5jeSI6IlVTRCIsImFtb3VudCI6IjIwMCJ9LCJ0cmFuc2FjdGlvblR5cGUiOnsic2NlbmFyaW8iOiJERVBPU0lUIiwic3ViU2NlbmFyaW8iOiJERVBPU0lUIiwiaW5pdGlhdG9yIjoiUEFZRVIiLCJpbml0aWF0b3JUeXBlIjoiQ09OU1VNRVIiLCJyZWZ1bmRJbmZvIjp7fX19',
|
|
37
|
+
createdDate: '2020-05-23T17:31:29.000Z'
|
|
38
|
+
}]
|
|
39
|
+
const transferObject = {
|
|
40
|
+
transactionId: '2df774e2-f1db-4ff7-a495-2ddd37af7c2c',
|
|
41
|
+
quoteId: '03a60550-6f2f-4556-8e04-0703e39b87ff',
|
|
42
|
+
payee: {
|
|
43
|
+
partyIdInfo: {
|
|
44
|
+
partyIdType: 'MSISDN',
|
|
45
|
+
partyIdentifier: '27713803913',
|
|
46
|
+
fspId: 'payeefsp'
|
|
47
|
+
},
|
|
48
|
+
personalInfo: {
|
|
49
|
+
complexName: {}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
payer: {
|
|
53
|
+
partyIdInfo: {
|
|
54
|
+
partyIdType: 'MSISDN',
|
|
55
|
+
partyIdentifier: '27713803911',
|
|
56
|
+
fspId: 'payerfsp'
|
|
57
|
+
},
|
|
58
|
+
personalInfo: {
|
|
59
|
+
complexName: {}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
amount: {
|
|
63
|
+
currency: 'USD',
|
|
64
|
+
amount: '200'
|
|
65
|
+
},
|
|
66
|
+
transactionType: {
|
|
67
|
+
scenario: 'DEPOSIT',
|
|
68
|
+
subScenario: 'DEPOSIT',
|
|
69
|
+
initiator: 'PAYER',
|
|
70
|
+
initiatorType: 'CONSUMER',
|
|
71
|
+
refundInfo: {}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
IlpPacketsHandlerTest.beforeEach(test => {
|
|
75
|
+
sandbox = Sinon.createSandbox()
|
|
76
|
+
sandbox.stub(TransactionsService)
|
|
77
|
+
test.end()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
IlpPacketsHandlerTest.afterEach(test => {
|
|
81
|
+
sandbox.restore()
|
|
82
|
+
test.end()
|
|
83
|
+
})
|
|
84
|
+
IlpPacketsHandlerTest.test('Handler Test', async handlerTest => {
|
|
85
|
+
handlerTest.test('getById should return ilpPacket for the transfer Id', async function (test) {
|
|
86
|
+
TransactionsService.getById.returns(Promise.resolve(ilpPacket))
|
|
87
|
+
TransactionsService.getTransactionObject.returns(Promise.resolve(transferObject))
|
|
88
|
+
const result = await Handler.getById({ params: { id: ilpPacket[0].transferId } })
|
|
89
|
+
test.deepEqual(result, transferObject, 'The results match')
|
|
90
|
+
test.end()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
handlerTest.test('getByName should throw error', async function (test) {
|
|
94
|
+
TransactionsService.getById.withArgs(ilpPacket[0].transferId).returns(Promise.resolve(null))
|
|
95
|
+
try {
|
|
96
|
+
await Handler.getById({ params: { id: ilpPacket[0].transferId } })
|
|
97
|
+
} catch (e) {
|
|
98
|
+
test.ok(e instanceof Error)
|
|
99
|
+
test.equal(e.message, 'The requested resource could not be found.')
|
|
100
|
+
test.end()
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
handlerTest.end()
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
IlpPacketsHandlerTest.end()
|
|
108
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
* ModusBox
|
|
22
|
+
- Lazola Lucas <lazola.lucas@modusbox.com>
|
|
23
|
+
--------------
|
|
24
|
+
******/
|
|
25
|
+
'use strict'
|
|
26
|
+
|
|
27
|
+
const Test = require('tape')
|
|
28
|
+
const Base = require('../../base')
|
|
29
|
+
const AdminRoutes = require('../../../../src/api/routes')
|
|
30
|
+
|
|
31
|
+
Test('test transactions routes', async function (assert) {
|
|
32
|
+
const req = Base.buildRequest({ url: '/transfers', method: 'GET' })
|
|
33
|
+
const server = await Base.setup(AdminRoutes)
|
|
34
|
+
const res = await server.inject(req)
|
|
35
|
+
assert.ok(res)
|
|
36
|
+
await server.stop()
|
|
37
|
+
assert.end()
|
|
38
|
+
})
|