@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,128 @@
|
|
|
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 Db = require('../../../../src/lib/db')
|
|
30
|
+
const IlpPackets = require('../../../../src/models/ilpPackets/ilpPacket')
|
|
31
|
+
|
|
32
|
+
const TransactionsService = require('../../../../src/domain/transactions/index')
|
|
33
|
+
|
|
34
|
+
Test('Transactions Service', async (transactionsTest) => {
|
|
35
|
+
let sandbox
|
|
36
|
+
|
|
37
|
+
transactionsTest.beforeEach(t => {
|
|
38
|
+
sandbox = Sinon.createSandbox()
|
|
39
|
+
|
|
40
|
+
Db.ilpPacket = {
|
|
41
|
+
find: sandbox.stub()
|
|
42
|
+
}
|
|
43
|
+
t.end()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
transactionsTest.afterEach(t => {
|
|
47
|
+
sandbox.restore()
|
|
48
|
+
t.end()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const ilpPacket = {
|
|
52
|
+
transferId: '6d3e964e-9a25-4ff5-a365-2cc5af348321',
|
|
53
|
+
value: 'AYIC-AAAAAAAAeIfHWcucGF5ZWVmc3AubXNpc2RuLjIyNTU2OTk5MTI1ggLOZXlKMGNtRnVjMkZqZEdsdmJrbGtJam9pTlRWa09ESXdObVV0T0RCaU55MDBPR00wTFRrNU5HTXRaREEyTmpRd01XRXdZbU00SWl3aWNYVnZkR1ZKWkNJNklqRmtPVGhpTkdReExXWmpOVFV0TkRaa09DMDROV1EyTFRnNVl6TXdZMkZoWWpRME5pSXNJbkJoZVdWbElqcDdJbkJoY25SNVNXUkpibVp2SWpwN0luQmhjblI1U1dSVWVYQmxJam9pVFZOSlUwUk9JaXdpY0dGeWRIbEpaR1Z1ZEdsbWFXVnlJam9pTWpJMU5UWTVPVGt4TWpVaUxDSm1jM0JKWkNJNkluQmhlV1ZsWm5Od0luMTlMQ0p3WVhsbGNpSTZleUp3WVhKMGVVbGtTVzVtYnlJNmV5SndZWEowZVVsa1ZIbHdaU0k2SWsxVFNWTkVUaUlzSW5CaGNuUjVTV1JsYm5ScFptbGxjaUk2SWpJeU5UQTNNREE0TVRneElpd2labk53U1dRaU9pSndZWGxsY21aemNDSjlMQ0p3WlhKemIyNWhiRWx1Wm04aU9uc2lZMjl0Y0d4bGVFNWhiV1VpT25zaVptbHljM1JPWVcxbElqb2lUV0YwY3lJc0lteGhjM1JPWVcxbElqb2lTR0ZuYldGdUluMHNJbVJoZEdWUFprSnBjblJvSWpvaU1UazRNeTB4TUMweU5TSjlmU3dpWVcxdmRXNTBJanA3SW1OMWNuSmxibU41SWpvaVZWTkVJaXdpWVcxdmRXNTBJam94TWpNMExqSXpmU3dpZEhKaGJuTmhZM1JwYjI1VWVYQmxJanA3SW5OalpXNWhjbWx2SWpvaVZGSkJUbE5HUlZJaUxDSnBibWwwYVdGMGIzSWlPaUpRUVZsRlVpSXNJbWx1YVhScFlYUnZjbFI1Y0dVaU9pSkRUMDVUVlUxRlVpSjlmUQA',
|
|
54
|
+
createdDate: '2020-05-23T17:31:29.000Z'
|
|
55
|
+
}
|
|
56
|
+
const base64Value = 'AYIC-AAAAAAAAeIfHWcucGF5ZWVmc3AubXNpc2RuLjIyNTU2OTk5MTI1ggLOZXlKMGNtRnVjMkZqZEdsdmJrbGtJam9pTlRWa09ESXdObVV0T0RCaU55MDBPR00wTFRrNU5HTXRaREEyTmpRd01XRXdZbU00SWl3aWNYVnZkR1ZKWkNJNklqRmtPVGhpTkdReExXWmpOVFV0TkRaa09DMDROV1EyTFRnNVl6TXdZMkZoWWpRME5pSXNJbkJoZVdWbElqcDdJbkJoY25SNVNXUkpibVp2SWpwN0luQmhjblI1U1dSVWVYQmxJam9pVFZOSlUwUk9JaXdpY0dGeWRIbEpaR1Z1ZEdsbWFXVnlJam9pTWpJMU5UWTVPVGt4TWpVaUxDSm1jM0JKWkNJNkluQmhlV1ZsWm5Od0luMTlMQ0p3WVhsbGNpSTZleUp3WVhKMGVVbGtTVzVtYnlJNmV5SndZWEowZVVsa1ZIbHdaU0k2SWsxVFNWTkVUaUlzSW5CaGNuUjVTV1JsYm5ScFptbGxjaUk2SWpJeU5UQTNNREE0TVRneElpd2labk53U1dRaU9pSndZWGxsY21aemNDSjlMQ0p3WlhKemIyNWhiRWx1Wm04aU9uc2lZMjl0Y0d4bGVFNWhiV1VpT25zaVptbHljM1JPWVcxbElqb2lUV0YwY3lJc0lteGhjM1JPWVcxbElqb2lTR0ZuYldGdUluMHNJbVJoZEdWUFprSnBjblJvSWpvaU1UazRNeTB4TUMweU5TSjlmU3dpWVcxdmRXNTBJanA3SW1OMWNuSmxibU41SWpvaVZWTkVJaXdpWVcxdmRXNTBJam94TWpNMExqSXpmU3dpZEhKaGJuTmhZM1JwYjI1VWVYQmxJanA3SW5OalpXNWhjbWx2SWpvaVZGSkJUbE5HUlZJaUxDSnBibWwwYVdGMGIzSWlPaUpRUVZsRlVpSXNJbWx1YVhScFlYUnZjbFI1Y0dVaU9pSkRUMDVUVlUxRlVpSjlmUQA=='
|
|
57
|
+
const transactionObject = {
|
|
58
|
+
transactionId: '55d8206e-80b7-48c4-994c-d066401a0bc8',
|
|
59
|
+
quoteId: '1d98b4d1-fc55-46d8-85d6-89c30caab446',
|
|
60
|
+
payee: {
|
|
61
|
+
partyIdInfo: {
|
|
62
|
+
partyIdType: 'MSISDN',
|
|
63
|
+
partyIdentifier: '22556999125',
|
|
64
|
+
fspId: 'payeefsp'
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
payer: {
|
|
68
|
+
partyIdInfo: {
|
|
69
|
+
partyIdType: 'MSISDN',
|
|
70
|
+
partyIdentifier: '22507008181',
|
|
71
|
+
fspId: 'payerfsp'
|
|
72
|
+
},
|
|
73
|
+
personalInfo: {
|
|
74
|
+
complexName: {
|
|
75
|
+
firstName: 'Mats',
|
|
76
|
+
lastName: 'Hagman'
|
|
77
|
+
},
|
|
78
|
+
dateOfBirth: '1983-10-25'
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
amount: {
|
|
82
|
+
currency: 'USD',
|
|
83
|
+
amount: 1234.23
|
|
84
|
+
},
|
|
85
|
+
transactionType: {
|
|
86
|
+
scenario: 'TRANSFER',
|
|
87
|
+
initiator: 'PAYER',
|
|
88
|
+
initiatorType: 'CONSUMER'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
await transactionsTest.test('get ilpPacket object by transfer id', async (assert) => {
|
|
93
|
+
try {
|
|
94
|
+
sandbox.stub(IlpPackets, 'getById').returns(ilpPacket)
|
|
95
|
+
const expected = await TransactionsService.getById('6d3e964e-9a25-4ff5-a365-2cc5af348321')
|
|
96
|
+
assert.equal(expected, ilpPacket)
|
|
97
|
+
assert.end()
|
|
98
|
+
} catch (err) {
|
|
99
|
+
assert.assert(err instanceof Error, ` throws ${err} `)
|
|
100
|
+
assert.end()
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
await transactionsTest.test('get ilpPacket by transfer id should throw an error', async (assert) => {
|
|
105
|
+
try {
|
|
106
|
+
sandbox.stub(IlpPackets, 'getById').throws(new Error())
|
|
107
|
+
await TransactionsService.getById('6d3e964e-9a25-4ff5-a365-2cc5af348321')
|
|
108
|
+
assert.fail('Error not thrown')
|
|
109
|
+
assert.end()
|
|
110
|
+
} catch (err) {
|
|
111
|
+
assert.ok(err instanceof Error)
|
|
112
|
+
assert.end()
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
await transactionsTest.test('get transaction object by transfer id', async (assert) => {
|
|
117
|
+
try {
|
|
118
|
+
const expected = await TransactionsService.getTransactionObject(base64Value)
|
|
119
|
+
assert.deepEqual(expected, transactionObject)
|
|
120
|
+
assert.end()
|
|
121
|
+
} catch (err) {
|
|
122
|
+
assert.assert(err instanceof Error, ` throws ${err} `)
|
|
123
|
+
assert.end()
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
await transactionsTest.end()
|
|
128
|
+
})
|
|
@@ -108,6 +108,7 @@ Test('Transfer Service', transferIndexTest => {
|
|
|
108
108
|
sandbox.stub(TransferDuplicateCheckModel)
|
|
109
109
|
sandbox.stub(TransferFulfilmentDuplicateCheckModel)
|
|
110
110
|
sandbox.stub(TransferErrorDuplicateCheckModel)
|
|
111
|
+
sandbox.stub(Logger, 'isDebugEnabled').value(true)
|
|
111
112
|
t.end()
|
|
112
113
|
})
|
|
113
114
|
|
|
@@ -29,6 +29,7 @@ const Sinon = require('sinon')
|
|
|
29
29
|
const Uuid = require('uuid4')
|
|
30
30
|
const TransformService = require('../../../../src/domain/transfer/transform')
|
|
31
31
|
const Util = require('@mojaloop/central-services-shared').Util
|
|
32
|
+
const Logger = require('@mojaloop/central-services-logger')
|
|
32
33
|
|
|
33
34
|
Test('Transform Service', transformTest => {
|
|
34
35
|
let sandbox
|
|
@@ -36,6 +37,7 @@ Test('Transform Service', transformTest => {
|
|
|
36
37
|
transformTest.beforeEach(t => {
|
|
37
38
|
sandbox = Sinon.createSandbox()
|
|
38
39
|
// sandbox.stub(TransferObjectTransform)
|
|
40
|
+
sandbox.stub(Logger, 'isDebugEnabled').value(true)
|
|
39
41
|
t.end()
|
|
40
42
|
})
|
|
41
43
|
|
|
@@ -42,6 +42,7 @@ const transfer = {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
const currentDate = new Date()
|
|
45
46
|
const transferRecordOutPrepare = {
|
|
46
47
|
transferId: 'b51ec534-ee48-4575-b6a9-ead2955b8999',
|
|
47
48
|
payerFsp: 'dfsp1',
|
|
@@ -54,7 +55,7 @@ const transferRecordOutPrepare = {
|
|
|
54
55
|
},
|
|
55
56
|
ilpPacket: 'AYIBgQAAAAAAAASwNGxldmVsb25lLmRmc3AxLm1lci45T2RTOF81MDdqUUZERmZlakgyOVc4bXFmNEpLMHlGTFGCAUBQU0svMS4wCk5vbmNlOiB1SXlweUYzY3pYSXBFdzVVc05TYWh3CkVuY3J5cHRpb246IG5vbmUKUGF5bWVudC1JZDogMTMyMzZhM2ItOGZhOC00MTYzLTg0NDctNGMzZWQzZGE5OGE3CgpDb250ZW50LUxlbmd0aDogMTM1CkNvbnRlbnQtVHlwZTogYXBwbGljYXRpb24vanNvbgpTZW5kZXItSWRlbnRpZmllcjogOTI4MDYzOTEKCiJ7XCJmZWVcIjowLFwidHJhbnNmZXJDb2RlXCI6XCJpbnZvaWNlXCIsXCJkZWJpdE5hbWVcIjpcImFsaWNlIGNvb3BlclwiLFwiY3JlZGl0TmFtZVwiOlwibWVyIGNoYW50XCIsXCJkZWJpdElkZW50aWZpZXJcIjpcIjkyODA2MzkxXCJ9IgA',
|
|
56
57
|
condition: 'YlK5TZyhflbXaDRPtR5zhCu8FrbgvrQwwmzuH0iQ0AI',
|
|
57
|
-
expirationDate:
|
|
58
|
+
expirationDate: new Date(currentDate.setDate(currentDate.getDate() + 1)),
|
|
58
59
|
extensionList: {
|
|
59
60
|
extension: [
|
|
60
61
|
{
|
|
@@ -310,6 +311,7 @@ Test('Admin handler', adminHandlerTest => {
|
|
|
310
311
|
sandbox.stub(TransferService, 'reconciliationTransferReserve')
|
|
311
312
|
sandbox.stub(TransferService, 'reconciliationTransferCommit')
|
|
312
313
|
sandbox.stub(TransferService, 'reconciliationTransferAbort')
|
|
314
|
+
sandbox.stub(TransferService, 'recordFundsIn')
|
|
313
315
|
sandbox.stub(TransferService, 'getTransferStateChange')
|
|
314
316
|
sandbox.stub(TransferService, 'getTransferState')
|
|
315
317
|
sandbox.stub(TransferService, 'getTransferById')
|
|
@@ -373,9 +375,7 @@ Test('Admin handler', adminHandlerTest => {
|
|
|
373
375
|
|
|
374
376
|
const result = await AdminHandler.transfer(null, Object.assign({}, messages[0]))
|
|
375
377
|
Logger.info(result)
|
|
376
|
-
test.ok(TransferService.
|
|
377
|
-
test.ok(TransferService.reconciliationTransferReserve.callsArgWith(0, trxStub))
|
|
378
|
-
test.ok(TransferService.reconciliationTransferCommit.callsArgWith(0, trxStub))
|
|
378
|
+
test.ok(TransferService.recordFundsIn.callsArgWith(0, trxStub))
|
|
379
379
|
test.equal(result, true)
|
|
380
380
|
test.end()
|
|
381
381
|
} catch (e) {
|
|
@@ -416,7 +416,7 @@ Test('Admin handler', adminHandlerTest => {
|
|
|
416
416
|
hasDuplicateId: false,
|
|
417
417
|
hasDuplicateHash: false
|
|
418
418
|
}))
|
|
419
|
-
TransferService.
|
|
419
|
+
TransferService.recordFundsIn.callsArgWith(0, trxStub).throws(new Error())
|
|
420
420
|
await AdminHandler.transfer(null, Object.assign({}, messages[0]))
|
|
421
421
|
test.fail('Error is not thrown!')
|
|
422
422
|
test.end()
|
|
@@ -0,0 +1,401 @@
|
|
|
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
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Gates Foundation organization for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Gates Foundation
|
|
23
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
|
24
|
+
|
|
25
|
+
* Steven Oderayi <steven.oderayi@modusbox.com>
|
|
26
|
+
--------------
|
|
27
|
+
******/
|
|
28
|
+
'use strict'
|
|
29
|
+
|
|
30
|
+
const Uuid = require('uuid4')
|
|
31
|
+
const Sinon = require('sinon')
|
|
32
|
+
const Proxyquire = require('proxyquire')
|
|
33
|
+
const Test = require('tapes')(require('tape'))
|
|
34
|
+
const EventSdk = require('@mojaloop/event-sdk')
|
|
35
|
+
const Kafka = require('@mojaloop/central-services-shared').Util.Kafka
|
|
36
|
+
const MainUtil = require('@mojaloop/central-services-shared').Util
|
|
37
|
+
const KafkaConsumer = require('@mojaloop/central-services-stream').Kafka.Consumer
|
|
38
|
+
const Consumer = require('@mojaloop/central-services-stream').Util.Consumer
|
|
39
|
+
const Enum = require('@mojaloop/central-services-shared').Enum
|
|
40
|
+
const Comparators = require('@mojaloop/central-services-shared').Util.Comparators
|
|
41
|
+
const Validator = require('../../../../../src/handlers/bulk/shared/validator')
|
|
42
|
+
const BulkTransferService = require('../../../../../src/domain/bulkTransfer')
|
|
43
|
+
const BulkTransferModel = require('../../../../../src/models/bulkTransfer/bulkTransfer')
|
|
44
|
+
const ilp = require('../../../../../src/models/transfer/ilpPacket')
|
|
45
|
+
// const TransferState = Enum.Transfers.TransferState
|
|
46
|
+
// const TransferInternalState = Enum.Transfers.TransferInternalState
|
|
47
|
+
|
|
48
|
+
const bulkTransfer = {
|
|
49
|
+
bulkTransferId: 'fake-bulk-transfer-id',
|
|
50
|
+
bulkQuoteId: 'fake-bulk-quote-id',
|
|
51
|
+
payerFsp: 'dfsp1',
|
|
52
|
+
payeeFsp: 'dfsp2',
|
|
53
|
+
expiration: '2016-05-24T08:38:08.699-04:00',
|
|
54
|
+
individualTransfers: [
|
|
55
|
+
{
|
|
56
|
+
transferId: 'b51ec534-ee48-4575-b6a9-ead2955b8999',
|
|
57
|
+
transferAmount: {
|
|
58
|
+
currency: 'USD',
|
|
59
|
+
amount: '433.88'
|
|
60
|
+
},
|
|
61
|
+
ilpPacket: 'AYIBgQAAAAAAAASwNGxldmVsb25lLmRmc3AxLm1lci45T2RTOF81MDdqUUZERmZlakgyOVc4bXFmNEpLMHlGTFGCAUBQU0svMS4wCk5vbmNlOiB1SXlweUYzY3pYSXBFdzVVc05TYWh3CkVuY3J5cHRpb246IG5vbmUKUGF5bWVudC1JZDogMTMyMzZhM2ItOGZhOC00MTYzLTg0NDctNGMzZWQzZGE5OGE3CgpDb250ZW50LUxlbmd0aDogMTM1CkNvbnRlbnQtVHlwZTogYXBwbGljYXRpb24vanNvbgpTZW5kZXItSWRlbnRpZmllcjogOTI4MDYzOTEKCiJ7XCJmZWVcIjowLFwidHJhbnNmZXJDb2RlXCI6XCJpbnZvaWNlXCIsXCJkZWJpdE5hbWVcIjpcImFsaWNlIGNvb3BlclwiLFwiY3JlZGl0TmFtZVwiOlwibWVyIGNoYW50XCIsXCJkZWJpdElkZW50aWZpZXJcIjpcIjkyODA2MzkxXCJ9IgA',
|
|
62
|
+
condition: 'YlK5TZyhflbXaDRPtR5zhCu8FrbgvrQwwmzuH0iQ0AI'
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
extensionList: {
|
|
66
|
+
extension: [
|
|
67
|
+
{
|
|
68
|
+
key: 'key1',
|
|
69
|
+
value: 'value1'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
key: 'key2',
|
|
73
|
+
value: 'value2'
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const bulkTransferReturn = {
|
|
80
|
+
bulkTransferId: bulkTransfer.bulkTransferId,
|
|
81
|
+
bulkTransferStateId: 'COMPLETED',
|
|
82
|
+
completedTimestamp: new Date().toISOString(),
|
|
83
|
+
payerFsp: 'payerfsp',
|
|
84
|
+
payeeFsp: 'payeefsp',
|
|
85
|
+
bulkQuoteId: bulkTransfer.bulkQuoteId,
|
|
86
|
+
expirationDate: new Date().toISOString()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const messageProtocol = {
|
|
90
|
+
id: Uuid(),
|
|
91
|
+
from: bulkTransfer.payerFsp,
|
|
92
|
+
to: bulkTransfer.payeeFsp,
|
|
93
|
+
type: 'application/json',
|
|
94
|
+
content: {
|
|
95
|
+
headers: {
|
|
96
|
+
'fspiop-source': bulkTransfer.payeeFsp,
|
|
97
|
+
'fspiop-destination': 'source'
|
|
98
|
+
},
|
|
99
|
+
uriParams: { id: bulkTransfer.bulkTransferId }
|
|
100
|
+
},
|
|
101
|
+
metadata: {
|
|
102
|
+
event: {
|
|
103
|
+
id: Uuid(),
|
|
104
|
+
type: Enum.Events.Event.Type.BULK,
|
|
105
|
+
action: Enum.Events.Event.Action.GET,
|
|
106
|
+
createdAt: new Date(),
|
|
107
|
+
state: {
|
|
108
|
+
status: 'success',
|
|
109
|
+
code: 0
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
pp: ''
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const topicName = 'topic-test'
|
|
117
|
+
|
|
118
|
+
const messages = [
|
|
119
|
+
{
|
|
120
|
+
topic: topicName,
|
|
121
|
+
value: messageProtocol
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
const config = {
|
|
126
|
+
options: {
|
|
127
|
+
mode: 2,
|
|
128
|
+
batchSize: 1,
|
|
129
|
+
pollFrequency: 10,
|
|
130
|
+
recursiveTimeout: 100,
|
|
131
|
+
messageCharset: 'utf8',
|
|
132
|
+
messageAsJSON: true,
|
|
133
|
+
sync: true,
|
|
134
|
+
consumeTimeout: 1000
|
|
135
|
+
},
|
|
136
|
+
rdkafkaConf: {
|
|
137
|
+
'client.id': 'kafka-test',
|
|
138
|
+
debug: 'all',
|
|
139
|
+
'group.id': 'central-ledger-kafka',
|
|
140
|
+
'metadata.broker.list': 'localhost:9092',
|
|
141
|
+
'enable.auto.commit': false
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const command = () => { }
|
|
146
|
+
|
|
147
|
+
let SpanStub
|
|
148
|
+
let allBulkTransferHandlers
|
|
149
|
+
|
|
150
|
+
Test('Bulk Transfer GET handler', getHandlerTest => {
|
|
151
|
+
let sandbox
|
|
152
|
+
|
|
153
|
+
getHandlerTest.beforeEach(test => {
|
|
154
|
+
sandbox = Sinon.createSandbox()
|
|
155
|
+
SpanStub = {
|
|
156
|
+
audit: sandbox.stub().callsFake(),
|
|
157
|
+
error: sandbox.stub().callsFake(),
|
|
158
|
+
finish: sandbox.stub().callsFake(),
|
|
159
|
+
debug: sandbox.stub().callsFake(),
|
|
160
|
+
info: sandbox.stub().callsFake(),
|
|
161
|
+
getChild: sandbox.stub().returns(SpanStub),
|
|
162
|
+
setTags: sandbox.stub().callsFake()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const TracerStub = {
|
|
166
|
+
extractContextFromMessage: sandbox.stub().callsFake(() => {
|
|
167
|
+
return {}
|
|
168
|
+
}),
|
|
169
|
+
createChildSpanFromContext: sandbox.stub().callsFake(() => {
|
|
170
|
+
return SpanStub
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const EventSdkStub = {
|
|
175
|
+
Tracer: TracerStub
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
allBulkTransferHandlers = Proxyquire('../../../../../src/handlers/bulk/get/handler', {
|
|
179
|
+
'@mojaloop/event-sdk': EventSdkStub
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
sandbox.stub(KafkaConsumer.prototype, 'constructor').returns(Promise.resolve())
|
|
183
|
+
sandbox.stub(KafkaConsumer.prototype, 'connect').returns(Promise.resolve())
|
|
184
|
+
sandbox.stub(KafkaConsumer.prototype, 'consume').returns(Promise.resolve())
|
|
185
|
+
sandbox.stub(KafkaConsumer.prototype, 'commitMessageSync').returns(Promise.resolve())
|
|
186
|
+
sandbox.stub(Comparators)
|
|
187
|
+
sandbox.stub(Validator)
|
|
188
|
+
sandbox.stub(BulkTransferService)
|
|
189
|
+
sandbox.stub(BulkTransferModel)
|
|
190
|
+
sandbox.stub(Consumer, 'getConsumer').returns({
|
|
191
|
+
commitMessageSync: async function () {
|
|
192
|
+
return true
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
sandbox.stub(Consumer, 'isConsumerAutoCommitEnabled').returns(false)
|
|
196
|
+
sandbox.stub(ilp)
|
|
197
|
+
sandbox.stub(Kafka)
|
|
198
|
+
sandbox.stub(MainUtil.StreamingProtocol)
|
|
199
|
+
Kafka.produceGeneralMessage.returns(Promise.resolve())
|
|
200
|
+
test.end()
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
getHandlerTest.afterEach(test => {
|
|
204
|
+
sandbox.restore()
|
|
205
|
+
test.end()
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
getHandlerTest.test('registerGetBulkTransferHandler should', registerHandlerTest => {
|
|
209
|
+
registerHandlerTest.test('returns true when registering the GET bulk transfer handler', async (test) => {
|
|
210
|
+
await Consumer.createHandler(topicName, config, command)
|
|
211
|
+
Kafka.transformAccountToTopicName.returns(topicName)
|
|
212
|
+
Kafka.proceed.returns(true)
|
|
213
|
+
Kafka.getKafkaConfig.returns(config)
|
|
214
|
+
const result = await allBulkTransferHandlers.registerGetBulkTransferHandler()
|
|
215
|
+
test.equal(result, true)
|
|
216
|
+
test.end()
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
registerHandlerTest.test('return an error when registering GET bulk transfer handler.', async (test) => {
|
|
220
|
+
try {
|
|
221
|
+
await Consumer.createHandler(topicName, config, command)
|
|
222
|
+
Kafka.transformGeneralTopicName.returns(topicName)
|
|
223
|
+
Kafka.getKafkaConfig.throws(new Error())
|
|
224
|
+
await allBulkTransferHandlers.registerGetBulkTransferHandler()
|
|
225
|
+
test.fail('Error not thrown')
|
|
226
|
+
test.end()
|
|
227
|
+
} catch (e) {
|
|
228
|
+
test.pass('Error thrown')
|
|
229
|
+
test.end()
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
registerHandlerTest.end()
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
getHandlerTest.test('get bulk transfer by id should', getBulkTransferTest => {
|
|
236
|
+
getBulkTransferTest.test('return true on a single message', async (test) => {
|
|
237
|
+
const localMessages = MainUtil.clone(messages)
|
|
238
|
+
await Consumer.createHandler(topicName, config, command)
|
|
239
|
+
Kafka.transformAccountToTopicName.returns(topicName)
|
|
240
|
+
Kafka.proceed.returns(true)
|
|
241
|
+
Kafka.getKafkaConfig.returns(config)
|
|
242
|
+
const result = await allBulkTransferHandlers.getBulkTransfer(null, localMessages[0])
|
|
243
|
+
test.equal(result, true)
|
|
244
|
+
test.end()
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
getBulkTransferTest.test('return true on an array of messages', async (test) => {
|
|
248
|
+
const localMessages = MainUtil.clone(messages)
|
|
249
|
+
await Consumer.createHandler(topicName, config, command)
|
|
250
|
+
Kafka.transformAccountToTopicName.returns(topicName)
|
|
251
|
+
Kafka.proceed.returns(true)
|
|
252
|
+
Kafka.getKafkaConfig.returns(config)
|
|
253
|
+
Consumer.isConsumerAutoCommitEnabled.returns(true)
|
|
254
|
+
const result = await allBulkTransferHandlers.getBulkTransfer(null, localMessages)
|
|
255
|
+
test.equal(result, true)
|
|
256
|
+
test.end()
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
getBulkTransferTest.test('return an error when an error is passed in', async (test) => {
|
|
260
|
+
try {
|
|
261
|
+
const localMessages = MainUtil.clone(messages)
|
|
262
|
+
await Consumer.createHandler(topicName, config, command)
|
|
263
|
+
Kafka.transformGeneralTopicName.returns(topicName)
|
|
264
|
+
Kafka.getKafkaConfig.returns(config)
|
|
265
|
+
await allBulkTransferHandlers.getBulkTransfer(true, localMessages)
|
|
266
|
+
test.fail('Error not thrown')
|
|
267
|
+
test.end()
|
|
268
|
+
} catch (e) {
|
|
269
|
+
test.pass('Error thrown')
|
|
270
|
+
test.end()
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
getBulkTransferTest.test('return an error when the Kafka topic is invalid', async (test) => {
|
|
275
|
+
const localMessages = MainUtil.clone(messages)
|
|
276
|
+
await Consumer.createHandler(topicName, config, command)
|
|
277
|
+
Consumer.getConsumer.throws(new Error())
|
|
278
|
+
Kafka.getKafkaConfig.returns(config)
|
|
279
|
+
const result = await allBulkTransferHandlers.getBulkTransfer(null, localMessages)
|
|
280
|
+
test.equal(result, true)
|
|
281
|
+
test.end()
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
getBulkTransferTest.test('return an error when the bulk transfer by id is not found', async (test) => {
|
|
285
|
+
const localMessages = MainUtil.clone(messages)
|
|
286
|
+
await Consumer.createHandler(topicName, config, command)
|
|
287
|
+
Kafka.transformAccountToTopicName.returns(topicName)
|
|
288
|
+
Kafka.proceed.returns(true)
|
|
289
|
+
Kafka.getKafkaConfig.returns(config)
|
|
290
|
+
Validator.validateParticipantByName.returns({ isValid: true })
|
|
291
|
+
BulkTransferService.getParticipantsById.withArgs(bulkTransfer.bulkTransferId).returns({ payeeFsp: bulkTransfer.payeeFsp, payerFsp: bulkTransfer.payerFsp })
|
|
292
|
+
BulkTransferModel.getById.returns(null)
|
|
293
|
+
const result = await allBulkTransferHandlers.getBulkTransfer(null, localMessages)
|
|
294
|
+
test.equal(result, true)
|
|
295
|
+
test.end()
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
getBulkTransferTest.test('return an error when the bulk transfer by id is not found - autocommit enabled', async (test) => {
|
|
299
|
+
const localMessages = MainUtil.clone(messages)
|
|
300
|
+
await Consumer.createHandler(topicName, config, command)
|
|
301
|
+
Kafka.transformAccountToTopicName.returns(topicName)
|
|
302
|
+
Kafka.proceed.returns(true)
|
|
303
|
+
Kafka.getKafkaConfig.returns(config)
|
|
304
|
+
Validator.validateParticipantByName.returns({ isValid: true })
|
|
305
|
+
BulkTransferService.getParticipantsById.withArgs(bulkTransfer.bulkTransferId).returns({ payeeFsp: bulkTransfer.payeeFsp, payerFsp: bulkTransfer.payerFsp })
|
|
306
|
+
BulkTransferModel.getById.returns(null)
|
|
307
|
+
Consumer.isConsumerAutoCommitEnabled.returns(true)
|
|
308
|
+
const result = await allBulkTransferHandlers.getBulkTransfer(null, localMessages)
|
|
309
|
+
test.equal(result, true)
|
|
310
|
+
test.end()
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
getBulkTransferTest.test('return an error when the requester is not involved in the bulk transfer', async (test) => {
|
|
314
|
+
const localMessages = MainUtil.clone(messages)
|
|
315
|
+
await Consumer.createHandler(topicName, config, command)
|
|
316
|
+
Kafka.transformAccountToTopicName.returns(topicName)
|
|
317
|
+
Kafka.proceed.returns(true)
|
|
318
|
+
Kafka.getKafkaConfig.returns(config)
|
|
319
|
+
Validator.validateParticipantByName.returns({ isValid: true })
|
|
320
|
+
Validator.validateParticipantBulkTransferId.returns(false)
|
|
321
|
+
BulkTransferService.getParticipantsById.withArgs(bulkTransfer.bulkTransferId).returns({ payeeFsp: bulkTransfer.payeeFsp, payerFsp: bulkTransfer.payerFsp })
|
|
322
|
+
BulkTransferModel.getById.returns({})
|
|
323
|
+
Consumer.isConsumerAutoCommitEnabled.returns(true)
|
|
324
|
+
localMessages[0].value.from = 'invalidfsp'
|
|
325
|
+
const result = await allBulkTransferHandlers.getBulkTransfer(null, localMessages)
|
|
326
|
+
test.equal(result, true)
|
|
327
|
+
test.end()
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
getBulkTransferTest.test('return an error when the requester is not involved in the bulk transfer - autocommit disabled', async (test) => {
|
|
331
|
+
const localMessages = MainUtil.clone(messages)
|
|
332
|
+
await Consumer.createHandler(topicName, config, command)
|
|
333
|
+
Kafka.transformAccountToTopicName.returns(topicName)
|
|
334
|
+
Kafka.proceed.returns(true)
|
|
335
|
+
Kafka.getKafkaConfig.returns(config)
|
|
336
|
+
Validator.validateParticipantByName.returns({ isValid: true })
|
|
337
|
+
Validator.validateParticipantBulkTransferId.returns(false)
|
|
338
|
+
BulkTransferService.getParticipantsById.withArgs(bulkTransfer.bulkTransferId).returns({ payeeFsp: bulkTransfer.payeeFsp, payerFsp: bulkTransfer.payerFsp })
|
|
339
|
+
BulkTransferModel.getById.returns({})
|
|
340
|
+
Consumer.isConsumerAutoCommitEnabled.returns(false)
|
|
341
|
+
localMessages[0].value.from = 'invalidfsp'
|
|
342
|
+
const result = await allBulkTransferHandlers.getBulkTransfer(null, localMessages)
|
|
343
|
+
test.equal(result, true)
|
|
344
|
+
test.end()
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
getBulkTransferTest.test('return an error when the bulk transfer by id is found - autocommit enabled', async (test) => {
|
|
348
|
+
const localMessages = MainUtil.clone(messages)
|
|
349
|
+
await Consumer.createHandler(topicName, config, command)
|
|
350
|
+
Kafka.transformAccountToTopicName.returns(topicName)
|
|
351
|
+
Kafka.proceed.returns(true)
|
|
352
|
+
Kafka.getKafkaConfig.returns(config)
|
|
353
|
+
Validator.validateParticipantByName.returns({ isValid: true })
|
|
354
|
+
BulkTransferService.getParticipantsById.withArgs(bulkTransfer.bulkTransferId).returns({ payeeFsp: bulkTransfer.payeeFsp, payerFsp: bulkTransfer.payerFsp })
|
|
355
|
+
BulkTransferModel.getById.withArgs(bulkTransfer.bulkTransferId).returns(Promise.resolve(bulkTransferReturn))
|
|
356
|
+
Consumer.isConsumerAutoCommitEnabled.returns(true)
|
|
357
|
+
const result = await allBulkTransferHandlers.getBulkTransfer(null, localMessages)
|
|
358
|
+
test.equal(result, true)
|
|
359
|
+
test.end()
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
getBulkTransferTest.test('log an error when general message cannot be produced', async (test) => {
|
|
363
|
+
const localMessages = MainUtil.clone(messages)
|
|
364
|
+
await Consumer.createHandler(topicName, config, command)
|
|
365
|
+
Kafka.proceed.throws(new Error())
|
|
366
|
+
Validator.validateParticipantByName.returns({ isValid: true })
|
|
367
|
+
BulkTransferService.getParticipantsById.withArgs(bulkTransfer.bulkTransferId).returns({ payeeFsp: bulkTransfer.payeeFsp, payerFsp: bulkTransfer.payerFsp })
|
|
368
|
+
const bulkTransferResult = MainUtil.clone(bulkTransferReturn)
|
|
369
|
+
bulkTransferResult.bulkTransferStateId = Enum.Transfers.BulkProcessingState.PROCESSING
|
|
370
|
+
bulkTransferResult.extensionList = []
|
|
371
|
+
BulkTransferModel.getById.withArgs(bulkTransfer.bulkTransferId).returns(Promise.resolve(bulkTransferResult))
|
|
372
|
+
const bulkTransferResult2 = {
|
|
373
|
+
...bulkTransferResult,
|
|
374
|
+
bulkTransferState: 'COMPLETED',
|
|
375
|
+
payerBulkTransfer: {
|
|
376
|
+
bulkTransferState: 'COMPLETED',
|
|
377
|
+
individualTransferResults: []
|
|
378
|
+
},
|
|
379
|
+
payeeBulkTransfer: {
|
|
380
|
+
bulkTransferState: 'COMPLETED',
|
|
381
|
+
individualTransferResults: []
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
BulkTransferService.getBulkTransferById.withArgs(bulkTransfer.bulkTransferId).returns(Promise.resolve(bulkTransferResult2))
|
|
385
|
+
|
|
386
|
+
try {
|
|
387
|
+
await allBulkTransferHandlers.getBulkTransfer(null, localMessages)
|
|
388
|
+
const expectedState = new EventSdk.EventStateMetadata(EventSdk.EventStatusType.failed, '2001', 'Internal server error')
|
|
389
|
+
test.ok(SpanStub.finish.calledWith('', expectedState))
|
|
390
|
+
test.end()
|
|
391
|
+
} catch (e) {
|
|
392
|
+
test.fail('Error thrown')
|
|
393
|
+
test.end()
|
|
394
|
+
}
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
getBulkTransferTest.end()
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
getHandlerTest.end()
|
|
401
|
+
})
|
|
@@ -6,15 +6,21 @@ const Config = require('../../../src/lib/config')
|
|
|
6
6
|
const Proxyquire = require('proxyquire')
|
|
7
7
|
const Plugin = require('../../../src/handlers/api/plugin')
|
|
8
8
|
const MetricsPlugin = require('../../../src/api/metrics/plugin')
|
|
9
|
+
const Logger = require('@mojaloop/central-services-logger')
|
|
9
10
|
|
|
10
11
|
Test('cli', async (cliTest) => {
|
|
12
|
+
let sandbox
|
|
13
|
+
|
|
11
14
|
cliTest.beforeEach(test => {
|
|
15
|
+
sandbox = Sinon.createSandbox()
|
|
16
|
+
sandbox.stub(Logger, 'isDebugEnabled').value(true)
|
|
12
17
|
console.log('start')
|
|
13
18
|
test.end()
|
|
14
19
|
})
|
|
15
20
|
|
|
16
21
|
cliTest.afterEach(test => {
|
|
17
22
|
console.log('end')
|
|
23
|
+
sandbox.restore()
|
|
18
24
|
test.end()
|
|
19
25
|
})
|
|
20
26
|
|
|
@@ -6,6 +6,7 @@ const Kafka = require('@mojaloop/central-services-shared').Util.Kafka
|
|
|
6
6
|
const Validator = require('../../../../src/handlers/transfers/validator')
|
|
7
7
|
const TransferService = require('../../../../src/domain/transfer')
|
|
8
8
|
const PositionService = require('../../../../src/domain/position')
|
|
9
|
+
const SettlementModelCached = require('../../../../src/models/settlement/settlementModelCached')
|
|
9
10
|
const MainUtil = require('@mojaloop/central-services-shared').Util
|
|
10
11
|
const Consumer = require('@mojaloop/central-services-stream').Util.Consumer
|
|
11
12
|
const KafkaConsumer = Consumer.Consumer
|
|
@@ -177,6 +178,7 @@ Test('Position handler', transferHandlerTest => {
|
|
|
177
178
|
sandbox.stub(TransferService)
|
|
178
179
|
sandbox.stub(PositionService)
|
|
179
180
|
sandbox.stub(TransferStateChange)
|
|
181
|
+
sandbox.stub(SettlementModelCached)
|
|
180
182
|
Kafka.transformAccountToTopicName.returns(topicName)
|
|
181
183
|
Kafka.produceGeneralMessage.resolves()
|
|
182
184
|
test.end()
|
|
@@ -793,6 +795,30 @@ Test('Position handler', transferHandlerTest => {
|
|
|
793
795
|
test.end()
|
|
794
796
|
})
|
|
795
797
|
|
|
798
|
+
positionsTest.test('update transferStateChange for BULK_ABORT action', async (test) => {
|
|
799
|
+
const isReversal = true
|
|
800
|
+
const transferStateChange = {
|
|
801
|
+
transferId: transferInfo.transferId,
|
|
802
|
+
transferStateId: TransferState.ABORTED_ERROR
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
await Consumer.createHandler(topicName, config, command)
|
|
806
|
+
Kafka.transformGeneralTopicName.returns(topicName)
|
|
807
|
+
Kafka.getKafkaConfig.returns(config)
|
|
808
|
+
|
|
809
|
+
const m = Object.assign({}, MainUtil.clone(messages[1]))
|
|
810
|
+
TransferService.getTransferInfoToChangePosition.withArgs(m.value.content.uriParams.id, Enum.Accounts.TransferParticipantRoleType.PAYER_DFSP, Enum.Accounts.LedgerEntryType.PRINCIPLE_VALUE).returns(transferInfo)
|
|
811
|
+
TransferStateChange.saveTransferStateChange.resolves(true)
|
|
812
|
+
PositionService.changeParticipantPosition.withArgs(transferInfo.participantCurrencyId, isReversal, transferInfo.amount, transferStateChange).resolves(true)
|
|
813
|
+
m.value.metadata.event.action = transferEventAction.BULK_ABORT
|
|
814
|
+
Kafka.proceed.returns(true)
|
|
815
|
+
|
|
816
|
+
const result = await allTransferHandlers.positions(null, m)
|
|
817
|
+
Logger.info(result)
|
|
818
|
+
test.equal(result, true)
|
|
819
|
+
test.end()
|
|
820
|
+
})
|
|
821
|
+
|
|
796
822
|
positionsTest.test('Throw error when invalid action is received', async (test) => {
|
|
797
823
|
try {
|
|
798
824
|
await Consumer.createHandler(topicName, config, command)
|