account-lookup-service 15.5.0-iso.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.circleci/config.yml +11 -0
- package/.ncurc.yaml +6 -0
- package/.nvmrc +1 -0
- package/.nycrc.yml +20 -0
- package/.versionrc +15 -0
- package/CHANGELOG.md +330 -0
- package/CODEOWNERS +38 -0
- package/Dockerfile +45 -0
- package/LICENSE.md +10 -0
- package/README.md +252 -0
- package/audit-ci.jsonc +32 -0
- package/audit-resolve.json +161 -0
- package/config/default.json +109 -0
- package/config/knexfile.js +21 -0
- package/docker/account-lookup-service/default.json +106 -0
- package/docker/account-lookup-service/make-default-json.sh +5 -0
- package/docker/account-lookup-service/override.json +15 -0
- package/docker/central-ledger/default.json +458 -0
- package/docker/config-modifier/account-lookup-service.js +31 -0
- package/docker/kafka/consumer.properties +26 -0
- package/docker/kafka/producer.properties +45 -0
- package/docker/kafka/server.properties +143 -0
- package/docker/kafka/tools-log4j.properties +21 -0
- package/docker/mock-proxy/Dockerfile +15 -0
- package/docker/mock-proxy/package-lock.json +4986 -0
- package/docker/mock-proxy/package.json +24 -0
- package/docker/mock-proxy/src/config.ts +14 -0
- package/docker/mock-proxy/src/server.ts +94 -0
- package/docker/mock-proxy/src/utils.ts +29 -0
- package/docker/mock-proxy/tsconfig.json +24 -0
- package/docker/sql-init/01_permissions.sql +2 -0
- package/docker/sql-init-central-ledger/01_permissions.sql +2 -0
- package/docker/wait-for/wait-for-account-lookup-service.sh +10 -0
- package/docker/wait-for/wait-for-central-ledger.sh +11 -0
- package/docker/wait-for/wait-for-kafka.sh +7 -0
- package/docker/wait-for/wait-for-ml-api-adapter.sh +9 -0
- package/docker/wait-for/wait-for-mockserver.sh +20 -0
- package/docker/wait-for/wait-for-mysql-als.sh +14 -0
- package/docker/wait-for/wait-for-mysql-central-ledger.sh +11 -0
- package/docker/wait-for/wait-for-mysql.sh +11 -0
- package/docker/wait-for/wait-for-objstore.sh +12 -0
- package/docker/wait-for/wait-for.env +18 -0
- package/docker/wait-for/wait-for.sh +81 -0
- package/docker-compose.integration.yml +29 -0
- package/docker-compose.yml +243 -0
- package/jest-int.config.js +8 -0
- package/jest.config.js +16 -0
- package/jsdoc.json +38 -0
- package/migrations/01_currency.js +42 -0
- package/migrations/02_endpointType.js +43 -0
- package/migrations/03_endpointType-indexes.js +37 -0
- package/migrations/04_partyIdType.js +43 -0
- package/migrations/05_partyIdType-indexes.js +38 -0
- package/migrations/08_oracleEndpoint.js +51 -0
- package/migrations/09_oracleEndpoint-indexes.js +41 -0
- package/migrations/10_oracleEndpoint-remove-constraints.js +38 -0
- package/package.json +180 -0
- package/scripts/_wait4_all.js +143 -0
- package/scripts/test-functional.sh +76 -0
- package/secrets/jwsSigningKey.key +27 -0
- package/seeds/currency.js +765 -0
- package/seeds/endpointType.js +65 -0
- package/seeds/partyIdType.js +79 -0
- package/src/api/endpointcache.js +67 -0
- package/src/api/health.js +66 -0
- package/src/api/index.js +85 -0
- package/src/api/oracles/{ID}.js +100 -0
- package/src/api/oracles.js +96 -0
- package/src/api/participants/{ID}/error.js +44 -0
- package/src/api/participants/{ID}.js +44 -0
- package/src/api/participants/{Type}/{ID}/error.js +74 -0
- package/src/api/participants/{Type}/{ID}/{SubId}/error.js +68 -0
- package/src/api/participants/{Type}/{ID}/{SubId}.js +113 -0
- package/src/api/participants/{Type}/{ID}.js +133 -0
- package/src/api/participants.js +63 -0
- package/src/api/parties/{Type}/{ID}/error.js +66 -0
- package/src/api/parties/{Type}/{ID}/{SubId}/error.js +56 -0
- package/src/api/parties/{Type}/{ID}/{SubId}.js +77 -0
- package/src/api/parties/{Type}/{ID}.js +98 -0
- package/src/api/routes.js +294 -0
- package/src/constants.js +16 -0
- package/src/domain/oracle/index.js +33 -0
- package/src/domain/oracle/oracle.js +234 -0
- package/src/domain/participants/index.js +35 -0
- package/src/domain/participants/participants.js +560 -0
- package/src/domain/parties/getPartiesByTypeAndID.js +239 -0
- package/src/domain/parties/index.js +32 -0
- package/src/domain/parties/parties.js +215 -0
- package/src/domain/parties/utils.js +84 -0
- package/src/domain/timeout/dto.js +48 -0
- package/src/domain/timeout/index.js +104 -0
- package/src/handlers/TimeoutHandler.js +94 -0
- package/src/handlers/index.js +70 -0
- package/src/handlers/monitoring/index.js +51 -0
- package/src/handlers/monitoring/plugins/health.js +61 -0
- package/src/handlers/monitoring/plugins/metrics.js +48 -0
- package/src/handlers/register.js +102 -0
- package/src/index.js +66 -0
- package/src/interface/admin-swagger.yaml +804 -0
- package/src/interface/admin_swagger.json +959 -0
- package/src/interface/api-swagger-iso20022-parties.yaml +1734 -0
- package/src/interface/api-swagger.yaml +1733 -0
- package/src/interface/api_swagger.json +3046 -0
- package/src/interface/fspiop-rest-v2.0-ISO20022_parties.yaml +2256 -0
- package/src/interface/thirdparty/admin-swagger.yaml +808 -0
- package/src/interface/thirdparty/admin_swagger.json +961 -0
- package/src/interface/thirdparty/api-swagger.yaml +1739 -0
- package/src/interface/thirdparty/api_swagger.json +3142 -0
- package/src/lib/argv.js +39 -0
- package/src/lib/cache.js +126 -0
- package/src/lib/config.js +183 -0
- package/src/lib/db.js +26 -0
- package/src/lib/headers.js +53 -0
- package/src/lib/healthCheck/subServiceHealth.js +84 -0
- package/src/lib/index.js +11 -0
- package/src/lib/migrator.js +17 -0
- package/src/lib/requestLogger.js +54 -0
- package/src/lib/util.js +66 -0
- package/src/metrics/handler.js +33 -0
- package/src/metrics/plugin.js +52 -0
- package/src/metrics/routes.js +43 -0
- package/src/models/currency/currency.js +48 -0
- package/src/models/currency/index.js +32 -0
- package/src/models/endpointType/endpointType.js +48 -0
- package/src/models/endpointType/index.js +32 -0
- package/src/models/misc/migrationLock.js +49 -0
- package/src/models/oracle/facade.js +341 -0
- package/src/models/oracle/index.js +41 -0
- package/src/models/oracle/oracleEndpoint.js +192 -0
- package/src/models/oracle/oracleEndpointCached.js +108 -0
- package/src/models/participantEndpoint/facade.js +238 -0
- package/src/models/partyIdType/index.js +32 -0
- package/src/models/partyIdType/partyIdType.js +41 -0
- package/src/plugins.js +139 -0
- package/src/server.js +199 -0
- package/test/fixtures/index.js +131 -0
- package/test/fixtures/iso.js +110 -0
- package/test/integration/.env +8 -0
- package/test/integration/api/parties.test.js +137 -0
- package/test/integration/constants.js +20 -0
- package/test/integration/domain/oracle/index.test.js +324 -0
- package/test/integration/domain/timeout/index.test.js +75 -0
- package/test/integration/env.sh +15 -0
- package/test/integration/example.test.js +12 -0
- package/test/integration/models/currency/currency.test.js +68 -0
- package/test/integration/plugins.test.js +62 -0
- package/test/integration/prepareTestParticipants.js +30 -0
- package/test/integration/setup.js +5 -0
- package/test/integration-config.json +81 -0
- package/test/integration-runner.sh +108 -0
- package/test/unit/api/health.test.js +142 -0
- package/test/unit/api/oracles/{ID}.test.js +264 -0
- package/test/unit/api/oracles.test.js +173 -0
- package/test/unit/api/participants/participants.test.js +117 -0
- package/test/unit/api/participants/{Type}/{ID}/error.test.js +155 -0
- package/test/unit/api/participants/{Type}/{ID}/{SubId}/error.test.js +131 -0
- package/test/unit/api/participants/{Type}/{ID}/{SubId}.test.js +377 -0
- package/test/unit/api/participants/{Type}/{ID}.test.js +383 -0
- package/test/unit/api/participants.test.js +108 -0
- package/test/unit/api/parties/endpointcache.test.js +83 -0
- package/test/unit/api/parties/parties.test.js +102 -0
- package/test/unit/api/parties/{Type}/{ID}/error.test.js +145 -0
- package/test/unit/api/parties/{Type}/{ID}/{SubId}/error.test.js +141 -0
- package/test/unit/api/parties/{Type}/{ID}/{SubId}.test.js +241 -0
- package/test/unit/api/parties/{Type}/{ID}.test.js +240 -0
- package/test/unit/domain/oracle/oracle.test.js +505 -0
- package/test/unit/domain/participants/participants.test.js +1724 -0
- package/test/unit/domain/parties/parties.test.js +940 -0
- package/test/unit/domain/timeout/dto.test.js +28 -0
- package/test/unit/domain/timeout/index.test.js +81 -0
- package/test/unit/handlers/TimeoutHandler.test.js +125 -0
- package/test/unit/handlers/index.test.js +56 -0
- package/test/unit/handlers/register.test.js +90 -0
- package/test/unit/index.test.js +139 -0
- package/test/unit/iso20022/partiesValidation.test.js +129 -0
- package/test/unit/lib/TransformFacades.test.js +18 -0
- package/test/unit/lib/argv.test.js +40 -0
- package/test/unit/lib/cache.test.js +172 -0
- package/test/unit/lib/config.test.js +108 -0
- package/test/unit/lib/healthCheck/subServiceHealth.test.js +89 -0
- package/test/unit/lib/migrator.test.js +52 -0
- package/test/unit/lib/requestLogger.test.js +115 -0
- package/test/unit/lib/util.test.js +68 -0
- package/test/unit/mocks.js +66 -0
- package/test/unit/models/currency/currency.test.js +91 -0
- package/test/unit/models/endpointType/endpointType.test.js +69 -0
- package/test/unit/models/misc/migrationLock.test.js +96 -0
- package/test/unit/models/oracle/facade.test.js +546 -0
- package/test/unit/models/oracle/oracleEndpoint.test.js +409 -0
- package/test/unit/models/oracle/oracleEndpointCached.test.js +153 -0
- package/test/unit/models/participantEndpoint/facade.test.js +295 -0
- package/test/unit/models/partyIdType/partyIdType.test.js +88 -0
- package/test/unit/plugins.test.js +89 -0
- package/test/unit/setup.js +7 -0
- package/test/util/apiClients/AlsApiClient.js +44 -0
- package/test/util/apiClients/BasicApiClient.js +34 -0
- package/test/util/apiClients/ProxyApiClient.js +25 -0
- package/test/util/apiClients/index.js +7 -0
- package/test/util/helper.js +332 -0
- package/test/util/index.js +11 -0
- package/test/util/mockgen.js +43 -0
- package/test/util/onboarding.js +132 -0
- package/test/util/scripts/addAlsDb.sh +33 -0
- package/test/util/scripts/configureMockServer.sh +35 -0
- package/test/util/scripts/env.sh +19 -0
- package/test/util/scripts/populateTestData.sh +62 -0
- package/test/util/scripts/startMockCentralServer.sh +45 -0
- package/test/util/scripts/startMockOracleServer.sh +45 -0
- package/test/util/testConfig.js +44 -0
@@ -0,0 +1,546 @@
|
|
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
|
+
* Crosslake
|
22
|
+
- Lewis Daly <lewisd@crosslaketech.com>
|
23
|
+
- Miguel de Barros <miguel.debarros@modusbox.com>
|
24
|
+
|
25
|
+
--------------
|
26
|
+
******/
|
27
|
+
|
28
|
+
'use strict'
|
29
|
+
|
30
|
+
const Sinon = require('sinon')
|
31
|
+
const Enums = require('@mojaloop/central-services-shared').Enum
|
32
|
+
const request = require('@mojaloop/central-services-shared').Util.Request
|
33
|
+
|
34
|
+
const OracleFacade = require('../../../../src/models/oracle/facade')
|
35
|
+
const oracleEndpointCached = require('../../../../src/models/oracle/oracleEndpointCached')
|
36
|
+
const Logger = require('@mojaloop/central-services-logger')
|
37
|
+
|
38
|
+
Logger.isDebugEnabled = jest.fn(() => true)
|
39
|
+
Logger.isErrorEnabled = jest.fn(() => true)
|
40
|
+
Logger.isInfoEnabled = jest.fn(() => true)
|
41
|
+
let sandbox
|
42
|
+
|
43
|
+
describe('Oracle Facade', () => {
|
44
|
+
beforeEach(() => {
|
45
|
+
sandbox = Sinon.createSandbox()
|
46
|
+
sandbox.stub(request)
|
47
|
+
})
|
48
|
+
|
49
|
+
afterEach(() => {
|
50
|
+
sandbox.restore()
|
51
|
+
})
|
52
|
+
|
53
|
+
describe('oracleRequest', () => {
|
54
|
+
it('sends requests to more than 1 oracle', async () => {
|
55
|
+
// Arrange
|
56
|
+
const requestStub = sandbox.stub()
|
57
|
+
request.sendRequest = requestStub
|
58
|
+
requestStub.resolves(true)
|
59
|
+
|
60
|
+
const getOracleResponse = [{
|
61
|
+
oracleId: '1',
|
62
|
+
oracleIdType: 'MSISDN',
|
63
|
+
endpoint: {
|
64
|
+
value: 'http://localhost:8444',
|
65
|
+
endpointType: 'URL'
|
66
|
+
},
|
67
|
+
isDefault: true
|
68
|
+
},
|
69
|
+
{
|
70
|
+
oracleId: '2',
|
71
|
+
oracleIdType: 'MSISDN',
|
72
|
+
endpoint: {
|
73
|
+
value: 'http://localhost:8445',
|
74
|
+
endpointType: 'URL'
|
75
|
+
},
|
76
|
+
isDefault: false
|
77
|
+
}]
|
78
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByTypeAndCurrency').returns(getOracleResponse)
|
79
|
+
const headers = {
|
80
|
+
|
81
|
+
}
|
82
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
83
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
84
|
+
const method = Enums.Http.RestMethods.GET
|
85
|
+
const params = {
|
86
|
+
Type: 'request_type',
|
87
|
+
ID: '12345'
|
88
|
+
}
|
89
|
+
const payload = { currency: 'AUD' }
|
90
|
+
|
91
|
+
// Act
|
92
|
+
await OracleFacade.oracleRequest(headers, method, params, {}, payload)
|
93
|
+
|
94
|
+
// Assert
|
95
|
+
expect(requestStub.calledOnce).toBe(true)
|
96
|
+
})
|
97
|
+
|
98
|
+
it('sends requests based on a payload currency', async () => {
|
99
|
+
// Arrange
|
100
|
+
const requestStub = sandbox.stub()
|
101
|
+
request.sendRequest = requestStub
|
102
|
+
requestStub.resolves(true)
|
103
|
+
|
104
|
+
const getOracleResponse = [{
|
105
|
+
oracleId: '1',
|
106
|
+
oracleIdType: 'MSISDN',
|
107
|
+
endpoint: {
|
108
|
+
value: 'http://localhost:8444',
|
109
|
+
endpointType: 'URL'
|
110
|
+
},
|
111
|
+
isDefault: true
|
112
|
+
}]
|
113
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByTypeAndCurrency').returns(getOracleResponse)
|
114
|
+
const headers = {}
|
115
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
116
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
117
|
+
const method = Enums.Http.RestMethods.GET
|
118
|
+
const params = {
|
119
|
+
Type: 'request_type',
|
120
|
+
ID: '12345'
|
121
|
+
}
|
122
|
+
const payload = { currency: 'AUD' }
|
123
|
+
|
124
|
+
// Act
|
125
|
+
await OracleFacade.oracleRequest(headers, method, params, {}, payload)
|
126
|
+
|
127
|
+
// Assert
|
128
|
+
expect(requestStub.calledOnce).toBe(true)
|
129
|
+
})
|
130
|
+
|
131
|
+
it('sends requests based on a payload currency and SubId param', async () => {
|
132
|
+
// Arrange
|
133
|
+
const requestStub = sandbox.stub()
|
134
|
+
request.sendRequest = requestStub
|
135
|
+
requestStub.resolves(true)
|
136
|
+
|
137
|
+
const getOracleResponse = [{
|
138
|
+
oracleId: '1',
|
139
|
+
oracleIdType: 'MSISDN',
|
140
|
+
endpoint: {
|
141
|
+
value: 'http://localhost:8444',
|
142
|
+
endpointType: 'URL'
|
143
|
+
},
|
144
|
+
isDefault: true
|
145
|
+
}]
|
146
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByTypeAndCurrency').returns(getOracleResponse)
|
147
|
+
const headers = {}
|
148
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
149
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
150
|
+
const method = Enums.Http.RestMethods.GET
|
151
|
+
const params = {
|
152
|
+
Type: 'request_type',
|
153
|
+
ID: '12345',
|
154
|
+
SubId: '6789'
|
155
|
+
}
|
156
|
+
const payload = { currency: 'AUD' }
|
157
|
+
|
158
|
+
// Act
|
159
|
+
await OracleFacade.oracleRequest(headers, method, params, {}, payload)
|
160
|
+
|
161
|
+
// Assert
|
162
|
+
expect(requestStub.calledOnce).toBe(true)
|
163
|
+
})
|
164
|
+
|
165
|
+
it('sends requests based on SubId param', async () => {
|
166
|
+
// Arrange
|
167
|
+
const requestStub = sandbox.stub()
|
168
|
+
request.sendRequest = requestStub
|
169
|
+
requestStub.resolves(true)
|
170
|
+
|
171
|
+
const getOracleResponse = [{
|
172
|
+
oracleId: '1',
|
173
|
+
oracleIdType: 'MSISDN',
|
174
|
+
endpoint: {
|
175
|
+
value: 'http://localhost:8444',
|
176
|
+
endpointType: 'URL'
|
177
|
+
},
|
178
|
+
isDefault: true
|
179
|
+
}]
|
180
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByType').returns(getOracleResponse)
|
181
|
+
const headers = {}
|
182
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
183
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
184
|
+
const method = Enums.Http.RestMethods.POST
|
185
|
+
const params = {
|
186
|
+
Type: 'request_type',
|
187
|
+
ID: '12345',
|
188
|
+
SubId: '6789'
|
189
|
+
}
|
190
|
+
const payload = { currency: 'AUG' }
|
191
|
+
|
192
|
+
// Act
|
193
|
+
await OracleFacade.oracleRequest(headers, method, params, {}, payload)
|
194
|
+
|
195
|
+
// Assert
|
196
|
+
expect(requestStub.calledOnce).toBe(true)
|
197
|
+
})
|
198
|
+
|
199
|
+
it('sends request to default oracle when multiple oracles are found (SubId branch)', async () => {
|
200
|
+
// Arrange
|
201
|
+
const requestStub = sandbox.stub()
|
202
|
+
request.sendRequest = requestStub
|
203
|
+
requestStub.resolves(true)
|
204
|
+
|
205
|
+
const getOracleResponse = [{
|
206
|
+
oracleId: '1',
|
207
|
+
oracleIdType: 'MSISDN',
|
208
|
+
endpoint: {
|
209
|
+
value: 'http://localhost:8444',
|
210
|
+
endpointType: 'URL'
|
211
|
+
},
|
212
|
+
isDefault: true
|
213
|
+
},
|
214
|
+
{
|
215
|
+
oracleId: '2',
|
216
|
+
oracleIdType: 'MSISDN',
|
217
|
+
endpoint: {
|
218
|
+
value: 'http://localhost:8445',
|
219
|
+
endpointType: 'URL'
|
220
|
+
},
|
221
|
+
isDefault: false
|
222
|
+
}]
|
223
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByType').returns(getOracleResponse)
|
224
|
+
const headers = {}
|
225
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
226
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
227
|
+
const method = Enums.Http.RestMethods.GET
|
228
|
+
const params = {
|
229
|
+
Type: 'request_type',
|
230
|
+
ID: '12345',
|
231
|
+
SubId: '6789'
|
232
|
+
}
|
233
|
+
const payload = { currency: '' }
|
234
|
+
|
235
|
+
// Act
|
236
|
+
await OracleFacade.oracleRequest(headers, method, params, {}, payload)
|
237
|
+
|
238
|
+
// Assert
|
239
|
+
expect(requestStub.calledOnce).toBe(true)
|
240
|
+
})
|
241
|
+
|
242
|
+
it('throws error if no oracle is found (SubId branch)', async () => {
|
243
|
+
// Arrange
|
244
|
+
const requestStub = sandbox.stub()
|
245
|
+
request.sendRequest = requestStub
|
246
|
+
requestStub.resolves(true)
|
247
|
+
|
248
|
+
const getOracleResponse = []
|
249
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByType').returns(getOracleResponse)
|
250
|
+
const headers = {}
|
251
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
252
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
253
|
+
const method = Enums.Http.RestMethods.GET
|
254
|
+
const params = {
|
255
|
+
Type: 'request_type',
|
256
|
+
ID: '12345',
|
257
|
+
SubId: '6789'
|
258
|
+
}
|
259
|
+
const payload = { currency: '' }
|
260
|
+
|
261
|
+
// Act / Assert
|
262
|
+
await expect(OracleFacade.oracleRequest(headers, method, params, {}, payload)).rejects.toThrow()
|
263
|
+
})
|
264
|
+
|
265
|
+
it('sends request to default oracle when multiple oracles are found (Type, Currency, and SubId branch)', async () => {
|
266
|
+
// Arrange
|
267
|
+
const requestStub = sandbox.stub()
|
268
|
+
request.sendRequest = requestStub
|
269
|
+
requestStub.resolves(true)
|
270
|
+
|
271
|
+
const getOracleResponse = [{
|
272
|
+
oracleId: '1',
|
273
|
+
oracleIdType: 'MSISDN',
|
274
|
+
endpoint: {
|
275
|
+
value: 'http://localhost:8444',
|
276
|
+
endpointType: 'URL'
|
277
|
+
},
|
278
|
+
isDefault: true
|
279
|
+
},
|
280
|
+
{
|
281
|
+
oracleId: '2',
|
282
|
+
oracleIdType: 'MSISDN',
|
283
|
+
endpoint: {
|
284
|
+
value: 'http://localhost:8445',
|
285
|
+
endpointType: 'URL'
|
286
|
+
},
|
287
|
+
isDefault: false
|
288
|
+
}]
|
289
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByTypeAndCurrency').returns(getOracleResponse)
|
290
|
+
const headers = {}
|
291
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
292
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
293
|
+
const method = Enums.Http.RestMethods.GET
|
294
|
+
const params = {
|
295
|
+
Type: 'request_type',
|
296
|
+
ID: '12345',
|
297
|
+
SubId: '6789'
|
298
|
+
}
|
299
|
+
const payload = { currency: 'AUD' }
|
300
|
+
|
301
|
+
// Act
|
302
|
+
await OracleFacade.oracleRequest(headers, method, params, {}, payload)
|
303
|
+
|
304
|
+
// Assert
|
305
|
+
expect(requestStub.calledOnce).toBe(true)
|
306
|
+
})
|
307
|
+
|
308
|
+
it('throws error if no oracle is found (Type, Currency and SubId branch)', async () => {
|
309
|
+
// Arrange
|
310
|
+
const requestStub = sandbox.stub()
|
311
|
+
request.sendRequest = requestStub
|
312
|
+
requestStub.resolves(true)
|
313
|
+
|
314
|
+
const getOracleResponse = []
|
315
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByTypeAndCurrency').returns(getOracleResponse)
|
316
|
+
const headers = {}
|
317
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
318
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
319
|
+
const method = Enums.Http.RestMethods.GET
|
320
|
+
const params = {
|
321
|
+
Type: 'request_type',
|
322
|
+
ID: '12345',
|
323
|
+
SubId: '6789'
|
324
|
+
}
|
325
|
+
const payload = { currency: 'AUD' }
|
326
|
+
|
327
|
+
// Act / Assert
|
328
|
+
await expect(OracleFacade.oracleRequest(headers, method, params, {}, payload)).rejects.toThrow()
|
329
|
+
})
|
330
|
+
|
331
|
+
it('fails to send request when type + currency cannot be found', async () => {
|
332
|
+
// Arrange
|
333
|
+
const requestStub = sandbox.stub()
|
334
|
+
request.sendRequest = requestStub
|
335
|
+
requestStub.resolves(true)
|
336
|
+
|
337
|
+
const getOracleResponse = []
|
338
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByTypeAndCurrency').returns(getOracleResponse)
|
339
|
+
const headers = {}
|
340
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
341
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
342
|
+
const method = Enums.Http.RestMethods.GET
|
343
|
+
const params = {
|
344
|
+
Type: 'request_type',
|
345
|
+
ID: '12345'
|
346
|
+
}
|
347
|
+
const payload = { currency: 'AUD' }
|
348
|
+
|
349
|
+
// Act
|
350
|
+
const action = async () => OracleFacade.oracleRequest(headers, method, params, {}, payload)
|
351
|
+
|
352
|
+
// Assert
|
353
|
+
await expect(action()).rejects.toThrow()
|
354
|
+
})
|
355
|
+
|
356
|
+
it('handles requests when no currency is specified', async () => {
|
357
|
+
// Arrange
|
358
|
+
const requestStub = sandbox.stub()
|
359
|
+
request.sendRequest = requestStub
|
360
|
+
requestStub.resolves(true)
|
361
|
+
|
362
|
+
const getOracleResponse = [{
|
363
|
+
oracleId: '1',
|
364
|
+
oracleIdType: 'MSISDN',
|
365
|
+
endpoint: {
|
366
|
+
value: 'http://localhost:8444',
|
367
|
+
endpointType: 'URL'
|
368
|
+
},
|
369
|
+
isDefault: true
|
370
|
+
}]
|
371
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByType').returns(getOracleResponse)
|
372
|
+
const headers = {}
|
373
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
374
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
375
|
+
const method = Enums.Http.RestMethods.GET
|
376
|
+
|
377
|
+
// Act
|
378
|
+
await OracleFacade.oracleRequest(headers, method)
|
379
|
+
|
380
|
+
// Assert
|
381
|
+
expect(requestStub.calledOnce).toBe(true)
|
382
|
+
})
|
383
|
+
|
384
|
+
it('handles requests whe no currency is specified and more than 1 oracleEndpintModel is found', async () => {
|
385
|
+
// Arrange
|
386
|
+
const requestStub = sandbox.stub()
|
387
|
+
request.sendRequest = requestStub
|
388
|
+
requestStub.resolves(true)
|
389
|
+
|
390
|
+
const getOracleResponse = [{
|
391
|
+
oracleId: '1',
|
392
|
+
oracleIdType: 'MSISDN',
|
393
|
+
endpoint: {
|
394
|
+
value: 'http://localhost:8444',
|
395
|
+
endpointType: 'URL'
|
396
|
+
},
|
397
|
+
isDefault: true
|
398
|
+
},
|
399
|
+
{
|
400
|
+
oracleId: '2',
|
401
|
+
oracleIdType: 'MSISDN',
|
402
|
+
endpoint: {
|
403
|
+
value: 'http://localhost:8445',
|
404
|
+
endpointType: 'URL'
|
405
|
+
},
|
406
|
+
isDefault: false
|
407
|
+
}]
|
408
|
+
|
409
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByType').returns(getOracleResponse)
|
410
|
+
const headers = {}
|
411
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
412
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
413
|
+
const method = Enums.Http.RestMethods.GET
|
414
|
+
|
415
|
+
// Act
|
416
|
+
await OracleFacade.oracleRequest(headers, method)
|
417
|
+
|
418
|
+
// Assert
|
419
|
+
expect(requestStub.calledOnce).toBe(true)
|
420
|
+
})
|
421
|
+
|
422
|
+
it('fails to send when currency is not specified, and type cannot be found', async () => {
|
423
|
+
// Arrange
|
424
|
+
const requestStub = sandbox.stub()
|
425
|
+
request.sendRequest = requestStub
|
426
|
+
requestStub.resolves(true)
|
427
|
+
|
428
|
+
const getOracleResponse = []
|
429
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByType').returns(getOracleResponse)
|
430
|
+
const headers = {}
|
431
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
432
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
433
|
+
const method = Enums.Http.RestMethods.GET
|
434
|
+
const params = {
|
435
|
+
Type: 'request_type',
|
436
|
+
ID: '12345'
|
437
|
+
}
|
438
|
+
const payload = {}
|
439
|
+
|
440
|
+
// Act
|
441
|
+
const action = async () => OracleFacade.oracleRequest(headers, method, params, {}, payload)
|
442
|
+
|
443
|
+
// Assert
|
444
|
+
await expect(action()).rejects.toThrowError(/(Oracle type:.*not found)/)
|
445
|
+
})
|
446
|
+
})
|
447
|
+
|
448
|
+
describe('oracleBatchRequest', () => {
|
449
|
+
it('sends a batch without a currency', async () => {
|
450
|
+
// Arrange
|
451
|
+
const requestStub = sandbox.stub()
|
452
|
+
request.sendRequest = requestStub
|
453
|
+
requestStub.resolves(true)
|
454
|
+
|
455
|
+
const getOracleResponse = [{
|
456
|
+
oracleId: '1',
|
457
|
+
oracleIdType: 'MSISDN',
|
458
|
+
endpoint: {
|
459
|
+
value: 'http://localhost:8444',
|
460
|
+
endpointType: 'URL'
|
461
|
+
},
|
462
|
+
isDefault: true
|
463
|
+
},
|
464
|
+
{
|
465
|
+
oracleId: '2',
|
466
|
+
oracleIdType: 'MSISDN',
|
467
|
+
endpoint: {
|
468
|
+
value: 'http://localhost:8445',
|
469
|
+
endpointType: 'URL'
|
470
|
+
},
|
471
|
+
isDefault: false
|
472
|
+
}]
|
473
|
+
|
474
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByType').returns(getOracleResponse)
|
475
|
+
const headers = {}
|
476
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
477
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
478
|
+
const method = Enums.Http.RestMethods.GET
|
479
|
+
const requestPayload = {}
|
480
|
+
const payload = {}
|
481
|
+
|
482
|
+
// Act
|
483
|
+
await OracleFacade.oracleBatchRequest(headers, method, requestPayload, 'URL', payload)
|
484
|
+
|
485
|
+
// Assert
|
486
|
+
expect(requestStub.calledOnce).toBe(true)
|
487
|
+
})
|
488
|
+
|
489
|
+
it('sends a batch from payload currency', async () => {
|
490
|
+
// Arrange
|
491
|
+
const requestStub = sandbox.stub()
|
492
|
+
request.sendRequest = requestStub
|
493
|
+
requestStub.resolves(true)
|
494
|
+
|
495
|
+
const getOracleResponse = [{
|
496
|
+
oracleId: '1',
|
497
|
+
oracleIdType: 'MSISDN',
|
498
|
+
endpoint: {
|
499
|
+
value: 'http://localhost:8444',
|
500
|
+
endpointType: 'URL'
|
501
|
+
},
|
502
|
+
isDefault: true
|
503
|
+
}]
|
504
|
+
|
505
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByTypeAndCurrency').returns(getOracleResponse)
|
506
|
+
const headers = {}
|
507
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
508
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
509
|
+
const method = Enums.Http.RestMethods.GET
|
510
|
+
const requestPayload = {
|
511
|
+
currency: 'AUD'
|
512
|
+
}
|
513
|
+
const payload = {}
|
514
|
+
|
515
|
+
// Act
|
516
|
+
await OracleFacade.oracleBatchRequest(headers, method, requestPayload, 'URL', payload)
|
517
|
+
|
518
|
+
// Assert
|
519
|
+
expect(requestStub.calledOnce).toBe(true)
|
520
|
+
})
|
521
|
+
|
522
|
+
it('fails when oracle type cannnot be found', async () => {
|
523
|
+
// Arrange
|
524
|
+
const requestStub = sandbox.stub()
|
525
|
+
request.sendRequest = requestStub
|
526
|
+
requestStub.resolves(true)
|
527
|
+
|
528
|
+
const getOracleResponse = []
|
529
|
+
sandbox.stub(oracleEndpointCached, 'getOracleEndpointByTypeAndCurrency').returns(getOracleResponse)
|
530
|
+
const headers = {}
|
531
|
+
headers[Enums.Http.Headers.FSPIOP.SOURCE] = 'fsp01'
|
532
|
+
headers[Enums.Http.Headers.FSPIOP.DESTINATION] = 'fsp02'
|
533
|
+
const method = Enums.Http.RestMethods.GET
|
534
|
+
const requestPayload = {
|
535
|
+
currency: 'AUD'
|
536
|
+
}
|
537
|
+
const payload = {}
|
538
|
+
|
539
|
+
// Act
|
540
|
+
const action = async () => OracleFacade.oracleBatchRequest(headers, method, requestPayload, 'URL', payload)
|
541
|
+
|
542
|
+
// Assert
|
543
|
+
await expect(action()).rejects.toThrow(/Oracle type:.* not found/)
|
544
|
+
})
|
545
|
+
})
|
546
|
+
})
|