@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,197 @@
|
|
|
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 Sinon = require('sinon')
|
|
29
|
+
const LedgerAccountTypeModel = require('../../../../src/models/ledgerAccountType/ledgerAccountType')
|
|
30
|
+
|
|
31
|
+
const LedgerAccountTypeService = require('../../../../src/domain/ledgerAccountTypes/index')
|
|
32
|
+
|
|
33
|
+
Test('LedgerAccountTypeService', async (ledgerAccountTypeServiceTest) => {
|
|
34
|
+
let sandbox
|
|
35
|
+
|
|
36
|
+
ledgerAccountTypeServiceTest.beforeEach(t => {
|
|
37
|
+
sandbox = Sinon.createSandbox()
|
|
38
|
+
sandbox.stub(LedgerAccountTypeModel)
|
|
39
|
+
t.end()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
ledgerAccountTypeServiceTest.afterEach(t => {
|
|
43
|
+
sandbox.restore()
|
|
44
|
+
t.end()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
await ledgerAccountTypeServiceTest.test('create when everything is ok', async (assert) => {
|
|
48
|
+
try {
|
|
49
|
+
const payload = {
|
|
50
|
+
name: 'INTERCHANGE_FEE_SETTLEMENT',
|
|
51
|
+
description: 'settlement account type for interchange fees',
|
|
52
|
+
isActive: true,
|
|
53
|
+
isSettleable: true,
|
|
54
|
+
createdDate: '2018-10-11T11:45:00.000Z'
|
|
55
|
+
}
|
|
56
|
+
const ledgerAccountTypeId = 127
|
|
57
|
+
LedgerAccountTypeModel.create.resolves(ledgerAccountTypeId)
|
|
58
|
+
|
|
59
|
+
const expected = await LedgerAccountTypeService.create(payload.name, payload.description, payload.isActive, payload.isSettleable)
|
|
60
|
+
assert.equal(LedgerAccountTypeModel.create.callCount, 1, 'should call the model create function')
|
|
61
|
+
assert.equal(LedgerAccountTypeModel.create.lastCall.args[0], payload.name, 'should call the model with the right argument: name')
|
|
62
|
+
assert.equal(LedgerAccountTypeModel.create.lastCall.args[1], payload.description, 'should call the model with the right argument: description')
|
|
63
|
+
assert.equal(LedgerAccountTypeModel.create.lastCall.args[2], payload.isActive, 'should call the model with the right argument: isActive')
|
|
64
|
+
assert.equal(LedgerAccountTypeModel.create.lastCall.args[3], payload.isSettleable, 'should call the model with the right argument: isSettleable')
|
|
65
|
+
assert.equal(expected, true, 'should return true')
|
|
66
|
+
assert.end()
|
|
67
|
+
} catch (err) {
|
|
68
|
+
assert.fail(`Error thrown ${err}`, 'should have not thrown an error')
|
|
69
|
+
assert.end()
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
await ledgerAccountTypeServiceTest.test('create when default arguments are not passed', async (assert) => {
|
|
74
|
+
try {
|
|
75
|
+
const payload = {
|
|
76
|
+
name: 'INTERCHANGE_FEE_SETTLEMENT',
|
|
77
|
+
description: 'settlement account type for interchange fees',
|
|
78
|
+
isActive: false,
|
|
79
|
+
isSettleable: false,
|
|
80
|
+
createdDate: '2018-10-11T11:45:00.000Z'
|
|
81
|
+
}
|
|
82
|
+
LedgerAccountTypeModel.create.resolves(payload)
|
|
83
|
+
const expected = await LedgerAccountTypeService.create(payload.name, payload.description)
|
|
84
|
+
assert.equal(LedgerAccountTypeModel.create.callCount, 1, 'should call the model create function')
|
|
85
|
+
assert.equal(LedgerAccountTypeModel.create.lastCall.args[0], payload.name, 'should call the model with the right argument: name')
|
|
86
|
+
assert.equal(LedgerAccountTypeModel.create.lastCall.args[1], payload.description, 'should call the model with the right argument: description')
|
|
87
|
+
assert.equal(LedgerAccountTypeModel.create.lastCall.args[2], false, 'should call the model with the right default argument: isActive: false')
|
|
88
|
+
assert.equal(LedgerAccountTypeModel.create.lastCall.args[3], false, 'should call the model with the right default argument: isSettleable: false')
|
|
89
|
+
assert.equal(expected, true, 'should return true')
|
|
90
|
+
assert.end()
|
|
91
|
+
} catch (err) {
|
|
92
|
+
assert.fail('Error thrown', 'should have not thrown an error')
|
|
93
|
+
assert.end()
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
await ledgerAccountTypeServiceTest.test('create when LedgerAccountTypeModel service fails', async (assert) => {
|
|
98
|
+
try {
|
|
99
|
+
const payload = {
|
|
100
|
+
name: 'INTERCHANGE_FEE_SETTLEMENT',
|
|
101
|
+
description: 'settlement account type for interchange fees',
|
|
102
|
+
isActive: true,
|
|
103
|
+
isSettleable: true
|
|
104
|
+
}
|
|
105
|
+
LedgerAccountTypeModel.create.throws(new Error())
|
|
106
|
+
await LedgerAccountTypeService.create(payload.name, payload.description, payload.isActive, payload.isSettleable)
|
|
107
|
+
assert.fail('Error not thrown', 'should have thrown an error')
|
|
108
|
+
assert.end()
|
|
109
|
+
} catch (err) {
|
|
110
|
+
assert.equal(LedgerAccountTypeModel.create.callCount, 1, 'should call the model create function')
|
|
111
|
+
assert.ok(err instanceof Error, 'should throw an error')
|
|
112
|
+
assert.end()
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
await ledgerAccountTypeServiceTest.test('getAll should return all ledgerAccountTypes model', async (assert) => {
|
|
117
|
+
const payload = [
|
|
118
|
+
{
|
|
119
|
+
name: 'INTERCHANGE_FEE_SETTLEMENT',
|
|
120
|
+
description: 'settlement account type for interchange fees',
|
|
121
|
+
isActive: true,
|
|
122
|
+
isSettleable: true,
|
|
123
|
+
createdDate: '2018-10-11T11:45:00.000Z'
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'INTERCHANGE_FEE_2_SETTLEMENT',
|
|
127
|
+
description: 'settlement account type for interchange fees type 2',
|
|
128
|
+
isActive: true,
|
|
129
|
+
isSettleable: true,
|
|
130
|
+
createdDate: '2018-10-11T12:45:00.000Z'
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
LedgerAccountTypeModel.getAll.resolves(payload)
|
|
136
|
+
const result = await LedgerAccountTypeService.getAll()
|
|
137
|
+
assert.deepEqual(result, payload, 'should return an array of ledger Account types models')
|
|
138
|
+
assert.equal(LedgerAccountTypeModel.getAll.callCount, 1, 'should call the model getAll function')
|
|
139
|
+
assert.equal(LedgerAccountTypeModel.getAll.lastCall.args[0], undefined, 'should call the model with getAll function with no parameters')
|
|
140
|
+
assert.end()
|
|
141
|
+
} catch (err) {
|
|
142
|
+
assert.assert(err instanceof Error, ` throws ${err} `)
|
|
143
|
+
assert.end()
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
await ledgerAccountTypeServiceTest.test('getAll should throw an error if the LedgerAccountTypeModel service fails', async (assert) => {
|
|
148
|
+
try {
|
|
149
|
+
LedgerAccountTypeModel.getAll.rejects(new Error('Error message'))
|
|
150
|
+
await LedgerAccountTypeService.getAll()
|
|
151
|
+
assert.fail('Error not thrown', 'should have thrown an error')
|
|
152
|
+
assert.end()
|
|
153
|
+
} catch (err) {
|
|
154
|
+
assert.assert(err instanceof Error, 'should throw an error')
|
|
155
|
+
assert.ok(err.message, 'Error message', 'should throw the right error message')
|
|
156
|
+
|
|
157
|
+
assert.end()
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
await ledgerAccountTypeServiceTest.test('getByName should return one ledgerAccountTypes if found', async (assert) => {
|
|
162
|
+
const payload = {
|
|
163
|
+
name: 'INTERCHANGE_FEE_SETTLEMENT',
|
|
164
|
+
description: 'settlement account type for interchange fees',
|
|
165
|
+
isActive: true,
|
|
166
|
+
isSettleable: true,
|
|
167
|
+
createdDate: '2018-10-11T11:45:00.000Z'
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
LedgerAccountTypeModel.getLedgerAccountByName.resolves(payload)
|
|
171
|
+
const result = await LedgerAccountTypeService.getByName(payload.name)
|
|
172
|
+
assert.deepEqual(result, payload, 'should return one ledger Account type models')
|
|
173
|
+
assert.equal(LedgerAccountTypeModel.getLedgerAccountByName.callCount, 1, 'should call the model getLedgerAccountByName function')
|
|
174
|
+
assert.equal(LedgerAccountTypeModel.getLedgerAccountByName.lastCall.args[0], payload.name, 'should call the model getLedgerAccountByName function with the name parameter')
|
|
175
|
+
assert.end()
|
|
176
|
+
} catch (err) {
|
|
177
|
+
assert.fail(err instanceof Error, ` throws ${err} `)
|
|
178
|
+
assert.end()
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
await ledgerAccountTypeServiceTest.test('getByName should throw an error if the LedgerAccountTypeModel service fails', async (assert) => {
|
|
183
|
+
try {
|
|
184
|
+
LedgerAccountTypeModel.getLedgerAccountByName.rejects(new Error('Error message'))
|
|
185
|
+
|
|
186
|
+
await LedgerAccountTypeService.getByName('settlement')
|
|
187
|
+
assert.fail('Error not thrown', 'should have thrown an error')
|
|
188
|
+
assert.end()
|
|
189
|
+
} catch (err) {
|
|
190
|
+
assert.assert(err instanceof Error, 'should throw an error')
|
|
191
|
+
assert.ok(err.message, 'Error message', 'should throw the right error message')
|
|
192
|
+
assert.end()
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
await ledgerAccountTypeServiceTest.end()
|
|
197
|
+
})
|
|
@@ -40,6 +40,7 @@ const ParticipantPositionChangeModel = require('../../../../src/models/participa
|
|
|
40
40
|
const LedgerAccountTypeFacade = require('../../../../src/models/participant/facade')
|
|
41
41
|
const Kafka = require('@mojaloop/central-services-shared').Util.Kafka
|
|
42
42
|
const LedgerAccountTypeModel = require('../../../../src/models/ledgerAccountType/ledgerAccountType')
|
|
43
|
+
const EnumCached = require('../../../../src/lib/enumCached')
|
|
43
44
|
|
|
44
45
|
const Service = require('../../../../src/domain/participant/index')
|
|
45
46
|
|
|
@@ -69,7 +70,7 @@ Test('Participant service', async (participantTest) => {
|
|
|
69
70
|
currency: 'USD',
|
|
70
71
|
isActive: 1,
|
|
71
72
|
createdDate: new Date(),
|
|
72
|
-
currencyList: 'USD'
|
|
73
|
+
currencyList: ['USD']
|
|
73
74
|
},
|
|
74
75
|
{
|
|
75
76
|
participantId: 1,
|
|
@@ -77,7 +78,7 @@ Test('Participant service', async (participantTest) => {
|
|
|
77
78
|
currency: 'EUR',
|
|
78
79
|
isActive: 1,
|
|
79
80
|
createdDate: new Date(),
|
|
80
|
-
currencyList: 'EUR'
|
|
81
|
+
currencyList: ['EUR']
|
|
81
82
|
}
|
|
82
83
|
]
|
|
83
84
|
const participantCurrencyResult = [
|
|
@@ -138,6 +139,7 @@ Test('Participant service', async (participantTest) => {
|
|
|
138
139
|
sandbox.stub(ParticipantCurrencyModel, 'getById')
|
|
139
140
|
sandbox.stub(ParticipantCurrencyModel, 'destroyByParticipantId')
|
|
140
141
|
sandbox.stub(ParticipantCurrencyModel, 'findOneByParams')
|
|
142
|
+
sandbox.stub(ParticipantCurrencyModel, 'hubAccountExists')
|
|
141
143
|
|
|
142
144
|
sandbox.stub(ParticipantFacade, 'getEndpoint')
|
|
143
145
|
sandbox.stub(ParticipantFacade, 'getAllEndpoints')
|
|
@@ -150,6 +152,7 @@ Test('Participant service', async (participantTest) => {
|
|
|
150
152
|
sandbox.stub(ParticipantFacade, 'getAllAccountsByNameAndCurrency')
|
|
151
153
|
sandbox.stub(ParticipantFacade, 'addHubAccountAndInitPosition')
|
|
152
154
|
sandbox.stub(ParticipantFacade, 'getLimitsForAllParticipants')
|
|
155
|
+
sandbox.stub(ParticipantFacade, 'getAllNonHubParticipantsWithCurrencies')
|
|
153
156
|
|
|
154
157
|
sandbox.stub(ParticipantLimitModel, 'getByParticipantCurrencyId')
|
|
155
158
|
sandbox.stub(ParticipantLimitModel, 'destroyByParticipantCurrencyId')
|
|
@@ -157,6 +160,7 @@ Test('Participant service', async (participantTest) => {
|
|
|
157
160
|
sandbox.stub(ParticipantPositionModel, 'getByParticipantCurrencyId')
|
|
158
161
|
sandbox.stub(ParticipantPositionModel, 'destroyByParticipantCurrencyId')
|
|
159
162
|
sandbox.stub(ParticipantPositionModel, 'destroyByParticipantId')
|
|
163
|
+
sandbox.stub(ParticipantPositionModel, 'createParticipantPositionRecords')
|
|
160
164
|
|
|
161
165
|
sandbox.stub(ParticipantPositionChangeModel, 'getByParticipantPositionId')
|
|
162
166
|
|
|
@@ -166,6 +170,9 @@ Test('Participant service', async (participantTest) => {
|
|
|
166
170
|
sandbox.stub(LedgerAccountTypeModel, 'getLedgerAccountByName')
|
|
167
171
|
|
|
168
172
|
sandbox.stub(Kafka, 'produceGeneralMessage')
|
|
173
|
+
sandbox.stub(EnumCached)
|
|
174
|
+
EnumCached.getEnums.returns(Promise.resolve({ POSITION: 1, SETTLEMENT: 2, HUB_RECONCILIATION: 3, HUB_MULTILATERAL_SETTLEMENT: 4, HUB_FEE: 5 }))
|
|
175
|
+
|
|
169
176
|
Db.participant = {
|
|
170
177
|
insert: sandbox.stub(),
|
|
171
178
|
update: sandbox.stub(),
|
|
@@ -181,6 +188,10 @@ Test('Participant service', async (participantTest) => {
|
|
|
181
188
|
destroy: sandbox.stub()
|
|
182
189
|
}
|
|
183
190
|
|
|
191
|
+
Db.from = (table) => {
|
|
192
|
+
return Db[table]
|
|
193
|
+
}
|
|
194
|
+
|
|
184
195
|
participantFixtures.forEach((participant, index) => {
|
|
185
196
|
participantMap.set(index + 1, participantResult[index])
|
|
186
197
|
Db.participant.insert.withArgs({ participant }).returns(index)
|
|
@@ -641,6 +652,7 @@ Test('Participant service', async (participantTest) => {
|
|
|
641
652
|
const settlementAccount = {
|
|
642
653
|
participantCurrencyId: 2
|
|
643
654
|
}
|
|
655
|
+
payload.name = participant.name
|
|
644
656
|
ParticipantFacade.getByNameAndCurrency.withArgs(participant.name, payload.currency, 1).returns(participant)
|
|
645
657
|
ParticipantFacade.getByNameAndCurrency.withArgs(participant.name, payload.currency, 2).returns(settlementAccount)
|
|
646
658
|
ParticipantLimitModel.getByParticipantCurrencyId.withArgs(participant.participantCurrencyId).returns(null)
|
|
@@ -687,6 +699,7 @@ Test('Participant service', async (participantTest) => {
|
|
|
687
699
|
const settlementAccount = {
|
|
688
700
|
participantCurrencyId: 2
|
|
689
701
|
}
|
|
702
|
+
limitPositionObj.name = participant.name
|
|
690
703
|
ParticipantFacade.getByNameAndCurrency.withArgs(participant.name, payload.currency, 1).returns(participant)
|
|
691
704
|
ParticipantFacade.getByNameAndCurrency.withArgs(participant.name, payload.currency, 2).returns(settlementAccount)
|
|
692
705
|
ParticipantLimitModel.getByParticipantCurrencyId.withArgs(participant.participantCurrencyId).returns(null)
|
|
@@ -2073,5 +2086,105 @@ Test('Participant service', async (participantTest) => {
|
|
|
2073
2086
|
}
|
|
2074
2087
|
})
|
|
2075
2088
|
|
|
2089
|
+
await participantTest.test('validateHubAccounts should', async (assert) => {
|
|
2090
|
+
try {
|
|
2091
|
+
const currency = 'USD'
|
|
2092
|
+
ParticipantCurrencyModel.hubAccountExists.withArgs(currency, 3).resolves(true)
|
|
2093
|
+
ParticipantCurrencyModel.hubAccountExists.withArgs(currency, 4).resolves(true)
|
|
2094
|
+
const result = await Service.validateHubAccounts(currency)
|
|
2095
|
+
assert.equal(result, true, 'return true')
|
|
2096
|
+
assert.end()
|
|
2097
|
+
} catch (err) {
|
|
2098
|
+
Logger.error(`validateHubAccounts failed with error - ${err}`)
|
|
2099
|
+
assert.fail()
|
|
2100
|
+
assert.end()
|
|
2101
|
+
}
|
|
2102
|
+
})
|
|
2103
|
+
|
|
2104
|
+
await participantTest.test('validateHubAccounts should throw error when hub reconciliation account does not exist', async (assert) => {
|
|
2105
|
+
try {
|
|
2106
|
+
const currency = 'USD'
|
|
2107
|
+
ParticipantCurrencyModel.hubAccountExists.withArgs(currency, 3).resolves(false)
|
|
2108
|
+
ParticipantCurrencyModel.hubAccountExists.withArgs(currency, 4).resolves(true)
|
|
2109
|
+
await Service.validateHubAccounts(currency)
|
|
2110
|
+
assert.fail('should throw')
|
|
2111
|
+
assert.end()
|
|
2112
|
+
} catch (err) {
|
|
2113
|
+
Logger.error(`validateHubAccounts failed with error - ${err}`)
|
|
2114
|
+
assert.equal(err.message, 'Hub reconciliation account for the specified currency does not exist', 'throws Hub reconciliation account for the specified currency does not exist')
|
|
2115
|
+
assert.end()
|
|
2116
|
+
}
|
|
2117
|
+
})
|
|
2118
|
+
|
|
2119
|
+
await participantTest.test('validateHubAccounts should throw error when hub settlement account does not exist', async (assert) => {
|
|
2120
|
+
try {
|
|
2121
|
+
const currency = 'USD'
|
|
2122
|
+
ParticipantCurrencyModel.hubAccountExists.withArgs(currency, 3).resolves(true)
|
|
2123
|
+
ParticipantCurrencyModel.hubAccountExists.withArgs(currency, 4).resolves(false)
|
|
2124
|
+
await Service.validateHubAccounts(currency)
|
|
2125
|
+
assert.fail('should throw')
|
|
2126
|
+
assert.end()
|
|
2127
|
+
} catch (err) {
|
|
2128
|
+
Logger.error(`validateHubAccounts failed with error - ${err}`)
|
|
2129
|
+
assert.equal(err.message, 'Hub multilateral net settlement account for the specified currency does not exist', 'throws Hub multilateral net settlement account for the specified currency does not exist')
|
|
2130
|
+
assert.end()
|
|
2131
|
+
}
|
|
2132
|
+
})
|
|
2133
|
+
|
|
2134
|
+
await participantTest.test('createAssociatedParticipantAccounts should create ParticipantPositionRecords records', async (assert) => {
|
|
2135
|
+
try {
|
|
2136
|
+
const currency = 'AUD'
|
|
2137
|
+
const ledgerAccountTypeId = 127
|
|
2138
|
+
const existingParticipantWithCurrencies = [
|
|
2139
|
+
{
|
|
2140
|
+
participantCurrencyId: 2,
|
|
2141
|
+
participantId: '2',
|
|
2142
|
+
currencyId: 'USD'
|
|
2143
|
+
}
|
|
2144
|
+
]
|
|
2145
|
+
|
|
2146
|
+
ParticipantFacade.getAllNonHubParticipantsWithCurrencies.resolves(existingParticipantWithCurrencies)
|
|
2147
|
+
|
|
2148
|
+
ParticipantCurrencyModel.getByParticipantId.resolves(['EUR', 'USD'])
|
|
2149
|
+
ParticipantCurrencyModel.create.resolves(1)
|
|
2150
|
+
ParticipantModelCached.getById.withArgs('1').resolves(participantResult[1])
|
|
2151
|
+
ParticipantModelCached.getById.withArgs('2').resolves(participantResult[0])
|
|
2152
|
+
ParticipantPositionModel.createParticipantPositionRecords.resolves(true)
|
|
2153
|
+
await Service.createAssociatedParticipantAccounts(currency, ledgerAccountTypeId)
|
|
2154
|
+
assert.equal(ParticipantFacade.getAllNonHubParticipantsWithCurrencies.callCount, 1, 'should retrieve non HUB Participants with currencies')
|
|
2155
|
+
assert.deepEqual(ParticipantCurrencyModel.create.callCount, 1, 'should call the create partipant currency record function')
|
|
2156
|
+
assert.equal(ParticipantCurrencyModel.create.lastCall.args[1], 'AUD', 'should call the create partipant currency records function with currency AUD')
|
|
2157
|
+
assert.equal(ParticipantCurrencyModel.create.lastCall.args[2], 127, 'should call the create partipant currency records function with ledgerAccountTypeId')
|
|
2158
|
+
|
|
2159
|
+
assert.equal(ParticipantPositionModel.createParticipantPositionRecords.callCount, 1, 'should call the model create function')
|
|
2160
|
+
const expectedParticipantPositionArg = [
|
|
2161
|
+
{ participantCurrencyId: 1, value: 0, reservedValue: 0 }
|
|
2162
|
+
]
|
|
2163
|
+
assert.deepEqual(ParticipantPositionModel.createParticipantPositionRecords.lastCall.args[0], expectedParticipantPositionArg, 'should call the create partipant position records function with the right arguments')
|
|
2164
|
+
|
|
2165
|
+
assert.end()
|
|
2166
|
+
} catch (err) {
|
|
2167
|
+
console.log(err)
|
|
2168
|
+
assert.fail(err instanceof Error, ` throws ${err} `)
|
|
2169
|
+
assert.end()
|
|
2170
|
+
}
|
|
2171
|
+
})
|
|
2172
|
+
|
|
2173
|
+
await participantTest.test('createAssociatedParticipantAccounts should throw an error if the LedgerAccountTypeModel service fails', async (assert) => {
|
|
2174
|
+
try {
|
|
2175
|
+
ParticipantFacade.getAllNonHubParticipantsWithCurrencies.rejects(new Error('Error message'))
|
|
2176
|
+
const ledgerAccountTypeId = 127
|
|
2177
|
+
const currency = 'AUD'
|
|
2178
|
+
|
|
2179
|
+
await Service.createAssociatedParticipantAccounts(currency, ledgerAccountTypeId)
|
|
2180
|
+
assert.fail('Error not thrown', 'should have thrown an error')
|
|
2181
|
+
assert.end()
|
|
2182
|
+
} catch (err) {
|
|
2183
|
+
assert.assert(err instanceof Error, 'should throw an error')
|
|
2184
|
+
assert.ok(err.message, 'Error message', 'should throw the right error message')
|
|
2185
|
+
assert.end()
|
|
2186
|
+
}
|
|
2187
|
+
})
|
|
2188
|
+
|
|
2076
2189
|
await participantTest.end()
|
|
2077
2190
|
})
|
|
@@ -33,6 +33,7 @@ const LedgerAccountTypeModel = require('../../../../src/models/ledgerAccountType
|
|
|
33
33
|
const Logger = require('@mojaloop/central-services-logger')
|
|
34
34
|
|
|
35
35
|
const SettlementService = require('../../../../src/domain/settlement/index')
|
|
36
|
+
const ParticipantService = require('../../../../src/domain/participant')
|
|
36
37
|
|
|
37
38
|
Test('SettlementModel SettlementService', async (settlementModelTest) => {
|
|
38
39
|
let sandbox
|
|
@@ -40,6 +41,8 @@ Test('SettlementModel SettlementService', async (settlementModelTest) => {
|
|
|
40
41
|
settlementModelTest.beforeEach(t => {
|
|
41
42
|
sandbox = Sinon.createSandbox()
|
|
42
43
|
sandbox.stub(LedgerAccountTypeModel, 'getLedgerAccountByName')
|
|
44
|
+
sandbox.stub(ParticipantService, 'createAssociatedParticipantAccounts')
|
|
45
|
+
sandbox.stub(ParticipantService, 'validateHubAccounts')
|
|
43
46
|
|
|
44
47
|
Db.settlementModel = {
|
|
45
48
|
insert: sandbox.stub(),
|
|
@@ -71,15 +74,204 @@ Test('SettlementModel SettlementService', async (settlementModelTest) => {
|
|
|
71
74
|
}
|
|
72
75
|
]
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
//
|
|
78
|
+
await settlementModelTest.test('create should fail if ledger account type does not exists', async function (test) {
|
|
75
79
|
try {
|
|
80
|
+
const payload = {
|
|
81
|
+
name: 'DEFERRED_NET',
|
|
82
|
+
settlementGranularity: 'NET',
|
|
83
|
+
settlementInterchange: 'MULTILATERAL',
|
|
84
|
+
settlementDelay: 'DEFERRED',
|
|
85
|
+
settlementCurrency: 'USD',
|
|
86
|
+
requireLiquidityCheck: true,
|
|
87
|
+
type: 'POSITION',
|
|
88
|
+
autoPositionReset: true
|
|
89
|
+
}
|
|
76
90
|
sandbox.stub(SettlementModel, 'create')
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
ParticipantService.validateHubAccounts.resolves(true)
|
|
92
|
+
|
|
93
|
+
await SettlementService.createSettlementModel(payload, {})
|
|
94
|
+
test.fail('should have thrown an error')
|
|
95
|
+
test.end()
|
|
80
96
|
} catch (err) {
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
console.log(err)
|
|
98
|
+
test.ok(err instanceof Error, 'should throw an error')
|
|
99
|
+
test.equal(err.message, 'Ledger account type was not found', 'throws Ledger account type was not found')
|
|
100
|
+
test.end()
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
await settlementModelTest.test('create should fail if settlement account type does not exists', async function (test) {
|
|
104
|
+
try {
|
|
105
|
+
const payload = {
|
|
106
|
+
name: 'DEFERRED_NET',
|
|
107
|
+
settlementGranularity: 'NET',
|
|
108
|
+
settlementInterchange: 'MULTILATERAL',
|
|
109
|
+
settlementDelay: 'DEFERRED',
|
|
110
|
+
settlementCurrency: 'USD',
|
|
111
|
+
requireLiquidityCheck: true,
|
|
112
|
+
type: 'POSITION',
|
|
113
|
+
autoPositionReset: true,
|
|
114
|
+
ledgerAccountType: 'SETTLEMENT',
|
|
115
|
+
settlementAccountType: 'POSITION'
|
|
116
|
+
}
|
|
117
|
+
sandbox.stub(SettlementModel, 'create')
|
|
118
|
+
LedgerAccountTypeModel.getLedgerAccountByName.resolves(true)
|
|
119
|
+
LedgerAccountTypeModel.getLedgerAccountByName.withArgs(payload.settlementAccountType).returns(Promise.resolve(false))
|
|
120
|
+
|
|
121
|
+
await SettlementService.createSettlementModel(payload, {})
|
|
122
|
+
test.fail('should have thrown an error')
|
|
123
|
+
test.end()
|
|
124
|
+
} catch (err) {
|
|
125
|
+
test.ok(err instanceof Error, 'should throw an error')
|
|
126
|
+
test.equal(err.message, 'Settlement account type was not found', 'throws Settlement account type was not found')
|
|
127
|
+
test.end()
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
await settlementModelTest.test('create should fail if definition is not supported', async function (test) {
|
|
132
|
+
try {
|
|
133
|
+
const payload = {
|
|
134
|
+
name: 'DEFERRED_NET',
|
|
135
|
+
settlementGranularity: 'GROSS',
|
|
136
|
+
settlementInterchange: 'MULTILATERAL',
|
|
137
|
+
settlementDelay: 'DEFERRED',
|
|
138
|
+
settlementCurrency: 'USD',
|
|
139
|
+
requireLiquidityCheck: true,
|
|
140
|
+
type: 'POSITION',
|
|
141
|
+
autoPositionReset: true
|
|
142
|
+
}
|
|
143
|
+
sandbox.stub(SettlementModel, 'create')
|
|
144
|
+
LedgerAccountTypeModel.getLedgerAccountByName.resolves(false)
|
|
145
|
+
|
|
146
|
+
await SettlementService.createSettlementModel(payload, {})
|
|
147
|
+
test.fail('should have thrown an error')
|
|
148
|
+
test.end()
|
|
149
|
+
} catch (err) {
|
|
150
|
+
test.ok(err instanceof Error, 'should throw an error')
|
|
151
|
+
test.equal(err.message, 'Invalid settlement model definition - delay-granularity-interchange combination is not supported', 'throws definition not supported error')
|
|
152
|
+
test.end()
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
await settlementModelTest.test('create should not create a settlementModel if it already exists', async function (test) {
|
|
157
|
+
try {
|
|
158
|
+
const payload = {
|
|
159
|
+
name: 'DEFERRED_NET',
|
|
160
|
+
settlementGranularity: 'NET',
|
|
161
|
+
settlementInterchange: 'MULTILATERAL',
|
|
162
|
+
settlementDelay: 'DEFERRED',
|
|
163
|
+
settlementCurrency: 'USD',
|
|
164
|
+
requireLiquidityCheck: true,
|
|
165
|
+
type: 'POSITION',
|
|
166
|
+
autoPositionReset: true,
|
|
167
|
+
ledgerAccountType: 'SETTLEMENT',
|
|
168
|
+
settlementAccountType: 'POSITION'
|
|
169
|
+
}
|
|
170
|
+
sandbox.stub(SettlementModel, 'create')
|
|
171
|
+
LedgerAccountTypeModel.getLedgerAccountByName.resolves({ ledgerAccountTypeId: 1 })
|
|
172
|
+
LedgerAccountTypeModel.getLedgerAccountByName.resolves({ ledgerAccountTypeId: 2 })
|
|
173
|
+
sandbox.stub(SettlementModel, 'getByName').returns(true)
|
|
174
|
+
|
|
175
|
+
const expected = await SettlementService.createSettlementModel(payload, {})
|
|
176
|
+
test.equal(expected, true, 'should return true')
|
|
177
|
+
test.end()
|
|
178
|
+
} catch (err) {
|
|
179
|
+
test.ok(err instanceof Error, 'should throw an error')
|
|
180
|
+
test.equal(err.message, 'Settlement Model already exists', 'throws Settlement Model already exists')
|
|
181
|
+
test.end()
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
await settlementModelTest.test('create should create a settlementModel if it does not exists', async function (test) {
|
|
186
|
+
try {
|
|
187
|
+
const payload = {
|
|
188
|
+
name: 'DEFERRED_NET',
|
|
189
|
+
settlementGranularity: 'NET',
|
|
190
|
+
settlementInterchange: 'MULTILATERAL',
|
|
191
|
+
settlementDelay: 'DEFERRED',
|
|
192
|
+
settlementCurrency: 'USD',
|
|
193
|
+
requireLiquidityCheck: true,
|
|
194
|
+
type: 'POSITION',
|
|
195
|
+
autoPositionReset: true,
|
|
196
|
+
ledgerAccountType: 'SETTLEMENT',
|
|
197
|
+
settlementAccountType: 'POSITION'
|
|
198
|
+
}
|
|
199
|
+
const existingModels = [{
|
|
200
|
+
name: 'DEFERRED_NET_EXISTING',
|
|
201
|
+
settlementGranularity: 'NET',
|
|
202
|
+
settlementInterchange: 'MULTILATERAL',
|
|
203
|
+
settlementDelay: 'DEFERRED',
|
|
204
|
+
settlementCurrency: 'USD',
|
|
205
|
+
requireLiquidityCheck: true,
|
|
206
|
+
type: 'POSITION',
|
|
207
|
+
autoPositionReset: true,
|
|
208
|
+
ledgerAccountType: 'SETTLEMENT',
|
|
209
|
+
settlementAccountType: 'POSITION'
|
|
210
|
+
}]
|
|
211
|
+
sandbox.stub(SettlementModel, 'create')
|
|
212
|
+
LedgerAccountTypeModel.getLedgerAccountByName.resolves({ ledgerAccountTypeId: 1 })
|
|
213
|
+
LedgerAccountTypeModel.getLedgerAccountByName.resolves({ ledgerAccountTypeId: 2 })
|
|
214
|
+
sandbox.stub(SettlementModel, 'getAll').returns(existingModels)
|
|
215
|
+
sandbox.stub(SettlementModel, 'getByName').returns(null)
|
|
216
|
+
|
|
217
|
+
await ParticipantService.createAssociatedParticipantAccounts.resolves(true)
|
|
218
|
+
await ParticipantService.createAssociatedParticipantAccounts.resolves(true)
|
|
219
|
+
|
|
220
|
+
const expected = await SettlementService.createSettlementModel(payload, {})
|
|
221
|
+
test.equal(expected, true, 'should return true')
|
|
222
|
+
test.end()
|
|
223
|
+
} catch (err) {
|
|
224
|
+
test.ok(err instanceof Error, 'should throw an error')
|
|
225
|
+
test.equal(err.message, 'Settlement account type was not found', 'throws Settlement account type was not found')
|
|
226
|
+
test.end()
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
await settlementModelTest.test('create should create a settlementModel with currency if it does not exists', async function (test) {
|
|
231
|
+
try {
|
|
232
|
+
const payload = {
|
|
233
|
+
name: 'DEFERRED_NET',
|
|
234
|
+
settlementGranularity: 'NET',
|
|
235
|
+
settlementInterchange: 'MULTILATERAL',
|
|
236
|
+
settlementDelay: 'DEFERRED',
|
|
237
|
+
settlementCurrency: 'USD',
|
|
238
|
+
requireLiquidityCheck: true,
|
|
239
|
+
type: 'POSITION',
|
|
240
|
+
autoPositionReset: true,
|
|
241
|
+
ledgerAccountType: 'SETTLEMENT',
|
|
242
|
+
settlementAccountType: 'POSITION',
|
|
243
|
+
currency: 'USD'
|
|
244
|
+
}
|
|
245
|
+
const existingModels = [{
|
|
246
|
+
name: 'DEFERRED_NET_EXISTING',
|
|
247
|
+
settlementGranularity: 'NET',
|
|
248
|
+
settlementInterchange: 'MULTILATERAL',
|
|
249
|
+
settlementDelay: 'DEFERRED',
|
|
250
|
+
settlementCurrency: 'USD',
|
|
251
|
+
requireLiquidityCheck: true,
|
|
252
|
+
type: 'POSITION',
|
|
253
|
+
autoPositionReset: true,
|
|
254
|
+
ledgerAccountType: 'SETTLEMENT',
|
|
255
|
+
settlementAccountType: 'POSITION'
|
|
256
|
+
}]
|
|
257
|
+
sandbox.stub(SettlementModel, 'create')
|
|
258
|
+
ParticipantService.validateHubAccounts.resolves(true)
|
|
259
|
+
|
|
260
|
+
LedgerAccountTypeModel.getLedgerAccountByName.resolves({ ledgerAccountTypeId: 1 })
|
|
261
|
+
LedgerAccountTypeModel.getLedgerAccountByName.resolves({ ledgerAccountTypeId: 2 })
|
|
262
|
+
sandbox.stub(SettlementModel, 'getAll').returns(existingModels)
|
|
263
|
+
sandbox.stub(SettlementModel, 'getByName').returns(null)
|
|
264
|
+
|
|
265
|
+
await ParticipantService.createAssociatedParticipantAccounts.resolves(true)
|
|
266
|
+
await ParticipantService.createAssociatedParticipantAccounts.resolves(true)
|
|
267
|
+
|
|
268
|
+
const expected = await SettlementService.createSettlementModel(payload, {})
|
|
269
|
+
test.equal(expected, true, 'should return true')
|
|
270
|
+
test.end()
|
|
271
|
+
} catch (err) {
|
|
272
|
+
test.ok(err instanceof Error, 'should throw an error')
|
|
273
|
+
test.equal(err.message, 'Settlement account type was not found', 'throws Settlement account type was not found')
|
|
274
|
+
test.end()
|
|
83
275
|
}
|
|
84
276
|
})
|
|
85
277
|
|
|
@@ -94,6 +286,7 @@ Test('SettlementModel SettlementService', async (settlementModelTest) => {
|
|
|
94
286
|
assert.end()
|
|
95
287
|
}
|
|
96
288
|
})
|
|
289
|
+
|
|
97
290
|
await settlementModelTest.test('getLedgerAccountType by name name should return ledgerAccountType', async (assert) => {
|
|
98
291
|
const name = {
|
|
99
292
|
currency: 'AFA',
|
|
@@ -141,29 +334,6 @@ Test('SettlementModel SettlementService', async (settlementModelTest) => {
|
|
|
141
334
|
assert.end()
|
|
142
335
|
}
|
|
143
336
|
})
|
|
144
|
-
await settlementModelTest.test('get settlement model by name', async (assert) => {
|
|
145
|
-
try {
|
|
146
|
-
sandbox.stub(SettlementModel, 'getByName').returns(settlementModel)
|
|
147
|
-
const expected = await SettlementService.getByName('test')
|
|
148
|
-
assert.equal(expected, settlementModel)
|
|
149
|
-
assert.end()
|
|
150
|
-
} catch (err) {
|
|
151
|
-
assert.assert(err instanceof Error, ` throws ${err} `)
|
|
152
|
-
assert.end()
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
await settlementModelTest.test('get settlement model by name should throw an error', async (assert) => {
|
|
157
|
-
try {
|
|
158
|
-
sandbox.stub(SettlementModel, 'getByName').throws(new Error())
|
|
159
|
-
await SettlementService.getByName('test')
|
|
160
|
-
assert.fail('Error not thrown')
|
|
161
|
-
assert.end()
|
|
162
|
-
} catch (err) {
|
|
163
|
-
assert.ok(err instanceof Error)
|
|
164
|
-
assert.end()
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
337
|
|
|
168
338
|
await settlementModelTest.test('getAll', async (assert) => {
|
|
169
339
|
try {
|