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

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 (34) hide show
  1. package/CHANGELOG.md +0 -7
  2. package/package.json +8 -5
  3. package/src/constants.js +34 -2
  4. package/src/domain/parties/deps.js +11 -4
  5. package/src/domain/parties/getPartiesByTypeAndID.js +9 -13
  6. package/src/domain/parties/partiesUtils.js +4 -34
  7. package/src/domain/parties/putParties.js +26 -71
  8. package/src/domain/parties/services/BasePartiesService.js +143 -15
  9. package/src/domain/parties/services/GetPartiesService.js +194 -164
  10. package/src/domain/parties/services/PutPartiesErrorService.js +51 -27
  11. package/src/domain/parties/services/PutPartiesService.js +51 -33
  12. package/src/domain/parties/services/TimeoutPartiesService.js +84 -0
  13. package/src/domain/parties/services/index.js +3 -1
  14. package/src/domain/timeout/createSpan.js +55 -0
  15. package/src/domain/timeout/index.js +27 -36
  16. package/src/handlers/TimeoutHandler.js +2 -2
  17. package/src/lib/util.js +11 -3
  18. package/test/fixtures/index.js +46 -0
  19. package/test/integration/domain/timeout/index.test.js +83 -28
  20. package/test/unit/domain/parties/parties.test.js +26 -18
  21. package/test/unit/domain/parties/partiesUtils.test.js +51 -0
  22. package/test/unit/domain/parties/services/BasePartiesService.test.js +71 -0
  23. package/test/unit/domain/parties/services/GetPartiesService.test.js +245 -0
  24. package/test/unit/domain/parties/services/PutPartiesErrorService.test.js +50 -0
  25. package/test/unit/domain/parties/services/TimeoutPartiesService.test.js +72 -0
  26. package/test/unit/domain/parties/services/deps.js +51 -0
  27. package/test/unit/domain/timeout/index.test.js +17 -12
  28. package/test/util/apiClients/BasicApiClient.js +33 -6
  29. package/test/util/apiClients/ProxyApiClient.js +46 -1
  30. package/test/util/index.js +5 -6
  31. package/test/util/mockDeps.js +72 -0
  32. package/src/domain/timeout/dto.js +0 -54
  33. package/test/unit/domain/parties/utils.test.js +0 -60
  34. package/test/unit/domain/timeout/dto.test.js +0 -24
@@ -56,7 +56,7 @@ const fixtures = require('../../../fixtures')
56
56
  const { type: proxyCacheType, proxyConfig: proxyCacheConfig } = Config.PROXY_CACHE_CONFIG
57
57
 
58
58
  const { encodePayload } = Util.StreamingProtocol
59
- const { RestMethods } = Enum.Http
59
+ const { RestMethods, Headers } = Enum.Http
60
60
 
61
61
  Logger.isDebugEnabled = jest.fn(() => true)
62
62
  Logger.isErrorEnabled = jest.fn(() => true)
@@ -192,24 +192,26 @@ describe('Parties Tests', () => {
192
192
  expect(cached).toBe(proxy)
193
193
  })
194
194
 
195
- it('should send error callback if destination is not in the scheme, and not in proxyCache', async () => {
195
+ it('should cleanup oracle and trigger discovery flow, if destination is not in scheme and no dfsp-to-proxy mapping', async () => {
196
+ Config.PROXY_CACHE_CONFIG.enabled = true
196
197
  participant.validateParticipant = sandbox.stub()
197
198
  .onFirstCall().resolves({}) // source
198
199
  .onSecondCall().resolves(null) // destination
199
200
  participant.sendRequest = sandbox.stub().resolves()
200
201
  participant.sendErrorToParticipant = sandbox.stub().resolves()
201
202
  sandbox.stub(oracle, 'oracleRequest')
203
+ const proxy = 'some-proxy'
204
+ Util.proxies.getAllProxiesNames = sandbox.stub().resolves([proxy])
202
205
  const headers = fixtures.partiesCallHeadersDto()
203
206
 
204
207
  await partiesDomain.getPartiesByTypeAndID(headers, Helper.getByTypeIdRequest.params, Helper.getByTypeIdRequest.method, Helper.getByTypeIdRequest.query, Helper.mockSpan(), null, proxyCache)
205
208
 
206
- expect(participant.sendRequest.callCount).toBe(0)
207
- expect(oracle.oracleRequest.callCount).toBe(0)
208
- expect(participant.sendErrorToParticipant.callCount).toBe(1)
209
-
210
- const { errorInformation } = participant.sendErrorToParticipant.getCall(0).args[2]
211
- expect(errorInformation.errorCode).toBe('3200')
212
- expect(errorInformation.errorDescription).toContain(ERROR_MESSAGES.partyDestinationFspNotFound)
209
+ expect(oracle.oracleRequest.lastCall.args[1]).toBe(RestMethods.DELETE)
210
+ expect(participant.sendErrorToParticipant.callCount).toBe(0)
211
+ expect(participant.sendRequest.callCount).toBe(1)
212
+ // eslint-disable-next-line no-unused-vars
213
+ const [_, sendTo] = participant.sendRequest.lastCall.args
214
+ expect(sendTo).toBe(proxy)
213
215
  })
214
216
 
215
217
  it('should send request to proxy, if destination is not in the scheme, but has proxyMapping', async () => {
@@ -470,7 +472,7 @@ describe('Parties Tests', () => {
470
472
  expect(firstCallArgs[2]).toBe(expectedCallbackEnpointType)
471
473
  })
472
474
 
473
- it('should send request to proxy if oracle returns dfsp NOT from the scheme', async () => {
475
+ it('should send errorCallback if oracle returns external dfsp, and source is external', async () => {
474
476
  Config.PROXY_CACHE_CONFIG.enabled = true
475
477
  const proxyName = `proxy-${Date.now()}`
476
478
  const fspId = `dfspNotFromScheme-${Date.now()}`
@@ -479,7 +481,7 @@ describe('Parties Tests', () => {
479
481
  })
480
482
  sandbox.stub(oracle, 'oracleRequest').resolves(oracleResponse)
481
483
  participant.validateParticipant = sandbox.stub()
482
- .onFirstCall().resolves({}) // source
484
+ .onFirstCall().resolves(null) // source
483
485
  .onSecondCall().resolves(null) // oracle dfsp
484
486
  participant.sendRequest = sandbox.stub().resolves()
485
487
  participant.sendErrorToParticipant = sandbox.stub().resolves()
@@ -487,15 +489,20 @@ describe('Parties Tests', () => {
487
489
  const isAdded = await proxyCache.addDfspIdToProxyMapping(fspId, proxyName)
488
490
  expect(isAdded).toBe(true)
489
491
 
490
- const headers = fixtures.partiesCallHeadersDto({ destination: '' })
492
+ const source = `fromDfsp-${Date.now()}`
493
+ const headers = fixtures.partiesCallHeadersDto({ destination: '', source, proxy: 'proxy' })
491
494
  const { params, method, query } = Helper.getByTypeIdRequest
492
495
 
493
496
  await partiesDomain.getPartiesByTypeAndID(headers, params, method, query, null, null, proxyCache)
494
497
 
495
- expect(participant.sendErrorToParticipant.callCount).toBe(0)
496
- expect(participant.sendRequest.callCount).toBe(1)
497
- const calledProxy = participant.sendRequest.getCall(0).args[1]
498
- expect(calledProxy).toBe(proxyName)
498
+ expect(participant.sendRequest.callCount).toBe(0)
499
+ expect(participant.sendErrorToParticipant.callCount).toBe(1)
500
+ // eslint-disable-next-line no-unused-vars
501
+ const [sentTo, _, payload, sentHeaders] = participant.sendErrorToParticipant.lastCall.args
502
+ expect(sentTo).toBe(source)
503
+ expect(payload.errorInformation.errorCode).toBe('3200')
504
+ expect(sentHeaders[Headers.FSPIOP.SOURCE]).toBe(Config.HUB_NAME)
505
+ expect(sentHeaders[Headers.FSPIOP.DESTINATION]).toBe(headers[Headers.FSPIOP.SOURCE])
499
506
  })
500
507
 
501
508
  it('handles error when `oracleRequest` returns no result', async () => {
@@ -554,13 +561,14 @@ describe('Parties Tests', () => {
554
561
  participant.sendRequest = sandbox.stub().rejects(new Error('Some network issue'))
555
562
  participant.sendErrorToParticipant = sandbox.stub().resolves()
556
563
  const headers = fixtures.partiesCallHeadersDto({ destination: '' })
564
+ const params = fixtures.partiesParamsDto()
557
565
 
558
- await partiesDomain.getPartiesByTypeAndID(headers, Helper.getByTypeIdRequest.params, Helper.getByTypeIdRequest.method, Helper.getByTypeIdRequest.query, Helper.mockSpan(), null, proxyCache)
566
+ await partiesDomain.getPartiesByTypeAndID(headers, params, Helper.getByTypeIdRequest.method, Helper.getByTypeIdRequest.query, Helper.mockSpan(), null, proxyCache)
559
567
 
560
568
  expect(participant.sendRequest.callCount).toBe(proxyNames.length)
561
569
  expect(participant.sendErrorToParticipant.callCount).toBe(1)
562
570
 
563
- const { errorInformation } = participant.sendErrorToParticipant.getCall(0).args[2]
571
+ const { errorInformation } = participant.sendErrorToParticipant.lastCall.args[2]
564
572
  expect(errorInformation.errorCode).toBe('3200')
565
573
  expect(errorInformation.errorDescription).toContain(ERROR_MESSAGES.proxyConnectionError)
566
574
  })
@@ -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
+ 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
+
9
+ Contributors
10
+ --------------
11
+ This is the official list of the Mojaloop project contributors for this file.
12
+ Names of the original copyright holders (individuals or organizations)
13
+ should be listed with a '*' in the first column. People who have
14
+ contributed from an organization can be listed under the organization
15
+ that actually holds the copyright for their contributions (see the
16
+ Mojaloop Foundation organization for an example). Those individuals should have
17
+ their names indented and be marked with a '-'. Email address can be added
18
+ optionally within square brackets <email>.
19
+ * Mojaloop Foundation
20
+ - Name Surname <name.surname@mojaloop.io>
21
+
22
+ * Eugen Klymniuk <eugen.klymniuk@infitx.com>
23
+ --------------
24
+ **********/
25
+
26
+ const ErrorHandler = require('@mojaloop/central-services-error-handling')
27
+ const partiesUtils = require('#src/domain/parties/partiesUtils')
28
+ const config = require('#src/lib/config')
29
+ const { API_TYPES } = require('#src/constants')
30
+ const fixtures = require('#test/fixtures/index')
31
+
32
+ describe('partiesUtils Tests -->', () => {
33
+ describe('makePutPartiesErrorPayload Tests', () => {
34
+ const error = ErrorHandler.Factory.reformatFSPIOPError(new Error('Test Error'))
35
+ const ERR_CODE = '2001'
36
+ const headers = fixtures.partiesCallHeadersDto()
37
+ const params = fixtures.partiesParamsDto()
38
+
39
+ test('should make putParties error payload in FSPIOP format', async () => {
40
+ const fspiopConfig = { ...config, API_TYPE: API_TYPES.fspiop }
41
+ const payload = await partiesUtils.makePutPartiesErrorPayload(fspiopConfig, error, headers, params)
42
+ expect(payload.errorInformation.errorCode).toBe(ERR_CODE)
43
+ })
44
+
45
+ test('should make putParties error payload in ISO20022 format', async () => {
46
+ const fspiopConfig = { ...config, API_TYPE: API_TYPES.iso20022 }
47
+ const payload = await partiesUtils.makePutPartiesErrorPayload(fspiopConfig, error, headers, params)
48
+ expect(payload.Rpt.Rsn.Cd).toBe(ERR_CODE)
49
+ })
50
+ })
51
+ })
@@ -0,0 +1,71 @@
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, participantMock } = require('./deps')
29
+ // ↑ should be first require to mock external deps ↑
30
+ const BasePartiesService = require('#src/domain/parties/services/BasePartiesService')
31
+ const config = require('#src/lib/config')
32
+ const { API_TYPES } = require('#src/constants')
33
+ const fixtures = require('#test/fixtures/index')
34
+
35
+ describe('BasePartiesService Tests -->', () => {
36
+ beforeEach(() => {
37
+ jest.clearAllMocks()
38
+ })
39
+
40
+ test('should send error party callback in ISO20022 format', async () => {
41
+ const deps = {
42
+ ...createMockDeps(),
43
+ config: { ...config, API_TYPE: API_TYPES.iso20022 }
44
+ }
45
+ const source = 'sourceFsp'
46
+ const headers = fixtures.partiesCallHeadersDto({ source })
47
+ const params = fixtures.partiesParamsDto()
48
+ const service = new BasePartiesService(deps, { headers, params })
49
+
50
+ await service.handleError(new Error('test error'))
51
+ expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
52
+ // eslint-disable-next-line no-unused-vars
53
+ const [sentTo, _, payload] = participantMock.sendErrorToParticipant.mock.lastCall
54
+ expect(sentTo).toBe(source)
55
+ expect(payload.Rpt.Rsn.Cd).toBe('2001')
56
+ expect(payload.Rpt.OrgnlId).toBe(`${params.Type}/${params.ID}`)
57
+ expect(payload.Assgnmt.Assgnr.Agt.FinInstnId.Othr.Id).toBe(source)
58
+ })
59
+
60
+ test('should remove proxy getParties timeout cache key', async () => {
61
+ const deps = createMockDeps()
62
+ const proxy = 'proxyAB'
63
+ const headers = fixtures.partiesCallHeadersDto({ proxy })
64
+ const params = fixtures.partiesParamsDto()
65
+ const alsReq = {}
66
+ const service = new BasePartiesService(deps, { headers, params })
67
+
68
+ await service.removeProxyGetPartiesTimeoutCache(alsReq)
69
+ expect(deps.proxyCache.removeProxyGetPartiesTimeout).toHaveBeenCalledWith(alsReq, proxy)
70
+ })
71
+ })
@@ -0,0 +1,245 @@
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 { API_TYPES } = require('#src/constants')
32
+ const fixtures = require('#test/fixtures/index')
33
+
34
+ const { RestMethods, Headers } = GetPartiesService.enums()
35
+
36
+ describe('GetPartiesService Tests -->', () => {
37
+ const { config } = createMockDeps()
38
+
39
+ beforeEach(() => {
40
+ jest.clearAllMocks()
41
+ })
42
+
43
+ describe('forwardRequestToDestination method', () => {
44
+ test('should delete party info from oracle, if no destination DFSP in proxy mapping', async () => {
45
+ participantMock.validateParticipant = jest.fn().mockResolvedValueOnce(null)
46
+ const proxyCache = createProxyCacheMock({
47
+ lookupProxyByDfspId: jest.fn().mockResolvedValueOnce(null)
48
+ })
49
+ const deps = createMockDeps({ proxyCache })
50
+
51
+ const destination = 'dfsp'
52
+ const headers = fixtures.partiesCallHeadersDto({ destination, proxy: 'proxy' })
53
+ const params = fixtures.partiesParamsDto()
54
+ const service = new GetPartiesService(deps, { headers, params })
55
+ service.triggerInterSchemeDiscoveryFlow = jest.fn()
56
+
57
+ await service.forwardRequestToDestination()
58
+
59
+ expect(oracleMock.oracleRequest.mock.calls.length).toBe(1)
60
+ const [sentHeaders, method, sentParams] = oracleMock.oracleRequest.mock.lastCall
61
+ expect(method).toBe(RestMethods.DELETE)
62
+ expect(sentHeaders).toEqual(headers)
63
+ expect(sentParams).toEqual(params)
64
+
65
+ expect(service.triggerInterSchemeDiscoveryFlow.mock.calls.length).toBe(1)
66
+ expect(service.triggerInterSchemeDiscoveryFlow.mock.lastCall[0]).toEqual({
67
+ ...headers,
68
+ [Headers.FSPIOP.DESTINATION]: undefined
69
+ })
70
+ })
71
+ })
72
+
73
+ describe('processOraclePartyList for external participants', () => {
74
+ const EXTERNAL_DFSP_ID = 'externalFsp'
75
+ const PROXY_ID = 'externalProxy'
76
+ let deps
77
+ let proxyCache
78
+
79
+ beforeEach(async () => {
80
+ oracleMock.oracleRequest = jest.fn().mockResolvedValueOnce(
81
+ fixtures.oracleRequestResponseDto({ partyList: [{ fspId: EXTERNAL_DFSP_ID }] })
82
+ )
83
+ participantMock.validateParticipant = jest.fn()
84
+ .mockResolvedValueOnce(null) // source
85
+ .mockResolvedValueOnce({}) // proxy
86
+
87
+ proxyCache = createProxyCacheMock({
88
+ addDfspIdToProxyMapping: jest.fn().mockResolvedValueOnce(true),
89
+ lookupProxyByDfspId: jest.fn().mockResolvedValueOnce(PROXY_ID)
90
+ })
91
+ deps = createMockDeps({ proxyCache })
92
+ })
93
+
94
+ test('should cleanup oracle and trigger interScheme discovery, if no proxyMapping for external dfsp', async () => {
95
+ proxyCache.lookupProxyByDfspId = jest.fn().mockResolvedValueOnce(null)
96
+ const headers = fixtures.partiesCallHeadersDto({
97
+ destination: '', proxy: 'proxyA'
98
+ })
99
+ const params = fixtures.partiesParamsDto()
100
+ const service = new GetPartiesService(deps, { headers, params })
101
+ service.triggerInterSchemeDiscoveryFlow = jest.fn()
102
+
103
+ await service.handleRequest()
104
+ expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(2) // GET + DELETE
105
+ expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
106
+ expect(service.triggerInterSchemeDiscoveryFlow).toHaveBeenCalledWith(headers)
107
+ })
108
+
109
+ test('should trigger interScheme discovery flow, if source is external', async () => {
110
+ const headers = fixtures.partiesCallHeadersDto({
111
+ destination: '', proxy: 'proxyA'
112
+ })
113
+ const params = fixtures.partiesParamsDto()
114
+ const service = new GetPartiesService(deps, { headers, params })
115
+ service.triggerInterSchemeDiscoveryFlow = jest.fn()
116
+
117
+ await service.handleRequest()
118
+ expect(service.triggerInterSchemeDiscoveryFlow).toHaveBeenCalledWith(headers)
119
+ })
120
+
121
+ test('should forward request, if source is in scheme (no proxy header)', async () => {
122
+ participantMock.validateParticipant = jest.fn(async (fsp) => (fsp === EXTERNAL_DFSP_ID ? null : {}))
123
+ const headers = fixtures.partiesCallHeadersDto({
124
+ destination: '', proxy: ''
125
+ })
126
+ const params = fixtures.partiesParamsDto()
127
+ const service = new GetPartiesService(deps, { headers, params })
128
+
129
+ await service.handleRequest()
130
+ expect(participantMock.sendRequest.mock.calls.length).toBe(1)
131
+ const [sentHeaders, sendTo] = participantMock.sendRequest.mock.lastCall
132
+ expect(sendTo).toEqual(PROXY_ID)
133
+ expect(sentHeaders[Headers.FSPIOP.DESTINATION]).toBe(EXTERNAL_DFSP_ID)
134
+ })
135
+
136
+ test('should trigger inter-scheme discovery flow, if source is NOT in scheme', async () => {
137
+ const source = 'test-zm-dfsp'
138
+ const proxyZm = 'proxy-zm'
139
+ participantMock.validateParticipant = jest.fn(
140
+ async (fsp) => ([EXTERNAL_DFSP_ID, source].includes(fsp) ? null : {})
141
+ )
142
+ deps.proxies.getAllProxiesNames = jest.fn().mockResolvedValueOnce([PROXY_ID, proxyZm])
143
+ const headers = fixtures.partiesCallHeadersDto({
144
+ source, destination: '', proxy: proxyZm
145
+ })
146
+ const params = fixtures.partiesParamsDto()
147
+ const service = new GetPartiesService(deps, { headers, params })
148
+
149
+ await service.handleRequest()
150
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
151
+ const [sentHeaders, sendTo] = participantMock.sendRequest.mock.lastCall
152
+ expect(sendTo).toEqual(PROXY_ID)
153
+ expect(sentHeaders[Headers.FSPIOP.DESTINATION]).toBeUndefined()
154
+ })
155
+ })
156
+
157
+ describe('setProxyGetPartiesTimeout Tests', () => {
158
+ test('should set getParties timeout for local source and external destination', async () => {
159
+ participantMock.validateParticipant = jest.fn()
160
+ .mockResolvedValueOnce({}) // source
161
+ .mockResolvedValueOnce(null) // destination
162
+ const proxyId = 'proxy-destination'
163
+ const proxyCache = createProxyCacheMock({
164
+ lookupProxyByDfspId: jest.fn().mockResolvedValueOnce(proxyId)
165
+ })
166
+ const deps = createMockDeps({ proxyCache })
167
+ const headers = fixtures.partiesCallHeadersDto()
168
+ const params = fixtures.partiesParamsDto()
169
+ const service = new GetPartiesService(deps, { headers, params })
170
+
171
+ await service.handleRequest()
172
+ expect(proxyCache.setProxyGetPartiesTimeout).toHaveBeenCalledTimes(1)
173
+ expect(proxyCache.setProxyGetPartiesTimeout.mock.lastCall[1]).toBe(proxyId)
174
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
175
+ })
176
+
177
+ test('should NOT set getParties timeout if source is external', async () => {
178
+ participantMock.validateParticipant = jest.fn()
179
+ .mockResolvedValueOnce(null) // source
180
+ .mockResolvedValueOnce({}) // proxy-src
181
+ const proxyCache = createProxyCacheMock({
182
+ lookupProxyByDfspId: jest.fn().mockResolvedValue('proxy-desc')
183
+ })
184
+ const deps = createMockDeps({ proxyCache })
185
+ const headers = fixtures.partiesCallHeadersDto({ proxy: 'proxy-src' })
186
+ const params = fixtures.partiesParamsDto()
187
+ const service = new GetPartiesService(deps, { headers, params })
188
+
189
+ await service.handleRequest()
190
+ expect(proxyCache.setProxyGetPartiesTimeout).not.toHaveBeenCalled()
191
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
192
+ })
193
+
194
+ test('should NOT set getParties timeout if destination is local', async () => {
195
+ participantMock.validateParticipant = jest.fn().mockResolvedValue({})
196
+ const proxyCache = createProxyCacheMock()
197
+ const deps = createMockDeps({ proxyCache })
198
+ const headers = fixtures.partiesCallHeadersDto()
199
+ const params = fixtures.partiesParamsDto()
200
+ const service = new GetPartiesService(deps, { headers, params })
201
+
202
+ await service.handleRequest()
203
+ expect(proxyCache.setProxyGetPartiesTimeout).not.toHaveBeenCalled()
204
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
205
+ })
206
+
207
+ test('should set getParties timeout if oracle returns external participant', async () => {
208
+ participantMock.validateParticipant = jest.fn()
209
+ .mockResolvedValueOnce({}) // source
210
+ .mockResolvedValueOnce(null) // externalDfsp
211
+ oracleMock.oracleRequest = jest.fn(async () => fixtures.oracleRequestResponseDto({
212
+ partyList: [{ fspId: 'externalDfsp' }]
213
+ }))
214
+ const proxyCache = createProxyCacheMock({
215
+ lookupProxyByDfspId: jest.fn().mockResolvedValue('proxyExternal')
216
+ })
217
+ const deps = createMockDeps({ proxyCache })
218
+ const headers = fixtures.partiesCallHeadersDto({ destination: '' })
219
+ const params = fixtures.partiesParamsDto()
220
+ const service = new GetPartiesService(deps, { headers, params })
221
+
222
+ await service.handleRequest()
223
+ expect(proxyCache.setProxyGetPartiesTimeout).toHaveBeenCalledTimes(1)
224
+ expect(participantMock.sendRequest).toHaveBeenCalledTimes(1)
225
+ })
226
+ })
227
+
228
+ test('should send partyNotFound callback in ISO20022 format', async () => {
229
+ participantMock.validateParticipant = jest.fn().mockResolvedValue({})
230
+ oracleMock.oracleRequest = jest.fn()
231
+ const deps = {
232
+ ...createMockDeps(),
233
+ config: { ...config, API_TYPE: API_TYPES.iso20022 }
234
+ }
235
+ const headers = fixtures.partiesCallHeadersDto({ destination: '' })
236
+ const params = fixtures.partiesParamsDto()
237
+ const service = new GetPartiesService(deps, { headers, params })
238
+
239
+ await service.handleRequest()
240
+ expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
241
+ const isoPayload = participantMock.sendErrorToParticipant.mock.lastCall[2]
242
+ expect(isoPayload.Assgnmt).toBeDefined()
243
+ expect(isoPayload.Rpt).toBeDefined()
244
+ })
245
+ })
@@ -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
+ }