account-lookup-service 17.7.0-snapshot.4 → 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.
@@ -1,224 +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 proxyId = 'proxy-destination'
160
- const proxyCache = createProxyCacheMock({
161
- lookupProxyByDfspId: jest.fn().mockResolvedValueOnce(proxyId)
162
- })
163
- const deps = createMockDeps({ proxyCache })
164
- const headers = fixtures.partiesCallHeadersDto()
165
- const params = fixtures.partiesParamsDto()
166
- const service = new GetPartiesService(deps, { headers, params })
167
-
168
- await service.handleRequest()
169
- expect(proxyCache.setProxyGetPartiesTimeout).toHaveBeenCalledTimes(1)
170
- expect(proxyCache.setProxyGetPartiesTimeout.mock.lastCall[1]).toBe(proxyId)
171
- expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
172
- })
173
-
174
- test('should NOT set getParties timeout if source is external', async () => {
175
- participantMock.validateParticipant = jest.fn()
176
- .mockResolvedValueOnce(null) // source
177
- .mockResolvedValueOnce({}) // proxy-src
178
- const proxyCache = createProxyCacheMock({
179
- lookupProxyByDfspId: jest.fn().mockResolvedValue('proxy-desc')
180
- })
181
- const deps = createMockDeps({ proxyCache })
182
- const headers = fixtures.partiesCallHeadersDto({ proxy: 'proxy-src' })
183
- const params = fixtures.partiesParamsDto()
184
- const service = new GetPartiesService(deps, { headers, params })
185
-
186
- await service.handleRequest()
187
- expect(proxyCache.setProxyGetPartiesTimeout).not.toHaveBeenCalled()
188
- expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
189
- })
190
-
191
- test('should NOT set getParties timeout if destination is local', async () => {
192
- participantMock.validateParticipant = jest.fn().mockResolvedValue({})
193
- const proxyCache = createProxyCacheMock()
194
- const deps = createMockDeps({ proxyCache })
195
- const headers = fixtures.partiesCallHeadersDto()
196
- const params = fixtures.partiesParamsDto()
197
- const service = new GetPartiesService(deps, { headers, params })
198
-
199
- await service.handleRequest()
200
- expect(proxyCache.setProxyGetPartiesTimeout).not.toHaveBeenCalled()
201
- expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
202
- })
203
-
204
- test('should set getParties timeout if oracle returns external participant', async () => {
205
- participantMock.validateParticipant = jest.fn()
206
- .mockResolvedValueOnce({}) // source
207
- .mockResolvedValueOnce(null) // externalDfsp
208
- oracleMock.oracleRequest = jest.fn(async () => fixtures.oracleRequestResponseDto({
209
- partyList: [{ fspId: 'externalDfsp' }]
210
- }))
211
- const proxyCache = createProxyCacheMock({
212
- lookupProxyByDfspId: jest.fn().mockResolvedValue('proxyExternal')
213
- })
214
- const deps = createMockDeps({ proxyCache })
215
- const headers = fixtures.partiesCallHeadersDto({ destination: '' })
216
- const params = fixtures.partiesParamsDto()
217
- const service = new GetPartiesService(deps, { headers, params })
218
-
219
- await service.handleRequest()
220
- expect(proxyCache.setProxyGetPartiesTimeout).toHaveBeenCalledTimes(1)
221
- expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
222
- })
223
- })
224
- })
@@ -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
- }
@@ -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
- }