account-lookup-service 17.7.0-snapshot.2 → 17.7.0
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/CHANGELOG.md +7 -0
- package/package.json +6 -9
- package/src/constants.js +2 -34
- package/src/domain/parties/deps.js +3 -4
- package/src/domain/parties/getPartiesByTypeAndID.js +13 -9
- package/src/domain/parties/partiesUtils.js +34 -4
- package/src/domain/parties/putParties.js +71 -26
- package/src/domain/parties/services/BasePartiesService.js +15 -137
- package/src/domain/parties/services/GetPartiesService.js +164 -190
- package/src/domain/parties/services/PutPartiesErrorService.js +27 -50
- package/src/domain/parties/services/PutPartiesService.js +33 -51
- package/src/domain/timeout/index.js +1 -11
- package/src/handlers/TimeoutHandler.js +2 -2
- package/src/lib/util.js +3 -11
- package/test/fixtures/index.js +0 -38
- package/test/unit/domain/parties/parties.test.js +18 -26
- package/test/unit/domain/parties/{services/BasePartiesService.test.js → utils.test.js} +34 -33
- package/test/unit/domain/timeout/index.test.js +5 -5
- package/test/util/index.js +6 -5
- package/test/unit/domain/parties/partiesUtils.test.js +0 -51
- package/test/unit/domain/parties/services/GetPartiesService.test.js +0 -222
- package/test/unit/domain/parties/services/PutPartiesErrorService.test.js +0 -49
- package/test/unit/domain/parties/services/deps.js +0 -49
- package/test/util/mockDeps.js +0 -52
@@ -1,222 +0,0 @@
|
|
1
|
-
/*****
|
2
|
-
License
|
3
|
-
--------------
|
4
|
-
Copyright © 2020-2025 Mojaloop Foundation
|
5
|
-
The Mojaloop files are made available by the Mojaloop 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
|
-
Mojaloop Foundation 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
|
-
* Mojaloop Foundation
|
23
|
-
* Eugen Klymniuk <eugen.klymniuk@infitx.com>
|
24
|
-
|
25
|
-
--------------
|
26
|
-
******/
|
27
|
-
|
28
|
-
const { createMockDeps, createProxyCacheMock, oracleMock, participantMock } = require('./deps')
|
29
|
-
// should be first require to mock external deps
|
30
|
-
const { GetPartiesService } = require('#src/domain/parties/services/index')
|
31
|
-
const fixtures = require('#test/fixtures/index')
|
32
|
-
|
33
|
-
const { RestMethods, Headers } = GetPartiesService.enums()
|
34
|
-
|
35
|
-
describe('GetPartiesService Tests -->', () => {
|
36
|
-
beforeEach(() => {
|
37
|
-
jest.clearAllMocks()
|
38
|
-
})
|
39
|
-
|
40
|
-
describe('forwardRequestToDestination method', () => {
|
41
|
-
test('should delete party info from oracle, if no destination DFSP in proxy mapping', async () => {
|
42
|
-
participantMock.validateParticipant = jest.fn().mockResolvedValueOnce(null)
|
43
|
-
const proxyCache = createProxyCacheMock({
|
44
|
-
lookupProxyByDfspId: jest.fn().mockResolvedValueOnce(null)
|
45
|
-
})
|
46
|
-
const deps = createMockDeps({ proxyCache })
|
47
|
-
|
48
|
-
const destination = 'dfsp'
|
49
|
-
const headers = fixtures.partiesCallHeadersDto({ destination, proxy: 'proxy' })
|
50
|
-
const params = fixtures.partiesParamsDto()
|
51
|
-
const service = new GetPartiesService(deps, { headers, params })
|
52
|
-
service.triggerInterSchemeDiscoveryFlow = jest.fn()
|
53
|
-
|
54
|
-
await service.forwardRequestToDestination()
|
55
|
-
|
56
|
-
expect(oracleMock.oracleRequest.mock.calls.length).toBe(1)
|
57
|
-
const [sentHeaders, method, sentParams] = oracleMock.oracleRequest.mock.lastCall
|
58
|
-
expect(method).toBe(RestMethods.DELETE)
|
59
|
-
expect(sentHeaders).toEqual(headers)
|
60
|
-
expect(sentParams).toEqual(params)
|
61
|
-
|
62
|
-
expect(service.triggerInterSchemeDiscoveryFlow.mock.calls.length).toBe(1)
|
63
|
-
expect(service.triggerInterSchemeDiscoveryFlow.mock.lastCall[0]).toEqual({
|
64
|
-
...headers,
|
65
|
-
[Headers.FSPIOP.DESTINATION]: undefined
|
66
|
-
})
|
67
|
-
})
|
68
|
-
})
|
69
|
-
|
70
|
-
describe('processOraclePartyList for external participants', () => {
|
71
|
-
const EXTERNAL_DFSP_ID = 'externalFsp'
|
72
|
-
const PROXY_ID = 'externalProxy'
|
73
|
-
let deps
|
74
|
-
let proxyCache
|
75
|
-
|
76
|
-
beforeEach(async () => {
|
77
|
-
oracleMock.oracleRequest = jest.fn().mockResolvedValueOnce(
|
78
|
-
fixtures.oracleRequestResponseDto({ partyList: [{ fspId: EXTERNAL_DFSP_ID }] })
|
79
|
-
)
|
80
|
-
participantMock.validateParticipant = jest.fn()
|
81
|
-
.mockResolvedValueOnce(null) // source
|
82
|
-
.mockResolvedValueOnce({}) // proxy
|
83
|
-
|
84
|
-
proxyCache = createProxyCacheMock({
|
85
|
-
addDfspIdToProxyMapping: jest.fn().mockResolvedValueOnce(true),
|
86
|
-
lookupProxyByDfspId: jest.fn().mockResolvedValueOnce(PROXY_ID)
|
87
|
-
})
|
88
|
-
deps = createMockDeps({ proxyCache })
|
89
|
-
})
|
90
|
-
|
91
|
-
test('should cleanup oracle and trigger interScheme discovery, if no proxyMapping for external dfsp', async () => {
|
92
|
-
proxyCache.lookupProxyByDfspId = jest.fn().mockResolvedValueOnce(null)
|
93
|
-
const headers = fixtures.partiesCallHeadersDto({
|
94
|
-
destination: '', proxy: 'proxyA'
|
95
|
-
})
|
96
|
-
const params = fixtures.partiesParamsDto()
|
97
|
-
const service = new GetPartiesService(deps, { headers, params })
|
98
|
-
service.triggerInterSchemeDiscoveryFlow = jest.fn()
|
99
|
-
|
100
|
-
await service.handleRequest()
|
101
|
-
expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(2) // GET + DELETE
|
102
|
-
expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
|
103
|
-
expect(service.triggerInterSchemeDiscoveryFlow).toHaveBeenCalledWith(headers)
|
104
|
-
})
|
105
|
-
|
106
|
-
test('should trigger interScheme discovery flow, if source is external', async () => {
|
107
|
-
const headers = fixtures.partiesCallHeadersDto({
|
108
|
-
destination: '', proxy: 'proxyA'
|
109
|
-
})
|
110
|
-
const params = fixtures.partiesParamsDto()
|
111
|
-
const service = new GetPartiesService(deps, { headers, params })
|
112
|
-
service.triggerInterSchemeDiscoveryFlow = jest.fn()
|
113
|
-
|
114
|
-
await service.handleRequest()
|
115
|
-
expect(service.triggerInterSchemeDiscoveryFlow).toHaveBeenCalledWith(headers)
|
116
|
-
})
|
117
|
-
|
118
|
-
test('should forward request, if source is in scheme (no proxy header)', async () => {
|
119
|
-
participantMock.validateParticipant = jest.fn(async (fsp) => (fsp === EXTERNAL_DFSP_ID ? null : {}))
|
120
|
-
const headers = fixtures.partiesCallHeadersDto({
|
121
|
-
destination: '', proxy: ''
|
122
|
-
})
|
123
|
-
const params = fixtures.partiesParamsDto()
|
124
|
-
const service = new GetPartiesService(deps, { headers, params })
|
125
|
-
|
126
|
-
await service.handleRequest()
|
127
|
-
expect(participantMock.sendRequest.mock.calls.length).toBe(1)
|
128
|
-
const [sentHeaders, sendTo] = participantMock.sendRequest.mock.lastCall
|
129
|
-
expect(sendTo).toEqual(PROXY_ID)
|
130
|
-
expect(sentHeaders[Headers.FSPIOP.DESTINATION]).toBe(EXTERNAL_DFSP_ID)
|
131
|
-
})
|
132
|
-
|
133
|
-
test('should trigger inter-scheme discovery flow, if source is NOT in scheme', async () => {
|
134
|
-
const source = 'test-zm-dfsp'
|
135
|
-
const proxyZm = 'proxy-zm'
|
136
|
-
participantMock.validateParticipant = jest.fn(
|
137
|
-
async (fsp) => ([EXTERNAL_DFSP_ID, source].includes(fsp) ? null : {})
|
138
|
-
)
|
139
|
-
deps.proxies.getAllProxiesNames = jest.fn().mockResolvedValueOnce([PROXY_ID, proxyZm])
|
140
|
-
const headers = fixtures.partiesCallHeadersDto({
|
141
|
-
source, destination: '', proxy: proxyZm
|
142
|
-
})
|
143
|
-
const params = fixtures.partiesParamsDto()
|
144
|
-
const service = new GetPartiesService(deps, { headers, params })
|
145
|
-
|
146
|
-
await service.handleRequest()
|
147
|
-
expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
|
148
|
-
const [sentHeaders, sendTo] = participantMock.sendRequest.mock.lastCall
|
149
|
-
expect(sendTo).toEqual(PROXY_ID)
|
150
|
-
expect(sentHeaders[Headers.FSPIOP.DESTINATION]).toBeUndefined()
|
151
|
-
})
|
152
|
-
})
|
153
|
-
|
154
|
-
describe('setProxyGetPartiesTimeout Tests', () => {
|
155
|
-
test('should set getParties timeout for local source and external destination', async () => {
|
156
|
-
participantMock.validateParticipant = jest.fn()
|
157
|
-
.mockResolvedValueOnce({}) // source
|
158
|
-
.mockResolvedValueOnce(null) // destination
|
159
|
-
const proxyCache = createProxyCacheMock({
|
160
|
-
lookupProxyByDfspId: jest.fn().mockResolvedValueOnce('proxy-dest')
|
161
|
-
})
|
162
|
-
const deps = createMockDeps({ proxyCache })
|
163
|
-
const headers = fixtures.partiesCallHeadersDto()
|
164
|
-
const params = fixtures.partiesParamsDto()
|
165
|
-
const service = new GetPartiesService(deps, { headers, params })
|
166
|
-
|
167
|
-
await service.handleRequest()
|
168
|
-
expect(proxyCache.setProxyGetPartiesTimeout).toHaveBeenCalledTimes(1)
|
169
|
-
expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
|
170
|
-
})
|
171
|
-
|
172
|
-
test('should NOT set getParties timeout if source is external', async () => {
|
173
|
-
participantMock.validateParticipant = jest.fn()
|
174
|
-
.mockResolvedValueOnce(null) // source
|
175
|
-
.mockResolvedValueOnce({}) // proxy-src
|
176
|
-
const proxyCache = createProxyCacheMock({
|
177
|
-
lookupProxyByDfspId: jest.fn().mockResolvedValue('proxy-desc')
|
178
|
-
})
|
179
|
-
const deps = createMockDeps({ proxyCache })
|
180
|
-
const headers = fixtures.partiesCallHeadersDto({ proxy: 'proxy-src' })
|
181
|
-
const params = fixtures.partiesParamsDto()
|
182
|
-
const service = new GetPartiesService(deps, { headers, params })
|
183
|
-
|
184
|
-
await service.handleRequest()
|
185
|
-
expect(proxyCache.setProxyGetPartiesTimeout).not.toHaveBeenCalled()
|
186
|
-
expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
|
187
|
-
})
|
188
|
-
|
189
|
-
test('should NOT set getParties timeout if destination is local', async () => {
|
190
|
-
participantMock.validateParticipant = jest.fn().mockResolvedValue({})
|
191
|
-
const proxyCache = createProxyCacheMock()
|
192
|
-
const deps = createMockDeps({ proxyCache })
|
193
|
-
const headers = fixtures.partiesCallHeadersDto()
|
194
|
-
const params = fixtures.partiesParamsDto()
|
195
|
-
const service = new GetPartiesService(deps, { headers, params })
|
196
|
-
|
197
|
-
await service.handleRequest()
|
198
|
-
expect(proxyCache.setProxyGetPartiesTimeout).not.toHaveBeenCalled()
|
199
|
-
expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
|
200
|
-
})
|
201
|
-
|
202
|
-
test('should set getParties timeout if oracle returns external participant', async () => {
|
203
|
-
participantMock.validateParticipant = jest.fn()
|
204
|
-
.mockResolvedValueOnce({}) // source
|
205
|
-
.mockResolvedValueOnce(null) // externalDfsp
|
206
|
-
oracleMock.oracleRequest = jest.fn(async () => fixtures.oracleRequestResponseDto({
|
207
|
-
partyList: [{ fspId: 'externalDfsp' }]
|
208
|
-
}))
|
209
|
-
const proxyCache = createProxyCacheMock({
|
210
|
-
lookupProxyByDfspId: jest.fn().mockResolvedValue('proxyExternal')
|
211
|
-
})
|
212
|
-
const deps = createMockDeps({ proxyCache })
|
213
|
-
const headers = fixtures.partiesCallHeadersDto({ destination: '' })
|
214
|
-
const params = fixtures.partiesParamsDto()
|
215
|
-
const service = new GetPartiesService(deps, { headers, params })
|
216
|
-
|
217
|
-
await service.handleRequest()
|
218
|
-
expect(proxyCache.setProxyGetPartiesTimeout).toHaveBeenCalledTimes(1)
|
219
|
-
expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
|
220
|
-
})
|
221
|
-
})
|
222
|
-
})
|
@@ -1,49 +0,0 @@
|
|
1
|
-
/*****
|
2
|
-
License
|
3
|
-
--------------
|
4
|
-
Copyright © 2020-2025 Mojaloop Foundation
|
5
|
-
The Mojaloop files are made available by the Mojaloop 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
|
-
Mojaloop Foundation 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
|
-
* Mojaloop Foundation
|
23
|
-
* Eugen Klymniuk <eugen.klymniuk@infitx.com>
|
24
|
-
|
25
|
-
--------------
|
26
|
-
******/
|
27
|
-
|
28
|
-
const { createMockDeps, oracleMock } = require('./deps')
|
29
|
-
const { PutPartiesErrorService } = require('#src/domain/parties/services/index')
|
30
|
-
const fixtures = require('#test/fixtures/index')
|
31
|
-
|
32
|
-
const { RestMethods } = PutPartiesErrorService.enums()
|
33
|
-
|
34
|
-
describe('PutPartiesErrorService Tests -->', () => {
|
35
|
-
beforeEach(() => {
|
36
|
-
jest.clearAllMocks()
|
37
|
-
})
|
38
|
-
|
39
|
-
test('should cleanup oracle and trigger discovery flow for party from external dfsp', async () => {
|
40
|
-
const headers = fixtures.partiesCallHeadersDto({ proxy: 'proxyA' })
|
41
|
-
const params = fixtures.partiesParamsDto()
|
42
|
-
const service = new PutPartiesErrorService(createMockDeps(), { headers, params })
|
43
|
-
|
44
|
-
const needDiscovery = await service.handleRequest()
|
45
|
-
expect(needDiscovery).toBe(true)
|
46
|
-
expect(oracleMock.oracleRequest.mock.calls.length).toBe(1)
|
47
|
-
expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
|
48
|
-
})
|
49
|
-
})
|
@@ -1,49 +0,0 @@
|
|
1
|
-
/*****
|
2
|
-
License
|
3
|
-
--------------
|
4
|
-
Copyright © 2020-2025 Mojaloop Foundation
|
5
|
-
The Mojaloop files are made available by the Mojaloop 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
|
-
Mojaloop Foundation 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
|
-
* Mojaloop Foundation
|
23
|
-
* Eugen Klymniuk <eugen.klymniuk@infitx.com>
|
24
|
-
|
25
|
-
--------------
|
26
|
-
******/
|
27
|
-
|
28
|
-
jest.mock('#src/models/oracle/facade')
|
29
|
-
jest.mock('#src/models/participantEndpoint/facade')
|
30
|
-
|
31
|
-
const oracleMock = require('#src/models/oracle/facade')
|
32
|
-
const participantMock = require('#src/models/participantEndpoint/facade')
|
33
|
-
const { createDeps } = require('#src/domain/parties/deps')
|
34
|
-
const { logger } = require('#src/lib/index')
|
35
|
-
const { createProxyCacheMock } = require('#test/util/mockDeps')
|
36
|
-
|
37
|
-
/** @returns {PartiesDeps} */
|
38
|
-
const createMockDeps = ({
|
39
|
-
proxyCache = createProxyCacheMock(),
|
40
|
-
log = logger.child({ test: true }),
|
41
|
-
cache
|
42
|
-
} = {}) => createDeps({ cache, proxyCache, log })
|
43
|
-
|
44
|
-
module.exports = {
|
45
|
-
createMockDeps,
|
46
|
-
createProxyCacheMock,
|
47
|
-
oracleMock,
|
48
|
-
participantMock
|
49
|
-
}
|
package/test/util/mockDeps.js
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
/*****
|
2
|
-
License
|
3
|
-
--------------
|
4
|
-
Copyright © 2020-2025 Mojaloop Foundation
|
5
|
-
The Mojaloop files are made available by the Mojaloop 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
|
-
Mojaloop Foundation 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
|
-
* Mojaloop Foundation
|
23
|
-
* Eugen Klymniuk <eugen.klymniuk@infitx.com>
|
24
|
-
|
25
|
-
--------------
|
26
|
-
******/
|
27
|
-
|
28
|
-
const createProxyCacheMock = ({
|
29
|
-
addDfspIdToProxyMapping = jest.fn(async () => true),
|
30
|
-
isPendingCallback = jest.fn(async () => false),
|
31
|
-
lookupProxyByDfspId = jest.fn(async () => null),
|
32
|
-
receivedErrorResponse = jest.fn(async () => false),
|
33
|
-
receivedSuccessResponse = jest.fn(async () => true),
|
34
|
-
removeDfspIdFromProxyMapping = jest.fn(async () => true),
|
35
|
-
removeProxyGetPartiesTimeout = jest.fn(async () => true),
|
36
|
-
setProxyGetPartiesTimeout = jest.fn(async () => true),
|
37
|
-
setSendToProxiesList = jest.fn(async () => true)
|
38
|
-
} = {}) => ({
|
39
|
-
addDfspIdToProxyMapping,
|
40
|
-
isPendingCallback,
|
41
|
-
lookupProxyByDfspId,
|
42
|
-
receivedErrorResponse,
|
43
|
-
receivedSuccessResponse,
|
44
|
-
removeDfspIdFromProxyMapping,
|
45
|
-
removeProxyGetPartiesTimeout,
|
46
|
-
setProxyGetPartiesTimeout,
|
47
|
-
setSendToProxiesList
|
48
|
-
})
|
49
|
-
|
50
|
-
module.exports = {
|
51
|
-
createProxyCacheMock
|
52
|
-
}
|