account-lookup-service 17.7.1 → 17.8.0-snapshot.11

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +0 -7
  2. package/docker/mock-proxy/src/server.ts +13 -4
  3. package/package.json +10 -7
  4. package/src/constants.js +35 -2
  5. package/src/domain/parties/deps.js +11 -4
  6. package/src/domain/parties/getPartiesByTypeAndID.js +9 -13
  7. package/src/domain/parties/partiesUtils.js +4 -34
  8. package/src/domain/parties/putParties.js +26 -71
  9. package/src/domain/parties/services/BasePartiesService.js +143 -15
  10. package/src/domain/parties/services/GetPartiesService.js +210 -165
  11. package/src/domain/parties/services/PutPartiesErrorService.js +52 -28
  12. package/src/domain/parties/services/PutPartiesService.js +51 -33
  13. package/src/domain/parties/services/TimeoutPartiesService.js +84 -0
  14. package/src/domain/parties/services/index.js +3 -1
  15. package/src/domain/timeout/createSpan.js +55 -0
  16. package/src/domain/timeout/index.js +27 -36
  17. package/src/handlers/TimeoutHandler.js +2 -2
  18. package/src/index.js +3 -0
  19. package/src/lib/util.js +11 -3
  20. package/src/server.js +16 -5
  21. package/test/fixtures/index.js +53 -3
  22. package/test/integration/api/parties.test.js +1 -0
  23. package/test/integration/domain/timeout/index.test.js +83 -28
  24. package/test/unit/domain/parties/parties.test.js +26 -18
  25. package/test/unit/domain/parties/partiesUtils.test.js +51 -0
  26. package/test/unit/domain/parties/services/BasePartiesService.test.js +71 -0
  27. package/test/unit/domain/parties/services/GetPartiesService.test.js +316 -0
  28. package/test/unit/domain/parties/services/PutPartiesErrorService.test.js +50 -0
  29. package/test/unit/domain/parties/services/TimeoutPartiesService.test.js +72 -0
  30. package/test/unit/domain/parties/services/deps.js +51 -0
  31. package/test/unit/domain/timeout/index.test.js +17 -12
  32. package/test/util/apiClients/AlsApiClient.js +6 -4
  33. package/test/util/apiClients/BasicApiClient.js +33 -6
  34. package/test/util/apiClients/ProxyApiClient.js +46 -1
  35. package/test/util/index.js +5 -6
  36. package/test/util/mockDeps.js +72 -0
  37. package/src/domain/timeout/dto.js +0 -54
  38. package/test/unit/domain/parties/utils.test.js +0 -60
  39. package/test/unit/domain/timeout/dto.test.js +0 -24
@@ -0,0 +1,316 @@
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 { setTimeout: sleep } = require('node:timers/promises')
29
+ const {
30
+ createMockDeps,
31
+ createProxyCacheMock,
32
+ createProxiesUtilMock,
33
+ oracleMock,
34
+ participantMock
35
+ } = require('./deps')
36
+ // ↑ should be first require to mock external deps ↑
37
+ const { GetPartiesService } = require('#src/domain/parties/services/index')
38
+ const { API_TYPES, ERROR_MESSAGES } = require('#src/constants')
39
+ const fixtures = require('#test/fixtures/index')
40
+
41
+ const { RestMethods, Headers } = GetPartiesService.enums()
42
+
43
+ describe('GetPartiesService Tests -->', () => {
44
+ const { config } = createMockDeps()
45
+
46
+ beforeEach(() => {
47
+ jest.clearAllMocks()
48
+ })
49
+
50
+ describe('forwardRequestToDestination method', () => {
51
+ test('should delete party info from oracle, if no destination DFSP in proxy mapping', async () => {
52
+ participantMock.validateParticipant = jest.fn().mockResolvedValueOnce(null)
53
+ const proxyCache = createProxyCacheMock({
54
+ lookupProxyByDfspId: jest.fn().mockResolvedValueOnce(null)
55
+ })
56
+ const deps = createMockDeps({ proxyCache })
57
+
58
+ const destination = 'dfsp'
59
+ const headers = fixtures.partiesCallHeadersDto({ destination, proxy: 'proxy' })
60
+ const params = fixtures.partiesParamsDto()
61
+ const service = new GetPartiesService(deps, { headers, params })
62
+ service.triggerInterSchemeDiscoveryFlow = jest.fn()
63
+
64
+ await service.forwardRequestToDestination()
65
+
66
+ expect(oracleMock.oracleRequest.mock.calls.length).toBe(1)
67
+ const [sentHeaders, method, sentParams] = oracleMock.oracleRequest.mock.lastCall
68
+ expect(method).toBe(RestMethods.DELETE)
69
+ expect(sentHeaders).toEqual(headers)
70
+ expect(sentParams).toEqual(params)
71
+
72
+ expect(service.triggerInterSchemeDiscoveryFlow.mock.calls.length).toBe(1)
73
+ expect(service.triggerInterSchemeDiscoveryFlow.mock.lastCall[0]).toEqual({
74
+ ...headers,
75
+ [Headers.FSPIOP.DESTINATION]: undefined
76
+ })
77
+ })
78
+ })
79
+
80
+ describe('processOraclePartyList for external participants', () => {
81
+ const EXTERNAL_DFSP_ID = 'externalFsp'
82
+ const PROXY_ID = 'externalProxy'
83
+ let deps
84
+ let proxyCache
85
+
86
+ beforeEach(async () => {
87
+ oracleMock.oracleRequest = jest.fn().mockResolvedValueOnce(
88
+ fixtures.oracleRequestResponseDto({ partyList: [{ fspId: EXTERNAL_DFSP_ID }] })
89
+ )
90
+ participantMock.validateParticipant = jest.fn()
91
+ .mockResolvedValueOnce(null) // source
92
+ .mockResolvedValueOnce({}) // proxy
93
+
94
+ proxyCache = createProxyCacheMock({
95
+ addDfspIdToProxyMapping: jest.fn().mockResolvedValueOnce(true),
96
+ lookupProxyByDfspId: jest.fn().mockResolvedValueOnce(PROXY_ID)
97
+ })
98
+ deps = createMockDeps({ proxyCache })
99
+ })
100
+
101
+ test('should cleanup oracle and trigger interScheme discovery, if no proxyMapping for external dfsp', async () => {
102
+ proxyCache.lookupProxyByDfspId = jest.fn().mockResolvedValueOnce(null)
103
+ const headers = fixtures.partiesCallHeadersDto({
104
+ destination: '', proxy: 'proxyA'
105
+ })
106
+ const params = fixtures.partiesParamsDto()
107
+ const service = new GetPartiesService(deps, { headers, params })
108
+ service.triggerInterSchemeDiscoveryFlow = jest.fn()
109
+
110
+ await service.handleRequest()
111
+ expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(2) // GET + DELETE
112
+ expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
113
+ expect(service.triggerInterSchemeDiscoveryFlow).toHaveBeenCalledWith(headers)
114
+ })
115
+
116
+ test('should trigger interScheme discovery flow, if source is external', async () => {
117
+ const headers = fixtures.partiesCallHeadersDto({
118
+ destination: '', proxy: 'proxyA'
119
+ })
120
+ const params = fixtures.partiesParamsDto()
121
+ const service = new GetPartiesService(deps, { headers, params })
122
+ service.triggerInterSchemeDiscoveryFlow = jest.fn()
123
+
124
+ await service.handleRequest()
125
+ expect(service.triggerInterSchemeDiscoveryFlow).toHaveBeenCalledWith(headers)
126
+ })
127
+
128
+ test('should forward request, if source is in scheme (no proxy header)', async () => {
129
+ participantMock.validateParticipant = jest.fn(async (fsp) => (fsp === EXTERNAL_DFSP_ID ? null : {}))
130
+ const headers = fixtures.partiesCallHeadersDto({
131
+ destination: '', proxy: ''
132
+ })
133
+ const params = fixtures.partiesParamsDto()
134
+ const service = new GetPartiesService(deps, { headers, params })
135
+
136
+ await service.handleRequest()
137
+ expect(participantMock.sendRequest.mock.calls.length).toBe(1)
138
+ const [sentHeaders, sendTo] = participantMock.sendRequest.mock.lastCall
139
+ expect(sendTo).toEqual(PROXY_ID)
140
+ expect(sentHeaders[Headers.FSPIOP.DESTINATION]).toBe(EXTERNAL_DFSP_ID)
141
+ })
142
+
143
+ test('should trigger inter-scheme discovery flow, if source is NOT in scheme', async () => {
144
+ const source = 'test-zm-dfsp'
145
+ const proxyZm = 'proxy-zm'
146
+ participantMock.validateParticipant = jest.fn(
147
+ async (fsp) => ([EXTERNAL_DFSP_ID, source].includes(fsp) ? null : {})
148
+ )
149
+ deps.proxies.getAllProxiesNames = jest.fn().mockResolvedValueOnce([PROXY_ID, proxyZm])
150
+ const headers = fixtures.partiesCallHeadersDto({
151
+ source, destination: '', proxy: proxyZm
152
+ })
153
+ const params = fixtures.partiesParamsDto()
154
+ const service = new GetPartiesService(deps, { headers, params })
155
+
156
+ await service.handleRequest()
157
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
158
+ const [sentHeaders, sendTo] = participantMock.sendRequest.mock.lastCall
159
+ expect(sendTo).toEqual(PROXY_ID)
160
+ expect(sentHeaders[Headers.FSPIOP.DESTINATION]).toBeUndefined()
161
+ })
162
+ })
163
+
164
+ describe('triggerInterSchemeDiscoveryFlow Tests', () => {
165
+ test('should remove proxy from proxyCache if sending request to it fails', async () => {
166
+ expect.assertions(2)
167
+ participantMock.sendRequest = jest.fn().mockRejectedValue(new Error('Proxy error'))
168
+ const proxies = createProxiesUtilMock({
169
+ getAllProxiesNames: jest.fn().mockResolvedValue(['proxy-1'])
170
+ })
171
+ const deps = createMockDeps({ proxies })
172
+
173
+ const headers = fixtures.partiesCallHeadersDto({ destination: '' })
174
+ const params = fixtures.partiesParamsDto()
175
+ const service = new GetPartiesService(deps, { headers, params })
176
+
177
+ await expect(service.triggerInterSchemeDiscoveryFlow(headers))
178
+ .rejects.toThrow(ERROR_MESSAGES.proxyConnectionError)
179
+ expect(deps.proxyCache.receivedErrorResponse).toHaveBeenCalledTimes(1)
180
+ })
181
+
182
+ test('should NOT throw an error if at least one request is sent to a proxy', async () => {
183
+ participantMock.sendRequest = jest.fn()
184
+ .mockRejectedValueOnce(new Error('Proxy error'))
185
+ .mockResolvedValueOnce({})
186
+ const proxyOk = 'proxyOk'
187
+ const proxies = createProxiesUtilMock({
188
+ getAllProxiesNames: jest.fn().mockResolvedValue(['proxyErr', proxyOk])
189
+ })
190
+ const deps = createMockDeps({ proxies })
191
+
192
+ const headers = fixtures.partiesCallHeadersDto({ destination: '' })
193
+ const params = fixtures.partiesParamsDto()
194
+ const service = new GetPartiesService(deps, { headers, params })
195
+
196
+ const sentList = await service.triggerInterSchemeDiscoveryFlow(headers)
197
+ expect(sentList).toEqual([proxyOk])
198
+ expect(deps.proxyCache.receivedErrorResponse).toHaveBeenCalledTimes(1)
199
+ expect(participantMock.sendRequest.mock.lastCall[1]).toBe(proxyOk)
200
+ })
201
+
202
+ test('should throw an error if proxyRequest failed after delay, and other proxies have already replied', async () => {
203
+ expect.assertions(1)
204
+ let count = 0
205
+ participantMock.sendRequest = jest.fn(async () => {
206
+ count++
207
+ if (count !== 2) return {}
208
+ await sleep(1000) // throw delayed error for 2nd proxy call
209
+ throw new Error('Proxy delayed error')
210
+ })
211
+ const proxies = createProxiesUtilMock({
212
+ getAllProxiesNames: jest.fn().mockResolvedValue(['proxy1', 'proxy2'])
213
+ })
214
+ const proxyCache = createProxyCacheMock({
215
+ receivedErrorResponse: jest.fn().mockResolvedValue(true) // failed proxy request is last in inter-scheme discovery flow
216
+ })
217
+ const deps = createMockDeps({ proxies, proxyCache })
218
+
219
+ const headers = fixtures.partiesCallHeadersDto({ destination: '' })
220
+ const params = fixtures.partiesParamsDto()
221
+ const service = new GetPartiesService(deps, { headers, params })
222
+
223
+ await expect(service.triggerInterSchemeDiscoveryFlow(headers))
224
+ .rejects.toThrow(ERROR_MESSAGES.noSuccessfulProxyDiscoveryResponses)
225
+ })
226
+ })
227
+
228
+ describe('setProxyGetPartiesTimeout Tests', () => {
229
+ test('should set getParties timeout for local source and external destination', async () => {
230
+ participantMock.validateParticipant = jest.fn()
231
+ .mockResolvedValueOnce({}) // source
232
+ .mockResolvedValueOnce(null) // destination
233
+ const proxyId = 'proxy-destination'
234
+ const proxyCache = createProxyCacheMock({
235
+ lookupProxyByDfspId: jest.fn().mockResolvedValueOnce(proxyId)
236
+ })
237
+ const deps = createMockDeps({ proxyCache })
238
+ const headers = fixtures.partiesCallHeadersDto()
239
+ const params = fixtures.partiesParamsDto()
240
+ const service = new GetPartiesService(deps, { headers, params })
241
+
242
+ await service.handleRequest()
243
+ expect(proxyCache.setProxyGetPartiesTimeout).toHaveBeenCalledTimes(1)
244
+ expect(proxyCache.setProxyGetPartiesTimeout.mock.lastCall[1]).toBe(proxyId)
245
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
246
+ })
247
+
248
+ test('should NOT set getParties timeout if source is external', async () => {
249
+ participantMock.validateParticipant = jest.fn()
250
+ .mockResolvedValueOnce(null) // source
251
+ .mockResolvedValueOnce({}) // proxy-src
252
+ const proxyCache = createProxyCacheMock({
253
+ lookupProxyByDfspId: jest.fn().mockResolvedValue('proxy-desc')
254
+ })
255
+ const deps = createMockDeps({ proxyCache })
256
+ const headers = fixtures.partiesCallHeadersDto({ proxy: 'proxy-src' })
257
+ const params = fixtures.partiesParamsDto()
258
+ const service = new GetPartiesService(deps, { headers, params })
259
+
260
+ await service.handleRequest()
261
+ expect(proxyCache.setProxyGetPartiesTimeout).not.toHaveBeenCalled()
262
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
263
+ })
264
+
265
+ test('should NOT set getParties timeout if destination is local', async () => {
266
+ participantMock.validateParticipant = jest.fn().mockResolvedValue({})
267
+ const proxyCache = createProxyCacheMock()
268
+ const deps = createMockDeps({ proxyCache })
269
+ const headers = fixtures.partiesCallHeadersDto()
270
+ const params = fixtures.partiesParamsDto()
271
+ const service = new GetPartiesService(deps, { headers, params })
272
+
273
+ await service.handleRequest()
274
+ expect(proxyCache.setProxyGetPartiesTimeout).not.toHaveBeenCalled()
275
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
276
+ })
277
+
278
+ test('should set getParties timeout if oracle returns external participant', async () => {
279
+ participantMock.validateParticipant = jest.fn()
280
+ .mockResolvedValueOnce({}) // source
281
+ .mockResolvedValueOnce(null) // externalDfsp
282
+ oracleMock.oracleRequest = jest.fn(async () => fixtures.oracleRequestResponseDto({
283
+ partyList: [{ fspId: 'externalDfsp' }]
284
+ }))
285
+ const proxyCache = createProxyCacheMock({
286
+ lookupProxyByDfspId: jest.fn().mockResolvedValue('proxyExternal')
287
+ })
288
+ const deps = createMockDeps({ proxyCache })
289
+ const headers = fixtures.partiesCallHeadersDto({ destination: '' })
290
+ const params = fixtures.partiesParamsDto()
291
+ const service = new GetPartiesService(deps, { headers, params })
292
+
293
+ await service.handleRequest()
294
+ expect(proxyCache.setProxyGetPartiesTimeout).toHaveBeenCalledTimes(1)
295
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
296
+ })
297
+ })
298
+
299
+ test('should send partyNotFound callback in ISO20022 format', async () => {
300
+ participantMock.validateParticipant = jest.fn().mockResolvedValue({})
301
+ oracleMock.oracleRequest = jest.fn()
302
+ const deps = {
303
+ ...createMockDeps(),
304
+ config: { ...config, API_TYPE: API_TYPES.iso20022 }
305
+ }
306
+ const headers = fixtures.partiesCallHeadersDto({ destination: '' })
307
+ const params = fixtures.partiesParamsDto()
308
+ const service = new GetPartiesService(deps, { headers, params })
309
+
310
+ await service.handleRequest()
311
+ expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
312
+ const isoPayload = participantMock.sendErrorToParticipant.mock.lastCall[2]
313
+ expect(isoPayload.Assgnmt).toBeDefined()
314
+ expect(isoPayload.Rpt).toBeDefined()
315
+ })
316
+ })
@@ -0,0 +1,50 @@
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
+ // ↑ should be first require to mock external deps ↑
30
+ const { PutPartiesErrorService } = require('#src/domain/parties/services/index')
31
+ const fixtures = require('#test/fixtures/index')
32
+
33
+ const { RestMethods } = PutPartiesErrorService.enums()
34
+
35
+ describe('PutPartiesErrorService Tests -->', () => {
36
+ beforeEach(() => {
37
+ jest.clearAllMocks()
38
+ })
39
+
40
+ test('should cleanup oracle and trigger discovery flow for party from external dfsp', async () => {
41
+ const headers = fixtures.partiesCallHeadersDto({ proxy: 'proxyA' })
42
+ const params = fixtures.partiesParamsDto()
43
+ const service = new PutPartiesErrorService(createMockDeps(), { headers, params })
44
+
45
+ const needDiscovery = await service.handleRequest()
46
+ expect(needDiscovery).toBe(true)
47
+ expect(oracleMock.oracleRequest.mock.calls.length).toBe(1)
48
+ expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
49
+ })
50
+ })
@@ -0,0 +1,72 @@
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, participantMock } = require('./deps')
29
+ // ↑ should be first require to mock external deps ↑
30
+ const { TimeoutPartiesService } = require('#src/domain/parties/services/index')
31
+ const { API_TYPES } = require('#src/constants')
32
+ const fixtures = require('#test/fixtures/index')
33
+
34
+ describe('TimeoutPartiesService Tests -->', () => {
35
+ const { config } = createMockDeps()
36
+
37
+ beforeEach(() => {
38
+ jest.clearAllMocks()
39
+ })
40
+
41
+ test('should send error callback to external participant through proxy', async () => {
42
+ participantMock.validateParticipant = jest.fn().mockResolvedValue(null)
43
+ const proxy = 'proxyAB'
44
+ const proxyCache = createProxyCacheMock({
45
+ lookupProxyByDfspId: jest.fn().mockResolvedValue(proxy)
46
+ })
47
+ const deps = createMockDeps({ proxyCache })
48
+ const cacheKey = fixtures.expiredCacheKeyDto()
49
+ const service = TimeoutPartiesService.createInstance(deps, cacheKey, 'test')
50
+
51
+ await service.handleExpiredKey()
52
+ expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
53
+ expect(participantMock.sendErrorToParticipant.mock.lastCall[0]).toBe(proxy)
54
+ })
55
+
56
+ test('should send error callback in ISO20022 format', async () => {
57
+ participantMock.validateParticipant = jest.fn().mockResolvedValue({})
58
+ const deps = {
59
+ ...createMockDeps(),
60
+ config: { ...config, API_TYPE: API_TYPES.iso20022 }
61
+ }
62
+ const sourceId = 'sourceFsp'
63
+ const cacheKey = fixtures.expiredCacheKeyDto({ sourceId })
64
+ const service = TimeoutPartiesService.createInstance(deps, cacheKey, 'test')
65
+
66
+ await service.handleExpiredKey()
67
+ expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
68
+ const { Assgnr, Assgne } = participantMock.sendErrorToParticipant.mock.lastCall[2].Assgnmt
69
+ expect(Assgnr.Agt.FinInstnId.Othr.Id).toBe(config.HUB_NAME)
70
+ expect(Assgne.Agt.FinInstnId.Othr.Id).toBe(sourceId)
71
+ })
72
+ })
@@ -0,0 +1,51 @@
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, createProxiesUtilMock } = require('#test/util/mockDeps')
36
+
37
+ /** @returns {PartiesDeps} */
38
+ const createMockDeps = ({
39
+ proxyCache = createProxyCacheMock(),
40
+ proxies = createProxiesUtilMock(),
41
+ log = logger.child({ test: true }),
42
+ cache
43
+ } = {}) => createDeps({ cache, proxyCache, proxies, log })
44
+
45
+ module.exports = {
46
+ createMockDeps,
47
+ createProxyCacheMock,
48
+ createProxiesUtilMock,
49
+ oracleMock,
50
+ participantMock
51
+ }
@@ -31,11 +31,13 @@
31
31
 
32
32
  'use strict'
33
33
 
34
- const Participant = require('../../../../src/models/participantEndpoint/facade')
35
- const TimeoutDomain = require('../../../../src/domain/timeout')
36
34
  const Metrics = require('@mojaloop/central-services-metrics')
35
+ const Participant = require('#src/models/participantEndpoint/facade')
36
+ const TimeoutDomain = require('#src/domain/timeout/index')
37
+ const { mockDeps } = require('#test/util/index')
37
38
 
38
39
  describe('Timeout Domain', () => {
40
+ const proxyCache = mockDeps.createProxyCacheMock()
39
41
  // Initialize Metrics for testing
40
42
  Metrics.getCounter(
41
43
  'errorCount',
@@ -56,24 +58,25 @@ describe('Timeout Domain', () => {
56
58
  describe('timeoutInterschemePartiesLookups', () => {
57
59
  describe('timeoutInterschemePartiesLookups', () => {
58
60
  it('should process expired ALS keys', async () => {
59
- const mockCache = { processExpiredAlsKeys: jest.fn() }
60
- await TimeoutDomain.timeoutInterschemePartiesLookups({ proxyCache: mockCache, batchSize: 10 })
61
- expect(mockCache.processExpiredAlsKeys).toHaveBeenCalledWith(TimeoutDomain.sendTimeoutCallback, 10)
61
+ const batchSize = 10
62
+ await TimeoutDomain.timeoutInterschemePartiesLookups({ proxyCache, batchSize })
63
+ expect(proxyCache.processExpiredAlsKeys).toHaveBeenCalledWith(expect.any(Function), batchSize)
64
+ expect(Participant.sendErrorToParticipant).toHaveBeenCalled()
62
65
  })
63
66
  })
64
67
 
65
68
  describe('sendTimeoutCallback', () => {
66
69
  it('should send error to participant', async () => {
67
- jest.spyOn(Participant, 'validateParticipant').mockResolvedValue({ fspId: 'sourceId' })
70
+ const SOURCE_ID = 'sourceId'
71
+ jest.spyOn(Participant, 'validateParticipant').mockResolvedValue({ fspId: SOURCE_ID })
68
72
 
69
- const cacheKey = 'als:sourceId:2:3:expiresAt'
70
- const [, destination] = cacheKey.split(':')
73
+ const cacheKey = `als:${SOURCE_ID}:2:3` // ':expiresAt' part is removed inside proxyCache.processExpiryKey()
71
74
 
72
- await TimeoutDomain.sendTimeoutCallback(cacheKey)
75
+ await TimeoutDomain.sendTimeoutCallback(cacheKey, proxyCache)
73
76
 
74
- expect(Participant.validateParticipant).toHaveBeenCalledWith('sourceId')
77
+ expect(Participant.validateParticipant).toHaveBeenCalledWith(SOURCE_ID)
75
78
  expect(Participant.sendErrorToParticipant).toHaveBeenCalledWith(
76
- destination,
79
+ SOURCE_ID,
77
80
  'FSPIOP_CALLBACK_URL_PARTIES_PUT_ERROR',
78
81
  { errorInformation: { errorCode: '3300', errorDescription: 'Generic expired error' } },
79
82
  expect.any(Object), expect.any(Object), undefined, expect.any(Object)
@@ -82,7 +85,9 @@ describe('Timeout Domain', () => {
82
85
 
83
86
  it('should throw error if participant validation fails', async () => {
84
87
  Participant.validateParticipant.mockResolvedValue(null)
85
- await expect(TimeoutDomain.sendTimeoutCallback('als:sourceId:2:3:expiresAt')).rejects.toThrow()
88
+ await expect(
89
+ TimeoutDomain.sendTimeoutCallback('als:sourceId:2:3:expiresAt', proxyCache)
90
+ ).rejects.toThrow()
86
91
  })
87
92
  })
88
93
  })
@@ -8,9 +8,9 @@ class AlsProxyApiClient extends BasicApiClient {
8
8
  super({ ...deps, baseURL })
9
9
  }
10
10
 
11
- async getPartyByIdAndType ({ partyId, partyIdType, source, destination, proxy = '' }) {
11
+ async getPartyByIdAndType ({ partyId, partyIdType, source, destination, proxy = '', addHeaders = null }) {
12
12
  return this.sendPartyRequest({
13
- partyId, partyIdType, source, destination, proxy
13
+ partyId, partyIdType, source, destination, proxy, addHeaders
14
14
  })
15
15
  }
16
16
 
@@ -27,10 +27,12 @@ class AlsProxyApiClient extends BasicApiClient {
27
27
  })
28
28
  }
29
29
 
30
- async sendPartyRequest ({ partyId, partyIdType, source, destination, proxy = '', body = null, isError = false }) {
30
+ async sendPartyRequest ({
31
+ partyId, partyIdType, source, destination, proxy = '', body = null, isError = false, addHeaders = null
32
+ }) {
31
33
  const method = body ? 'PUT' : 'GET'
32
34
  const url = `/parties/${partyIdType}/${partyId}${isError ? '/error' : ''}`
33
- const headers = this.fixtures.partiesCallHeadersDto({ source, destination, proxy })
35
+ const headers = this.fixtures.partiesCallHeadersDto({ source, destination, proxy, addHeaders })
34
36
 
35
37
  return this.sendRequest({
36
38
  method,
@@ -1,16 +1,43 @@
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
+
1
28
  const axiosLib = require('axios')
2
- const lib = require('../../../src/lib')
3
- const fixtures = require('../../fixtures')
29
+ const { logger } = require('#src/lib/index')
30
+ const fixtures = require('#test/fixtures/index')
4
31
 
5
32
  class BasicApiClient {
6
33
  constructor ({
7
34
  baseURL,
8
35
  axios = axiosLib.create({ baseURL }),
9
- logger = lib.logger.child(this.constructor.name)
36
+ log = logger.child({ component: this.constructor.name })
10
37
  } = {}) {
11
38
  this.baseURL = baseURL
12
39
  this.axios = axios
13
- this.logger = logger
40
+ this.log = log
14
41
  this.fixtures = fixtures
15
42
  }
16
43
 
@@ -22,10 +49,10 @@ class BasicApiClient {
22
49
  headers,
23
50
  data: body
24
51
  })
25
- this.logger.info('sendRequest is done:', { method, url, body, headers, response: { status, data } })
52
+ this.log.info(`sendRequest is done [${method} ${url}]:`, { method, url, body, headers, response: { status, data } })
26
53
  return { data, status }
27
54
  } catch (err) {
28
- this.logger.error('error in sendRequest: ', err)
55
+ this.log.error('error in sendRequest: ', err)
29
56
  throw err
30
57
  }
31
58
  }