account-lookup-service 17.7.1 → 17.8.0-snapshot.100
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 +0 -7
- package/docker/mock-proxy/src/server.ts +13 -4
- package/package.json +12 -9
- package/src/constants.js +35 -2
- package/src/domain/parties/deps.js +11 -4
- package/src/domain/parties/getPartiesByTypeAndID.js +9 -13
- package/src/domain/parties/partiesUtils.js +4 -34
- package/src/domain/parties/putParties.js +26 -71
- package/src/domain/parties/services/BasePartiesService.js +146 -17
- package/src/domain/parties/services/GetPartiesService.js +213 -166
- package/src/domain/parties/services/PutPartiesErrorService.js +52 -28
- package/src/domain/parties/services/PutPartiesService.js +51 -33
- package/src/domain/parties/services/TimeoutPartiesService.js +84 -0
- package/src/domain/parties/services/index.js +3 -1
- package/src/domain/timeout/createSpan.js +55 -0
- package/src/domain/timeout/index.js +27 -36
- package/src/handlers/TimeoutHandler.js +2 -2
- package/src/index.js +3 -0
- package/src/lib/util.js +11 -3
- package/src/server.js +16 -5
- package/test/fixtures/index.js +53 -3
- package/test/integration/api/parties.test.js +1 -0
- package/test/integration/domain/timeout/index.test.js +83 -28
- package/test/unit/domain/parties/parties.test.js +27 -20
- package/test/unit/domain/parties/partiesUtils.test.js +51 -0
- package/test/unit/domain/parties/services/BasePartiesService.test.js +72 -0
- package/test/unit/domain/parties/services/GetPartiesService.test.js +340 -0
- package/test/unit/domain/parties/services/PutPartiesErrorService.test.js +50 -0
- package/test/unit/domain/parties/services/TimeoutPartiesService.test.js +72 -0
- package/test/unit/domain/parties/services/deps.js +51 -0
- package/test/unit/domain/timeout/index.test.js +17 -12
- package/test/util/apiClients/AlsApiClient.js +6 -4
- package/test/util/apiClients/BasicApiClient.js +33 -6
- package/test/util/apiClients/ProxyApiClient.js +46 -1
- package/test/util/index.js +5 -6
- package/test/util/mockDeps.js +72 -0
- package/src/domain/timeout/dto.js +0 -54
- package/test/unit/domain/parties/utils.test.js +0 -60
- package/test/unit/domain/timeout/dto.test.js +0 -24
@@ -1,18 +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
|
+
|
1
28
|
const { createProxyCache } = require('@mojaloop/inter-scheme-proxy-cache-lib')
|
2
|
-
const {
|
29
|
+
const { RedisProxyCache } = require('@mojaloop/inter-scheme-proxy-cache-lib/dist/lib/storages/RedisProxyCache')
|
30
|
+
const config = require('#src/lib/config')
|
3
31
|
const fixtures = require('../../../fixtures')
|
4
32
|
const { ProxyApiClient } = require('../../../util')
|
5
|
-
const
|
33
|
+
const { PAYER_DFSP, PARTY_ID_TYPE, PROXY_NAME } = require('../../constants')
|
6
34
|
|
7
35
|
const wait = (sec) => new Promise(resolve => setTimeout(resolve, sec * 1000))
|
8
36
|
|
9
37
|
const CRON_TIMEOUT_SEC = 15 // see TIMEXP
|
10
38
|
|
39
|
+
jest.setTimeout(60_000)
|
40
|
+
|
11
41
|
describe('Timeout Handler', () => {
|
12
42
|
const { type, proxyConfig } = config.PROXY_CACHE_CONFIG
|
13
43
|
const proxyCache = createProxyCache(type, proxyConfig)
|
14
44
|
const proxyClient = new ProxyApiClient()
|
15
45
|
|
46
|
+
const checkKeysExistence = async (keys) => Promise.all(keys.map(key => proxyCache.redisClient.exists(key)))
|
47
|
+
|
16
48
|
beforeAll(async () => {
|
17
49
|
await proxyCache.connect()
|
18
50
|
const redisClient = proxyCache.redisClient
|
@@ -22,6 +54,11 @@ describe('Timeout Handler', () => {
|
|
22
54
|
}))
|
23
55
|
})
|
24
56
|
|
57
|
+
beforeEach(async () => {
|
58
|
+
const history = await proxyClient.deleteHistory()
|
59
|
+
expect(history).toEqual([])
|
60
|
+
})
|
61
|
+
|
25
62
|
afterAll(async () => {
|
26
63
|
return Promise.all([
|
27
64
|
proxyClient.deleteHistory(),
|
@@ -29,47 +66,65 @@ describe('Timeout Handler', () => {
|
|
29
66
|
])
|
30
67
|
})
|
31
68
|
|
32
|
-
it('
|
33
|
-
|
34
|
-
expect(history).toEqual([])
|
35
|
-
|
36
|
-
// send a couple of keys to redis
|
37
|
-
const partyIds = ['1234567', '7654321']
|
38
|
-
const keys = [
|
39
|
-
`'als:${PAYER_DFSP}:${PARTY_ID_TYPE}:${partyIds[0]}:expiresAt'`,
|
40
|
-
`'als:${PAYER_DFSP}:${PARTY_ID_TYPE}:${partyIds[1]}:expiresAt'`
|
41
|
-
]
|
69
|
+
it('should pass timeoutInterschemePartiesLookups flow', async () => {
|
70
|
+
const partyIds = [`isp1-${Date.now()}`, `isp2-${Date.now()}`]
|
42
71
|
const proxies = [PROXY_NAME]
|
43
72
|
const alsReq1 = fixtures.mockAlsRequestDto(PAYER_DFSP, PARTY_ID_TYPE, partyIds[0])
|
44
73
|
const alsReq2 = fixtures.mockAlsRequestDto(PAYER_DFSP, PARTY_ID_TYPE, partyIds[1])
|
74
|
+
const keys = [
|
75
|
+
RedisProxyCache.formatAlsCacheExpiryKey(alsReq1),
|
76
|
+
RedisProxyCache.formatAlsCacheExpiryKey(alsReq2)
|
77
|
+
]
|
78
|
+
// send a couple of keys to redis
|
45
79
|
const results = await Promise.all([
|
46
80
|
proxyCache.setSendToProxiesList(alsReq1, proxies, CRON_TIMEOUT_SEC),
|
47
81
|
proxyCache.setSendToProxiesList(alsReq2, proxies, CRON_TIMEOUT_SEC)
|
48
82
|
])
|
49
|
-
expect(results
|
83
|
+
expect(results).toEqual([true, true])
|
84
|
+
expect(await checkKeysExistence(keys)).toEqual([1, 1])
|
50
85
|
|
51
86
|
// wait for the timeout handler to process the keys
|
52
87
|
await wait(CRON_TIMEOUT_SEC * 1.5)
|
88
|
+
const history = await proxyClient.waitForNHistoryCalls(2)
|
53
89
|
|
54
90
|
// check that the keys are no longer in redis
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
// check that the callbacks are sent and received at the FSP
|
59
|
-
// for test resilience, we will retry the history check a few times
|
60
|
-
const retryMaxCount = 20
|
61
|
-
const retryIntervalSec = 2
|
62
|
-
let retryCount = 0
|
63
|
-
|
64
|
-
while (history.length < 2 && retryCount < retryMaxCount) {
|
65
|
-
await wait(retryIntervalSec)
|
66
|
-
history = await proxyClient.getHistory()
|
67
|
-
retryCount++
|
68
|
-
}
|
91
|
+
expect(await checkKeysExistence(keys)).toEqual([0, 0])
|
92
|
+
|
69
93
|
expect(history.length).toBe(2)
|
70
94
|
const path0 = history.find(h => h.path.includes(partyIds[0])).path
|
71
95
|
const path1 = history.find(h => h.path.includes(partyIds[1])).path
|
72
96
|
expect(path0).toBe(`/parties/${PARTY_ID_TYPE}/${partyIds[0]}/error`)
|
73
97
|
expect(path1).toBe(`/parties/${PARTY_ID_TYPE}/${partyIds[1]}/error`)
|
74
|
-
}
|
98
|
+
})
|
99
|
+
|
100
|
+
it('should pass timeoutProxyGetPartiesLookups flow', async () => {
|
101
|
+
const partyId1 = `pgp1-${Date.now()}`
|
102
|
+
const partyId2 = `pgp2-${Date.now()}`
|
103
|
+
const alsReq1 = fixtures.mockAlsRequestDto(PAYER_DFSP, PARTY_ID_TYPE, partyId1)
|
104
|
+
const alsReq2 = fixtures.mockAlsRequestDto(PAYER_DFSP, PARTY_ID_TYPE, partyId2)
|
105
|
+
const keys = [
|
106
|
+
RedisProxyCache.formatProxyGetPartiesExpiryKey(alsReq1, PROXY_NAME),
|
107
|
+
RedisProxyCache.formatProxyGetPartiesExpiryKey(alsReq2, PROXY_NAME)
|
108
|
+
]
|
109
|
+
// send a couple of keys to redis
|
110
|
+
const results = await Promise.all([
|
111
|
+
proxyCache.setProxyGetPartiesTimeout(alsReq1, PROXY_NAME, CRON_TIMEOUT_SEC),
|
112
|
+
proxyCache.setProxyGetPartiesTimeout(alsReq2, PROXY_NAME, CRON_TIMEOUT_SEC)
|
113
|
+
])
|
114
|
+
expect(results).toEqual([true, true])
|
115
|
+
expect(await checkKeysExistence(keys)).toEqual([1, 1])
|
116
|
+
|
117
|
+
// wait for the timeout handler to process the keys
|
118
|
+
await wait(CRON_TIMEOUT_SEC * 1.5)
|
119
|
+
const history = await proxyClient.waitForNHistoryCalls(2)
|
120
|
+
|
121
|
+
// check that the keys are no longer in redis
|
122
|
+
expect(await checkKeysExistence(keys)).toEqual([0, 0])
|
123
|
+
|
124
|
+
expect(history.length).toBe(2)
|
125
|
+
const path1 = history.find(h => h.path.includes(partyId1)).path
|
126
|
+
const path2 = history.find(h => h.path.includes(partyId2)).path
|
127
|
+
expect(path1).toBe(`/parties/${PARTY_ID_TYPE}/${partyId1}/error`)
|
128
|
+
expect(path2).toBe(`/parties/${PARTY_ID_TYPE}/${partyId2}/error`)
|
129
|
+
})
|
75
130
|
})
|
@@ -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)
|
@@ -174,8 +174,7 @@ describe('Parties Tests', () => {
|
|
174
174
|
it('should set source proxyMapping if source is not in scheme, and there is proxy-header', async () => {
|
175
175
|
Config.PROXY_CACHE_CONFIG.enabled = true
|
176
176
|
participant.validateParticipant = sandbox.stub()
|
177
|
-
.onFirstCall().resolves(
|
178
|
-
.onSecondCall().resolves({}) // proxy
|
177
|
+
.onFirstCall().resolves({}) // proxy, source is skipped
|
179
178
|
const source = `source-${Date.now()}`
|
180
179
|
const proxy = `proxy-${Date.now()}`
|
181
180
|
|
@@ -192,24 +191,26 @@ describe('Parties Tests', () => {
|
|
192
191
|
expect(cached).toBe(proxy)
|
193
192
|
})
|
194
193
|
|
195
|
-
it('should
|
194
|
+
it('should cleanup oracle and trigger discovery flow, if destination is not in scheme and no dfsp-to-proxy mapping', async () => {
|
195
|
+
Config.PROXY_CACHE_CONFIG.enabled = true
|
196
196
|
participant.validateParticipant = sandbox.stub()
|
197
197
|
.onFirstCall().resolves({}) // source
|
198
198
|
.onSecondCall().resolves(null) // destination
|
199
199
|
participant.sendRequest = sandbox.stub().resolves()
|
200
200
|
participant.sendErrorToParticipant = sandbox.stub().resolves()
|
201
201
|
sandbox.stub(oracle, 'oracleRequest')
|
202
|
+
const proxy = 'some-proxy'
|
203
|
+
Util.proxies.getAllProxiesNames = sandbox.stub().resolves([proxy])
|
202
204
|
const headers = fixtures.partiesCallHeadersDto()
|
203
205
|
|
204
206
|
await partiesDomain.getPartiesByTypeAndID(headers, Helper.getByTypeIdRequest.params, Helper.getByTypeIdRequest.method, Helper.getByTypeIdRequest.query, Helper.mockSpan(), null, proxyCache)
|
205
207
|
|
206
|
-
expect(
|
207
|
-
expect(
|
208
|
-
expect(participant.
|
209
|
-
|
210
|
-
const
|
211
|
-
expect(
|
212
|
-
expect(errorInformation.errorDescription).toContain(ERROR_MESSAGES.partyDestinationFspNotFound)
|
208
|
+
expect(oracle.oracleRequest.lastCall.args[1]).toBe(RestMethods.DELETE)
|
209
|
+
expect(participant.sendErrorToParticipant.callCount).toBe(0)
|
210
|
+
expect(participant.sendRequest.callCount).toBe(1)
|
211
|
+
// eslint-disable-next-line no-unused-vars
|
212
|
+
const [_, sendTo] = participant.sendRequest.lastCall.args
|
213
|
+
expect(sendTo).toBe(proxy)
|
213
214
|
})
|
214
215
|
|
215
216
|
it('should send request to proxy, if destination is not in the scheme, but has proxyMapping', async () => {
|
@@ -470,7 +471,7 @@ describe('Parties Tests', () => {
|
|
470
471
|
expect(firstCallArgs[2]).toBe(expectedCallbackEnpointType)
|
471
472
|
})
|
472
473
|
|
473
|
-
it('should send
|
474
|
+
it('should send errorCallback if oracle returns external dfsp, and source is external', async () => {
|
474
475
|
Config.PROXY_CACHE_CONFIG.enabled = true
|
475
476
|
const proxyName = `proxy-${Date.now()}`
|
476
477
|
const fspId = `dfspNotFromScheme-${Date.now()}`
|
@@ -479,7 +480,7 @@ describe('Parties Tests', () => {
|
|
479
480
|
})
|
480
481
|
sandbox.stub(oracle, 'oracleRequest').resolves(oracleResponse)
|
481
482
|
participant.validateParticipant = sandbox.stub()
|
482
|
-
.onFirstCall().resolves(
|
483
|
+
.onFirstCall().resolves(null) // source
|
483
484
|
.onSecondCall().resolves(null) // oracle dfsp
|
484
485
|
participant.sendRequest = sandbox.stub().resolves()
|
485
486
|
participant.sendErrorToParticipant = sandbox.stub().resolves()
|
@@ -487,15 +488,20 @@ describe('Parties Tests', () => {
|
|
487
488
|
const isAdded = await proxyCache.addDfspIdToProxyMapping(fspId, proxyName)
|
488
489
|
expect(isAdded).toBe(true)
|
489
490
|
|
490
|
-
const
|
491
|
+
const source = `fromDfsp-${Date.now()}`
|
492
|
+
const headers = fixtures.partiesCallHeadersDto({ destination: '', source, proxy: 'proxy' })
|
491
493
|
const { params, method, query } = Helper.getByTypeIdRequest
|
492
494
|
|
493
495
|
await partiesDomain.getPartiesByTypeAndID(headers, params, method, query, null, null, proxyCache)
|
494
496
|
|
495
|
-
expect(participant.
|
496
|
-
expect(participant.
|
497
|
-
|
498
|
-
|
497
|
+
expect(participant.sendRequest.callCount).toBe(0)
|
498
|
+
expect(participant.sendErrorToParticipant.callCount).toBe(1)
|
499
|
+
// eslint-disable-next-line no-unused-vars
|
500
|
+
const [sentTo, _, payload, sentHeaders] = participant.sendErrorToParticipant.lastCall.args
|
501
|
+
expect(sentTo).toBe(source)
|
502
|
+
expect(payload.errorInformation.errorCode).toBe('3200')
|
503
|
+
expect(sentHeaders[Headers.FSPIOP.SOURCE]).toBe(Config.HUB_NAME)
|
504
|
+
expect(sentHeaders[Headers.FSPIOP.DESTINATION]).toBe(headers[Headers.FSPIOP.SOURCE])
|
499
505
|
})
|
500
506
|
|
501
507
|
it('handles error when `oracleRequest` returns no result', async () => {
|
@@ -554,13 +560,14 @@ describe('Parties Tests', () => {
|
|
554
560
|
participant.sendRequest = sandbox.stub().rejects(new Error('Some network issue'))
|
555
561
|
participant.sendErrorToParticipant = sandbox.stub().resolves()
|
556
562
|
const headers = fixtures.partiesCallHeadersDto({ destination: '' })
|
563
|
+
const params = fixtures.partiesParamsDto()
|
557
564
|
|
558
|
-
await partiesDomain.getPartiesByTypeAndID(headers,
|
565
|
+
await partiesDomain.getPartiesByTypeAndID(headers, params, Helper.getByTypeIdRequest.method, Helper.getByTypeIdRequest.query, Helper.mockSpan(), null, proxyCache)
|
559
566
|
|
560
567
|
expect(participant.sendRequest.callCount).toBe(proxyNames.length)
|
561
568
|
expect(participant.sendErrorToParticipant.callCount).toBe(1)
|
562
569
|
|
563
|
-
const { errorInformation } = participant.sendErrorToParticipant.
|
570
|
+
const { errorInformation } = participant.sendErrorToParticipant.lastCall.args[2]
|
564
571
|
expect(errorInformation.errorCode).toBe('3200')
|
565
572
|
expect(errorInformation.errorDescription).toContain(ERROR_MESSAGES.proxyConnectionError)
|
566
573
|
})
|
@@ -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,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, 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.Assgne.Agt.FinInstnId.Othr.Id).toBe(source)
|
58
|
+
expect(payload.Assgnmt.Assgnr.Agt.FinInstnId.Othr.Id).toBe(config.HUB_NAME)
|
59
|
+
})
|
60
|
+
|
61
|
+
test('should remove proxy getParties timeout cache key', async () => {
|
62
|
+
const deps = createMockDeps()
|
63
|
+
const proxy = 'proxyAB'
|
64
|
+
const headers = fixtures.partiesCallHeadersDto({ proxy })
|
65
|
+
const params = fixtures.partiesParamsDto()
|
66
|
+
const alsReq = {}
|
67
|
+
const service = new BasePartiesService(deps, { headers, params })
|
68
|
+
|
69
|
+
await service.removeProxyGetPartiesTimeoutCache(alsReq)
|
70
|
+
expect(deps.proxyCache.removeProxyGetPartiesTimeout).toHaveBeenCalledWith(alsReq, proxy)
|
71
|
+
})
|
72
|
+
})
|