@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
|
@@ -55,165 +55,165 @@ Test('transfer validator', validatorTest => {
|
|
|
55
55
|
test.end()
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
-
validatorTest.test('
|
|
59
|
-
|
|
58
|
+
validatorTest.test('validatePrepare should', validatePrepareTest => {
|
|
59
|
+
validatePrepareTest.test('pass validation for valid payload', async (test) => {
|
|
60
60
|
Participant.getByName.returns(Promise.resolve({ isActive: true }))
|
|
61
61
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
62
62
|
CryptoConditions.validateCondition.returns(true)
|
|
63
63
|
|
|
64
|
-
const { validationPassed } = await Validator.
|
|
64
|
+
const { validationPassed } = await Validator.validatePrepare(payload, headers)
|
|
65
65
|
test.equal(validationPassed, true)
|
|
66
66
|
test.end()
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
const { validationPassed, reasons } = await Validator.
|
|
69
|
+
validatePrepareTest.test('fail validation for no payload', async (test) => {
|
|
70
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(null)
|
|
71
71
|
test.equal(validationPassed, false)
|
|
72
72
|
test.deepEqual(reasons, ['Transfer must be provided'])
|
|
73
73
|
test.end()
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
validatePrepareTest.test('fail validation when FSPIOP-Source doesnt match Payer', async (test) => {
|
|
77
77
|
const headersModified = { 'fspiop-source': 'dfsp2' }
|
|
78
|
-
const { validationPassed, reasons } = await Validator.
|
|
78
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headersModified)
|
|
79
79
|
test.equal(validationPassed, false)
|
|
80
80
|
test.deepEqual(reasons, ['FSPIOP-Source header should match Payer'])
|
|
81
81
|
test.end()
|
|
82
82
|
})
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
validatePrepareTest.test('fail validation for invalid condition', async (test) => {
|
|
85
85
|
Participant.getByName.returns(Promise.resolve({ isActive: true }))
|
|
86
86
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
87
87
|
CryptoConditions.validateCondition.throws(new Error())
|
|
88
88
|
|
|
89
|
-
const { validationPassed, reasons } = await Validator.
|
|
89
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
90
90
|
test.equal(validationPassed, false)
|
|
91
91
|
test.deepEqual(reasons, ['Condition validation failed'])
|
|
92
92
|
test.end()
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
validatePrepareTest.test('fail validation for no condition', async (test) => {
|
|
96
96
|
Participant.getByName.returns(Promise.resolve({ isActive: true }))
|
|
97
97
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
98
98
|
payload.condition = null
|
|
99
99
|
|
|
100
|
-
const { validationPassed, reasons } = await Validator.
|
|
100
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
101
101
|
test.equal(validationPassed, false)
|
|
102
102
|
test.deepEqual(reasons, ['Condition is required for a conditional transfer'])
|
|
103
103
|
test.end()
|
|
104
104
|
})
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
validatePrepareTest.test('Fail validation for invalid expiration date', async (test) => {
|
|
107
107
|
Participant.getByName.returns(Promise.resolve({ isActive: true }))
|
|
108
108
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
109
109
|
CryptoConditions.validateCondition.returns(true)
|
|
110
110
|
payload.expiration = '1971-11-24T08:38:08.699-04:00'
|
|
111
111
|
|
|
112
|
-
const { validationPassed, reasons } = await Validator.
|
|
112
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
113
113
|
test.equal(validationPassed, false)
|
|
114
114
|
test.deepEqual(reasons, ['Expiration date 1971-11-24T12:38:08.699Z is already in the past'])
|
|
115
115
|
test.end()
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
validatePrepareTest.test('fail validation for no expiration date', async (test) => {
|
|
119
119
|
Participant.getByName.returns(Promise.resolve({ isActive: true }))
|
|
120
120
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
121
121
|
CryptoConditions.validateCondition.returns(true)
|
|
122
122
|
payload.expiration = null
|
|
123
123
|
|
|
124
|
-
const { validationPassed, reasons } = await Validator.
|
|
124
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
125
125
|
test.equal(validationPassed, false)
|
|
126
126
|
test.deepEqual(reasons, ['Expiration is required for conditional transfer'])
|
|
127
127
|
test.end()
|
|
128
128
|
})
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
validatePrepareTest.test('fail validation for invalid participant', async (test) => {
|
|
131
131
|
Participant.getByName.withArgs('dfsp1').returns(Promise.resolve({ isActive: true }))
|
|
132
132
|
Participant.getByName.withArgs('dfsp2').returns(Promise.resolve(null))
|
|
133
133
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
134
134
|
CryptoConditions.validateCondition.returns(true)
|
|
135
135
|
|
|
136
|
-
const { validationPassed, reasons } = await Validator.
|
|
136
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
137
137
|
test.equal(validationPassed, false)
|
|
138
138
|
test.deepEqual(reasons, ['Participant dfsp2 not found'])
|
|
139
139
|
test.end()
|
|
140
140
|
})
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
validatePrepareTest.test('fail validation for inactive participant', async (test) => {
|
|
143
143
|
Participant.getByName.withArgs('dfsp1').returns(Promise.resolve({ isActive: true }))
|
|
144
144
|
Participant.getByName.withArgs('dfsp2').returns(Promise.resolve({ isActive: false }))
|
|
145
145
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
146
146
|
CryptoConditions.validateCondition.returns(true)
|
|
147
147
|
|
|
148
|
-
const { validationPassed, reasons } = await Validator.
|
|
148
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
149
149
|
test.equal(validationPassed, false)
|
|
150
150
|
test.deepEqual(reasons, ['Participant dfsp2 is inactive'])
|
|
151
151
|
test.end()
|
|
152
152
|
})
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
validatePrepareTest.test('fail validation for invalid account', async (test) => {
|
|
155
155
|
Participant.getByName.withArgs('dfsp1').returns(Promise.resolve({ isActive: true }))
|
|
156
156
|
Participant.getByName.withArgs('dfsp2').returns(Promise.resolve({ isActive: true }))
|
|
157
157
|
Participant.getAccountByNameAndCurrency.withArgs('dfsp1', 'USD', Enum.Accounts.LedgerAccountType.POSITION).returns(Promise.resolve({ currencyIsActive: true }))
|
|
158
158
|
Participant.getAccountByNameAndCurrency.withArgs('dfsp2', 'USD', Enum.Accounts.LedgerAccountType.POSITION).returns(Promise.resolve(null))
|
|
159
159
|
CryptoConditions.validateCondition.returns(true)
|
|
160
160
|
|
|
161
|
-
const { validationPassed, reasons } = await Validator.
|
|
161
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
162
162
|
test.equal(validationPassed, false)
|
|
163
163
|
test.deepEqual(reasons, ['Participant dfsp2 USD account not found'])
|
|
164
164
|
test.end()
|
|
165
165
|
})
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
validatePrepareTest.test('fail validation for inactive account', async (test) => {
|
|
168
168
|
Participant.getByName.withArgs('dfsp1').returns(Promise.resolve({ isActive: true }))
|
|
169
169
|
Participant.getByName.withArgs('dfsp2').returns(Promise.resolve({ isActive: true }))
|
|
170
170
|
Participant.getAccountByNameAndCurrency.withArgs('dfsp1', 'USD', Enum.Accounts.LedgerAccountType.POSITION).returns(Promise.resolve({ currencyIsActive: true }))
|
|
171
171
|
Participant.getAccountByNameAndCurrency.withArgs('dfsp2', 'USD', Enum.Accounts.LedgerAccountType.POSITION).returns(Promise.resolve({ currencyIsActive: false }))
|
|
172
172
|
CryptoConditions.validateCondition.returns(true)
|
|
173
173
|
|
|
174
|
-
const { validationPassed, reasons } = await Validator.
|
|
174
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
175
175
|
test.equal(validationPassed, false)
|
|
176
176
|
test.deepEqual(reasons, ['Participant dfsp2 USD account is inactive'])
|
|
177
177
|
test.end()
|
|
178
178
|
})
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
validatePrepareTest.test('pass validation for valid payload', async (test) => {
|
|
181
181
|
Participant.getByName.returns(Promise.resolve({ isActive: true }))
|
|
182
182
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
183
183
|
CryptoConditions.validateCondition.returns(true)
|
|
184
184
|
payload.amount.amount = '123.12345'
|
|
185
185
|
|
|
186
|
-
const { validationPassed, reasons } = await Validator.
|
|
186
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
187
187
|
test.equal(validationPassed, false)
|
|
188
188
|
test.deepEqual(reasons, ['Amount 123.12345 exceeds allowed scale of 4'])
|
|
189
189
|
test.end()
|
|
190
190
|
})
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
validatePrepareTest.test('fail validation for same payer and payee', async (test) => {
|
|
193
193
|
Participant.getByName.returns(Promise.resolve({ isActive: true }))
|
|
194
194
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
195
195
|
CryptoConditions.validateCondition.returns(true)
|
|
196
196
|
payload.payeeFsp = payload.payerFsp
|
|
197
197
|
|
|
198
|
-
const { validationPassed, reasons } = await Validator.
|
|
198
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
199
199
|
test.equal(validationPassed, false)
|
|
200
|
-
test.deepEqual(reasons, ['Payer and Payee should be different'])
|
|
200
|
+
test.deepEqual(reasons, ['Payer FSP and Payee FSP should be different, unless on-us tranfers are allowed by the Scheme'])
|
|
201
201
|
test.end()
|
|
202
202
|
})
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
validatePrepareTest.test('pass validation for valid payload', async (test) => {
|
|
205
205
|
Participant.getByName.returns(Promise.resolve({ isActive: true }))
|
|
206
206
|
Participant.getAccountByNameAndCurrency.returns(Promise.resolve({ currencyIsActive: true }))
|
|
207
207
|
CryptoConditions.validateCondition.returns(true)
|
|
208
208
|
payload.amount.amount = '123456789012345.6789'
|
|
209
209
|
|
|
210
|
-
const { validationPassed, reasons } = await Validator.
|
|
210
|
+
const { validationPassed, reasons } = await Validator.validatePrepare(payload, headers)
|
|
211
211
|
test.equal(validationPassed, false)
|
|
212
212
|
test.deepEqual(reasons, ['Amount 123456789012345.6789 exceeds allowed precision of 18'])
|
|
213
213
|
test.end()
|
|
214
214
|
})
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
validatePrepareTest.end()
|
|
217
217
|
})
|
|
218
218
|
|
|
219
219
|
validatorTest.test('validateById should', validateByIdTest => {
|
|
@@ -8,21 +8,11 @@ const Enums = require('../../../src/lib/enum')
|
|
|
8
8
|
|
|
9
9
|
Test('Cache test', async (cacheTest) => {
|
|
10
10
|
let sandbox
|
|
11
|
-
let allEnumsValue
|
|
12
|
-
|
|
13
|
-
const templateValueForEnum = (enumId) => {
|
|
14
|
-
return { testEnumKey: `testEnum of ${enumId}` }
|
|
15
|
-
}
|
|
16
11
|
|
|
17
12
|
cacheTest.beforeEach(t => {
|
|
18
13
|
sandbox = Sinon.createSandbox()
|
|
19
14
|
sandbox.stub(Enums)
|
|
20
15
|
sandbox.stub(Config.CACHE_CONFIG, 'CACHE_ENABLED')
|
|
21
|
-
allEnumsValue = {}
|
|
22
|
-
for (const enumId of Enums.enumsIds) {
|
|
23
|
-
Enums[enumId].returns(Promise.resolve(templateValueForEnum(enumId)))
|
|
24
|
-
allEnumsValue[enumId] = templateValueForEnum(enumId)
|
|
25
|
-
}
|
|
26
16
|
Cache.registerCacheClient({
|
|
27
17
|
id: 'testCacheClient',
|
|
28
18
|
preloadCache: async () => sandbox.stub()
|
|
@@ -60,60 +50,6 @@ Test('Cache test', async (cacheTest) => {
|
|
|
60
50
|
initTest.end()
|
|
61
51
|
})
|
|
62
52
|
|
|
63
|
-
await cacheTest.test('Caching enums:', async (enumTest) => {
|
|
64
|
-
await enumTest.test('should pre-fetch all enums info at start', async (test) => {
|
|
65
|
-
// Check that Enums haven't been called
|
|
66
|
-
for (const enumId of Enums.enumsIds) {
|
|
67
|
-
test.notOk(Enums[enumId].calledOnce, `enum ${enumId} wasn't called before initCache`)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// This should pre-fetch all enums
|
|
71
|
-
await Cache.initCache()
|
|
72
|
-
|
|
73
|
-
// Check that Enums have been called
|
|
74
|
-
for (const enumId of Enums.enumsIds) {
|
|
75
|
-
test.ok(Enums[enumId].calledOnce, `enum ${enumId} was called once during initCache`)
|
|
76
|
-
}
|
|
77
|
-
await Cache.destroyCache()
|
|
78
|
-
test.end()
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
await enumTest.test('should call enums only once and then should return cached data (should not call enums again)', async (test) => {
|
|
82
|
-
// This should pre-fetch all enums
|
|
83
|
-
await Cache.initCache()
|
|
84
|
-
|
|
85
|
-
// Check that Enums have been called once
|
|
86
|
-
for (const enumId of Enums.enumsIds) {
|
|
87
|
-
test.ok(Enums[enumId].calledOnce, `enum ${enumId} was called once`)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Get Enum info from cache and verify values
|
|
91
|
-
for (const enumId of Enums.enumsIds) {
|
|
92
|
-
const returnedValue = await Cache.getEnums(enumId)
|
|
93
|
-
test.deepEqual(templateValueForEnum(enumId), returnedValue, `value for enum ${enumId} is correct`)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Check again that Enums have been called once (so cache worked)
|
|
97
|
-
for (const enumId of Enums.enumsIds) {
|
|
98
|
-
test.ok(Enums[enumId].calledOnce, `enum ${enumId} was still called just once`)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Let's check the "all" summary-enum also works well on cached values
|
|
102
|
-
const returnedAllEnumsValue = await Cache.getEnums('all')
|
|
103
|
-
test.deepEqual(returnedAllEnumsValue, allEnumsValue, 'the "all" enum type works well')
|
|
104
|
-
|
|
105
|
-
// Check again that Enums have been called once (so cache worked)
|
|
106
|
-
for (const enumId of Enums.enumsIds) {
|
|
107
|
-
test.ok(Enums[enumId].calledOnce, `enum ${enumId} was still called just once`)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
await Cache.destroyCache()
|
|
111
|
-
test.end()
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
enumTest.end()
|
|
115
|
-
})
|
|
116
|
-
|
|
117
53
|
await cacheTest.test('Cache client', async (cacheClientTest) => {
|
|
118
54
|
await cacheClientTest.test('preload should be called once during Cache.initCache()', async (test) => {
|
|
119
55
|
let preloadCacheCalledCnt = 0
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
Test that integrated enumsCached.js and cache.js work together as expected.
|
|
3
|
+
|
|
4
|
+
License
|
|
5
|
+
--------------
|
|
6
|
+
Copyright © 2017 Bill & Melinda Gates Foundation
|
|
7
|
+
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
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
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
|
+
Contributors
|
|
11
|
+
--------------
|
|
12
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
13
|
+
Names of the original copyright holders (individuals or organizations)
|
|
14
|
+
should be listed with a '*' in the first column. People who have
|
|
15
|
+
contributed from an organization can be listed under the organization
|
|
16
|
+
that actually holds the copyright for their contributions (see the
|
|
17
|
+
Gates Foundation organization for an example). Those individuals should have
|
|
18
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
19
|
+
optionally within square brackets <email>.
|
|
20
|
+
* Gates Foundation
|
|
21
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
|
22
|
+
|
|
23
|
+
* Roman Pietrzak <roman.pietrzak@modusbox.com>
|
|
24
|
+
--------------
|
|
25
|
+
******/
|
|
26
|
+
|
|
27
|
+
'use strict'
|
|
28
|
+
|
|
29
|
+
const Test = require('tapes')(require('tape'))
|
|
30
|
+
const Sinon = require('sinon')
|
|
31
|
+
const EnumUncached = require('../../../src/lib/enum')
|
|
32
|
+
const Config = require('../../../src/lib/config')
|
|
33
|
+
const Cache = require('../../../src/lib/cache')
|
|
34
|
+
const Model = require('../../../src/lib/enumCached')
|
|
35
|
+
|
|
36
|
+
Test('Enums with caching', async (enumCachedTest) => {
|
|
37
|
+
let sandbox
|
|
38
|
+
let allEnumsValue
|
|
39
|
+
|
|
40
|
+
const templateValueForEnum = (enumId) => {
|
|
41
|
+
return { testEnumKey: `testEnum of ${enumId}` }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
enumCachedTest.beforeEach(t => {
|
|
45
|
+
sandbox = Sinon.createSandbox()
|
|
46
|
+
sandbox.stub(EnumUncached)
|
|
47
|
+
sandbox.stub(Config.CACHE_CONFIG, 'CACHE_ENABLED')
|
|
48
|
+
Config.CACHE_CONFIG.CACHE_ENABLED = true
|
|
49
|
+
allEnumsValue = {}
|
|
50
|
+
for (const enumId of EnumUncached.enumsIds) {
|
|
51
|
+
EnumUncached[enumId].returns(Promise.resolve(templateValueForEnum(enumId)))
|
|
52
|
+
allEnumsValue[enumId] = templateValueForEnum(enumId)
|
|
53
|
+
}
|
|
54
|
+
t.end()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
enumCachedTest.afterEach(t => {
|
|
58
|
+
sandbox.restore()
|
|
59
|
+
t.end()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
await enumCachedTest.test('Cache should pre-fetch all enums info at start', async (test) => {
|
|
63
|
+
// Check that Enums haven't been called
|
|
64
|
+
for (const enumId of EnumUncached.enumsIds) {
|
|
65
|
+
test.notOk(EnumUncached[enumId].calledOnce, `enum ${enumId} wasn't called before initCache`)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// This should pre-fetch all enums
|
|
69
|
+
await Model.initialize()
|
|
70
|
+
await Cache.initCache()
|
|
71
|
+
|
|
72
|
+
// Check that Enums have been called
|
|
73
|
+
for (const enumId of EnumUncached.enumsIds) {
|
|
74
|
+
test.ok(EnumUncached[enumId].calledOnce, `enum ${enumId} was called once during initCache`)
|
|
75
|
+
}
|
|
76
|
+
await Cache.destroyCache()
|
|
77
|
+
await Cache.dropClients()
|
|
78
|
+
test.end()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
await enumCachedTest.test('should call enums only once and then should return cached data (should not call enums again)', async (test) => {
|
|
82
|
+
// Check that Enums haven't been called
|
|
83
|
+
for (const enumId of EnumUncached.enumsIds) {
|
|
84
|
+
test.notOk(EnumUncached[enumId].calledOnce, `enum ${enumId} wasn't called before initCache`)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// This should pre-fetch all enums
|
|
88
|
+
await Model.initialize()
|
|
89
|
+
await Cache.initCache()
|
|
90
|
+
|
|
91
|
+
// Check that Enums have been called once
|
|
92
|
+
for (const enumId of EnumUncached.enumsIds) {
|
|
93
|
+
test.ok(EnumUncached[enumId].calledOnce, `enum ${enumId} was called once`)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Get Enum info from cache and verify values
|
|
97
|
+
for (const enumId of EnumUncached.enumsIds) {
|
|
98
|
+
const returnedValue = await Model.getEnums(enumId)
|
|
99
|
+
test.deepEqual(templateValueForEnum(enumId), returnedValue, `value for enum ${enumId} is correct`)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Check again that Enums have been called once (so cache worked)
|
|
103
|
+
for (const enumId of EnumUncached.enumsIds) {
|
|
104
|
+
test.ok(EnumUncached[enumId].calledOnce, `enum ${enumId} was still called just once`)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Let's check the "all" summary-enum also works well on cached values
|
|
108
|
+
const returnedAllEnumsValue = await Model.getEnums('all')
|
|
109
|
+
test.deepEqual(returnedAllEnumsValue, allEnumsValue, 'the "all" enum type works well')
|
|
110
|
+
|
|
111
|
+
// Check again that Enums have been called once (so cache worked)
|
|
112
|
+
for (const enumId of EnumUncached.enumsIds) {
|
|
113
|
+
test.ok(EnumUncached[enumId].calledOnce, `enum ${enumId} was still called just once`)
|
|
114
|
+
}
|
|
115
|
+
await Cache.destroyCache()
|
|
116
|
+
await Cache.dropClients()
|
|
117
|
+
test.end()
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
await enumCachedTest.end()
|
|
121
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const Test = require('tape')
|
|
4
|
+
const Proxyquire = require('proxyquire')
|
|
5
|
+
const Defaults = require('../../../config/default.json')
|
|
6
|
+
|
|
7
|
+
Test('Config should', configTest => {
|
|
8
|
+
configTest.test('enable API_DOC_ENDPOINTS_ENABLED', async function (test) {
|
|
9
|
+
const DefaultsStub = { ...Defaults }
|
|
10
|
+
DefaultsStub.API_DOC_ENDPOINTS_ENABLED = true
|
|
11
|
+
|
|
12
|
+
const Config = Proxyquire('../../../src/lib/config', {
|
|
13
|
+
'../../config/default.json': DefaultsStub
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test.ok(Config.API_DOC_ENDPOINTS_ENABLED === true)
|
|
17
|
+
test.end()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
configTest.test('disable API_DOC_ENDPOINTS_ENABLED', async function (test) {
|
|
21
|
+
console.log(Defaults)
|
|
22
|
+
const DefaultsStub = { ...Defaults }
|
|
23
|
+
DefaultsStub.API_DOC_ENDPOINTS_ENABLED = false
|
|
24
|
+
|
|
25
|
+
const Config = Proxyquire('../../../src/lib/config', {
|
|
26
|
+
'../../config/default.json': DefaultsStub
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test.ok(Config.API_DOC_ENDPOINTS_ENABLED === false)
|
|
30
|
+
test.end()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
configTest.end()
|
|
34
|
+
})
|
|
@@ -163,6 +163,7 @@ Test('Enum test', async (enumTest) => {
|
|
|
163
163
|
|
|
164
164
|
enumTest.beforeEach(t => {
|
|
165
165
|
sandbox = Sinon.createSandbox()
|
|
166
|
+
|
|
166
167
|
Db.endpointType = {
|
|
167
168
|
find: sandbox.stub()
|
|
168
169
|
}
|
|
@@ -191,6 +192,10 @@ Test('Enum test', async (enumTest) => {
|
|
|
191
192
|
find: sandbox.stub()
|
|
192
193
|
}
|
|
193
194
|
|
|
195
|
+
Db.from = (table) => {
|
|
196
|
+
return Db[table]
|
|
197
|
+
}
|
|
198
|
+
|
|
194
199
|
t.end()
|
|
195
200
|
})
|
|
196
201
|
|
|
@@ -202,7 +207,7 @@ Test('Enum test', async (enumTest) => {
|
|
|
202
207
|
await enumTest.test('endpointType should', async (endpointTypeTest) => {
|
|
203
208
|
await endpointTypeTest.test('return the endpoints', async (test) => {
|
|
204
209
|
try {
|
|
205
|
-
Db.endpointType.find.returns(Promise.resolve(allEnums.endpointType))
|
|
210
|
+
Db.from('endpointType').find.returns(Promise.resolve(allEnums.endpointType))
|
|
206
211
|
const result = await Model.endpointType()
|
|
207
212
|
test.deepEqual(result, allEnumExpected.endpointType, 'Results match')
|
|
208
213
|
test.end()
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
* Roman Pietrzak <roman.pietrzak@modusbox.com>
|
|
22
|
+
--------------
|
|
23
|
+
******/
|
|
24
|
+
|
|
25
|
+
'use strict'
|
|
26
|
+
|
|
27
|
+
const Test = require('tapes')(require('tape'))
|
|
28
|
+
const Sinon = require('sinon')
|
|
29
|
+
const EnumUncached = require('../../../src/lib/enum')
|
|
30
|
+
const Cache = require('../../../src/lib/cache')
|
|
31
|
+
const Model = require('../../../src/lib/enumCached')
|
|
32
|
+
|
|
33
|
+
Test('Enums cached model', async (enumCachedTest) => {
|
|
34
|
+
let sandbox
|
|
35
|
+
|
|
36
|
+
enumCachedTest.beforeEach(t => {
|
|
37
|
+
sandbox = Sinon.createSandbox()
|
|
38
|
+
sandbox.stub(Cache)
|
|
39
|
+
sandbox.stub(EnumUncached)
|
|
40
|
+
t.end()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
enumCachedTest.afterEach(t => {
|
|
44
|
+
sandbox.restore()
|
|
45
|
+
t.end()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
await enumCachedTest.test('initializes cache correctly', async (test) => {
|
|
49
|
+
const cacheClient = {
|
|
50
|
+
createKey: sandbox.stub().returns({})
|
|
51
|
+
}
|
|
52
|
+
Cache.registerCacheClient.returns(cacheClient)
|
|
53
|
+
|
|
54
|
+
// initialize calls registerCacheClient and createKey
|
|
55
|
+
test.notOk(Cache.registerCacheClient.calledOnce)
|
|
56
|
+
test.notOk(cacheClient.createKey.calledOnce)
|
|
57
|
+
await Model.initialize()
|
|
58
|
+
test.ok(Cache.registerCacheClient.calledOnce)
|
|
59
|
+
test.ok(cacheClient.createKey.calledOnce)
|
|
60
|
+
|
|
61
|
+
test.end()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
await enumCachedTest.test('calls drop() for invalidateEnumCache', async (test) => {
|
|
65
|
+
// initialize
|
|
66
|
+
const cacheClient = {
|
|
67
|
+
createKey: sandbox.stub().returns({}),
|
|
68
|
+
drop: sandbox.stub()
|
|
69
|
+
}
|
|
70
|
+
Cache.registerCacheClient.returns(cacheClient)
|
|
71
|
+
await Model.initialize()
|
|
72
|
+
|
|
73
|
+
// check
|
|
74
|
+
test.notOk(cacheClient.drop.calledOnce)
|
|
75
|
+
await Model.invalidateEnumCache()
|
|
76
|
+
test.ok(cacheClient.drop.calledOnce)
|
|
77
|
+
|
|
78
|
+
test.end()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
await enumCachedTest.end()
|
|
82
|
+
})
|
|
@@ -36,6 +36,7 @@ const { statusEnum, serviceName } = require('@mojaloop/central-services-shared')
|
|
|
36
36
|
|
|
37
37
|
const MigrationLockModel = require('../../../../src/models/misc/migrationLock')
|
|
38
38
|
const Consumer = require('@mojaloop/central-services-stream').Util.Consumer
|
|
39
|
+
const Logger = require('@mojaloop/central-services-logger')
|
|
39
40
|
|
|
40
41
|
const {
|
|
41
42
|
getSubServiceHealthBroker,
|
|
@@ -49,6 +50,7 @@ Test('SubServiceHealth test', subServiceHealthTest => {
|
|
|
49
50
|
sandbox = Sinon.createSandbox()
|
|
50
51
|
sandbox.stub(Consumer, 'getListOfTopics')
|
|
51
52
|
sandbox.stub(Consumer, 'isConnected')
|
|
53
|
+
sandbox.stub(Logger, 'isDebugEnabled').value(true)
|
|
52
54
|
|
|
53
55
|
t.end()
|
|
54
56
|
})
|
|
@@ -39,6 +39,8 @@ Test('logger', loggerTest => {
|
|
|
39
39
|
sandbox = Sinon.createSandbox()
|
|
40
40
|
sandbox.stub(Logger, 'info')
|
|
41
41
|
sandbox.stub(Logger, 'debug')
|
|
42
|
+
sandbox.stub(Logger, 'isInfoEnabled').value(true)
|
|
43
|
+
sandbox.stub(Logger, 'isDebugEnabled').value(true)
|
|
42
44
|
sandbox.stub(Util, 'inspect')
|
|
43
45
|
|
|
44
46
|
test.end()
|
|
@@ -54,18 +56,18 @@ Test('logger', loggerTest => {
|
|
|
54
56
|
const request = {
|
|
55
57
|
headers: { traceid: '123456' },
|
|
56
58
|
method: 'post',
|
|
57
|
-
|
|
59
|
+
path: '/participants',
|
|
58
60
|
query: { token: '1234' },
|
|
59
|
-
|
|
61
|
+
payload: 'this is the body'
|
|
60
62
|
}
|
|
61
63
|
RequestLogger.logRequest(request)
|
|
62
64
|
test.ok(Logger.debug.calledThrice)
|
|
63
65
|
const args = Logger.debug.firstCall.args
|
|
64
66
|
const args2 = Logger.debug.secondCall.args
|
|
65
67
|
const args3 = Logger.debug.thirdCall.args
|
|
66
|
-
test.equal(args[0], `L1p-Trace-Id=${request.headers.traceid} - Method: ${request.method} Path: ${request.
|
|
67
|
-
test.equal(args2[0], `L1p-Trace-Id=${request.headers.traceid} - Headers: ${JSON.stringify(request.headers)}`)
|
|
68
|
-
test.equal(args3[0], `L1p-Trace-Id=${request.headers.traceid} - Body: ${request.
|
|
68
|
+
test.equal(args[0], `L1p-Trace-Id=${request.headers.traceid} - Method: ${request.method}, Path: ${request.path}, Query: ${JSON.stringify(request.query)}`)
|
|
69
|
+
test.equal(args2[0], `L1p-Trace-Id=${request.headers.traceid} - Headers: ${JSON.stringify(request.headers, null, 2)}`)
|
|
70
|
+
test.equal(args3[0], `L1p-Trace-Id=${request.headers.traceid} - Body: ${JSON.stringify(request.payload, null, 2)}`)
|
|
69
71
|
test.end()
|
|
70
72
|
})
|
|
71
73
|
|
|
@@ -73,7 +75,7 @@ Test('logger', loggerTest => {
|
|
|
73
75
|
const request = {
|
|
74
76
|
headers: { traceid: '123456' },
|
|
75
77
|
method: 'post',
|
|
76
|
-
|
|
78
|
+
path: '/participants',
|
|
77
79
|
query: { token: '1234' }
|
|
78
80
|
}
|
|
79
81
|
RequestLogger.logRequest(request)
|
|
@@ -88,11 +90,11 @@ Test('logger', loggerTest => {
|
|
|
88
90
|
responseTest.test('send info message to the serviceslogger', test => {
|
|
89
91
|
const request = {
|
|
90
92
|
headers: { traceid: '123456' },
|
|
91
|
-
response: {
|
|
93
|
+
response: { message: 'this is the response', statusCode: '200', stack: 'test' }
|
|
92
94
|
}
|
|
93
95
|
RequestLogger.logResponse(request)
|
|
94
96
|
const args = Logger.debug.firstCall.args
|
|
95
|
-
test.equal(args[0], `L1p-Trace-Id=${request.headers.traceid} - Response: ${JSON.stringify(request.response
|
|
97
|
+
test.equal(args[0], `L1p-Trace-Id=${request.headers.traceid} - Response: ${JSON.stringify(request.response, null, 2)}, Status: ${request.response.statusCode}, Stack: ${request.response.stack}`)
|
|
96
98
|
test.end()
|
|
97
99
|
})
|
|
98
100
|
|
|
@@ -108,12 +110,12 @@ Test('logger', loggerTest => {
|
|
|
108
110
|
responseTest.test('use util.inspect if JSON.stringify throws', test => {
|
|
109
111
|
const request = {
|
|
110
112
|
headers: { traceid: '123456' },
|
|
111
|
-
response: {
|
|
113
|
+
response: { body: 'this is the response', statusCode: '200' }
|
|
112
114
|
}
|
|
113
|
-
request.response.
|
|
115
|
+
request.response.circular = request.response
|
|
114
116
|
RequestLogger.logResponse(request)
|
|
115
117
|
const args = Util.inspect.firstCall.args
|
|
116
|
-
test.equal(args[0], request.response
|
|
118
|
+
test.equal(args[0], request.response)
|
|
117
119
|
test.end()
|
|
118
120
|
})
|
|
119
121
|
responseTest.end()
|
|
@@ -122,7 +124,7 @@ Test('logger', loggerTest => {
|
|
|
122
124
|
loggerTest.test('websocket should', requestTest => {
|
|
123
125
|
requestTest.test('send info message to the serviceslogger', test => {
|
|
124
126
|
const request = {
|
|
125
|
-
|
|
127
|
+
payload: 'this is the body'
|
|
126
128
|
}
|
|
127
129
|
RequestLogger.logWebsocket(request)
|
|
128
130
|
const args = Logger.info.firstCall.args
|