account-lookup-service 17.6.0 → 17.7.0-snapshot.1

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.
@@ -32,64 +32,82 @@ const BasePartiesService = require('./BasePartiesService')
32
32
  const { RestMethods } = BasePartiesService.enums()
33
33
 
34
34
  class PutPartiesService extends BasePartiesService {
35
- // async handleRequest () {
36
- // // todo: add impl.
37
- // }
38
-
39
- async validateSourceParticipant ({ source, proxy }) {
40
- this.deps.stepState.inProgress('validateSourceParticipant-1')
41
- const requesterParticipant = await super.validateParticipant(source)
42
-
43
- if (!requesterParticipant) {
44
- if (!this.proxyEnabled || !proxy) {
45
- const errMessage = ERROR_MESSAGES.sourceFspNotFound
46
- this.log.warn(`${errMessage} and no proxy`, { source })
47
- throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ID_NOT_FOUND, errMessage)
35
+ async handleRequest () {
36
+ const { destination, source, proxy } = this.state
37
+ this.log.info('handleRequest start', { destination, source, proxy })
38
+
39
+ await this.validateSourceParticipant()
40
+ if (proxy) {
41
+ await this.checkProxySuccessResponse()
42
+ }
43
+ await this.identifyDestinationForSuccessCallback()
44
+ await this.sendSuccessCallback()
45
+ }
46
+
47
+ async validateSourceParticipant () {
48
+ const { source, proxy, proxyEnabled } = this.state
49
+ const log = this.log.child({ source, proxy, method: 'validateSourceParticipant' })
50
+ this.stepInProgress('validateSourceParticipant-1')
51
+
52
+ const schemeParticipant = await super.validateParticipant(source)
53
+ if (!schemeParticipant) {
54
+ if (!proxyEnabled || !proxy) {
55
+ throw super.createFspiopIdNotFoundError(ERROR_MESSAGES.sourceFspNotFound, log)
48
56
  }
57
+
49
58
  const isCached = await this.deps.proxyCache.addDfspIdToProxyMapping(source, proxy)
50
59
  if (!isCached) {
51
- const errMessage = 'failed to addDfspIdToProxyMapping'
52
- this.log.warn(errMessage, { source, proxy })
53
- throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ID_NOT_FOUND, errMessage)
60
+ throw super.createFspiopIdNotFoundError('failed to addDfspIdToProxyMapping', log)
54
61
  }
55
62
 
56
- this.log.info('addDfspIdToProxyMapping is done', { source, proxy })
63
+ log.info('addDfspIdToProxyMapping is done', { source, proxy })
57
64
  }
58
65
  }
59
66
 
60
- async checkProxySuccessResponse ({ destination, source, headers, params }) {
61
- if (this.proxyEnabled) {
62
- this.deps.stepState.inProgress('checkProxySuccessResponse-2')
67
+ async checkProxySuccessResponse () {
68
+ if (this.state.proxyEnabled) {
69
+ this.stepInProgress('checkProxySuccessResponse')
70
+ const { headers, params } = this.inputs
71
+ const { destination, source } = this.state
63
72
  const alsReq = this.deps.partiesUtils.alsRequestDto(destination, params)
64
73
 
65
74
  const isExists = await this.deps.proxyCache.receivedSuccessResponse(alsReq)
66
- if (isExists) {
67
- await this.#updateOracleWithParticipantMapping({ source, headers, params })
75
+ if (!isExists) {
76
+ this.log.verbose('NOT inter-scheme receivedSuccessResponse case')
77
+ await this.removeProxyGetPartiesTimeout(alsReq)
68
78
  return
69
79
  }
70
- this.log.warn('destination is NOT in scheme, and no cached sendToProxiesList', { destination, alsReq })
71
- // todo: think, if we need to throw an error here
80
+
81
+ const schemeParticipant = await super.validateParticipant(destination)
82
+ if (schemeParticipant) {
83
+ await this.#updateOracleWithParticipantMapping({ source, headers, params })
84
+ }
72
85
  }
73
86
  }
74
87
 
75
- async identifyDestinationForSuccessCallback (destination) {
76
- this.deps.stepState.inProgress('validateDestinationParticipant-4')
88
+ async identifyDestinationForSuccessCallback () {
89
+ const { destination } = this.state
90
+ this.stepInProgress('identifyDestinationForSuccessCallback')
77
91
  const destinationParticipant = await super.validateParticipant(destination)
78
92
  if (destinationParticipant) {
79
- return destinationParticipant.name
93
+ this.state.requester = destinationParticipant.name
94
+ return
80
95
  }
81
96
 
82
- const proxyName = this.proxyEnabled && await this.deps.proxyCache.lookupProxyByDfspId(destination)
97
+ const proxyName = this.state.proxyEnabled && await this.deps.proxyCache.lookupProxyByDfspId(destination)
83
98
  if (!proxyName) {
84
99
  const errMessage = ERROR_MESSAGES.partyDestinationFspNotFound
85
100
  this.log.warn(`${errMessage} and no proxy`, { destination })
86
101
  throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_FSP_ERROR, errMessage)
87
102
  }
88
- return proxyName
103
+
104
+ this.state.requester = proxyName
89
105
  }
90
106
 
91
- async sendSuccessCallback ({ sendTo, headers, params, dataUri }) {
92
- this.deps.stepState.inProgress('#sendSuccessCallback-6')
107
+ async sendSuccessCallback () {
108
+ const { headers, params, dataUri } = this.inputs
109
+ const sendTo = this.state.requester
110
+ this.stepInProgress('sendSuccessCallback')
93
111
  const payload = PutPartiesService.decodeDataUriPayload(dataUri)
94
112
  const callbackEndpointType = this.deps.partiesUtils.putPartyCbType(params.SubId)
95
113
  const options = this.deps.partiesUtils.partiesRequestOptionsDto(params)
@@ -97,11 +115,11 @@ class PutPartiesService extends BasePartiesService {
97
115
  await this.deps.participant.sendRequest(
98
116
  headers, sendTo, callbackEndpointType, RestMethods.PUT, payload, options
99
117
  )
100
- this.log.verbose('sendSuccessCallback is done', { sendTo, payload })
118
+ this.log.verbose('sendSuccessCallback is sent', { sendTo, payload })
101
119
  }
102
120
 
103
121
  async #updateOracleWithParticipantMapping ({ source, headers, params }) {
104
- this.deps.stepState.inProgress('#updateOracleWithParticipantMapping-3')
122
+ this.stepInProgress('#updateOracleWithParticipantMapping-3')
105
123
  const mappingPayload = {
106
124
  fspId: source
107
125
  }
@@ -52,6 +52,10 @@ const timeoutInterschemePartiesLookups = async ({ proxyCache, batchSize }) => {
52
52
  return proxyCache.processExpiredAlsKeys(sendTimeoutCallback, batchSize)
53
53
  }
54
54
 
55
+ const timeoutProxyGetPartiesLookups = async ({ proxyCache, batchSize }) => {
56
+ return proxyCache.processExpiredProxyGetPartiesKeys(sendTimeoutCallback, batchSize)
57
+ }
58
+
55
59
  const sendTimeoutCallback = async (cacheKey) => {
56
60
  const histTimerEnd = Metrics.getHistogram(
57
61
  'eg_timeoutInterschemePartiesLookups',
@@ -59,7 +63,7 @@ const sendTimeoutCallback = async (cacheKey) => {
59
63
  ['success']
60
64
  ).startTimer()
61
65
  let step
62
- const [, destination, partyType, partyId] = cacheKey.split(':')
66
+ const [destination, partyType, partyId] = parseCacheKey(cacheKey)
63
67
  const { errorInformation, params, headers, endpointType, span } = await timeoutCallbackDto({ destination, partyId, partyType })
64
68
  logger.debug('sendTimeoutCallback details:', { destination, partyType, partyId, cacheKey })
65
69
 
@@ -103,7 +107,13 @@ const finishSpan = async (span, err) => {
103
107
  }
104
108
  }
105
109
 
110
+ const parseCacheKey = (cacheKey) => {
111
+ const [destination, partyType, partyId] = cacheKey.split(':').slice(-3)
112
+ return [destination, partyType, partyId]
113
+ }
114
+
106
115
  module.exports = {
107
116
  timeoutInterschemePartiesLookups,
117
+ timeoutProxyGetPartiesLookups,
108
118
  sendTimeoutCallback // Exposed for testing
109
119
  }
@@ -41,13 +41,13 @@ let isRunning
41
41
 
42
42
  const timeout = async (options) => {
43
43
  if (isRunning) return
44
-
45
44
  const { logger } = options
46
45
 
47
46
  try {
48
47
  isRunning = true
49
- logger.debug('Timeout handler triggered')
50
48
  await TimeoutService.timeoutInterschemePartiesLookups(options)
49
+ await TimeoutService.timeoutProxyGetPartiesLookups(options)
50
+ logger.verbose('ALS timeout handler is done')
51
51
  } catch (err) {
52
52
  logger.error('error in timeout: ', err)
53
53
  } finally {
package/src/lib/util.js CHANGED
@@ -29,10 +29,11 @@ const util = require('node:util')
29
29
  const Path = require('node:path')
30
30
  const EventSdk = require('@mojaloop/event-sdk')
31
31
  const Enum = require('@mojaloop/central-services-shared').Enum
32
- const { HeaderValidation, Hapi } = require('@mojaloop/central-services-shared').Util
32
+ const { HeaderValidation } = require('@mojaloop/central-services-shared').Util
33
33
  const rethrow = require('@mojaloop/central-services-shared').Util.rethrow.with('ALS')
34
34
 
35
35
  const Config = require('../lib/config')
36
+ const { API_TYPES } = require('../constants')
36
37
  const { logger } = require('./index')
37
38
 
38
39
  const getSpanTags = ({ headers }, transactionType, transactionAction) => {
@@ -69,7 +70,7 @@ const pathForInterface = ({ isAdmin, isMockInterface }) => {
69
70
  if (isMockInterface) {
70
71
  apiFile = 'api_swagger.json'
71
72
  } else {
72
- apiFile = Config.API_TYPE === Hapi.API_TYPES.iso20022
73
+ apiFile = Config.API_TYPE === API_TYPES.iso20022
73
74
  ? 'api-swagger-iso20022-parties.yaml'
74
75
  : 'api-swagger.yaml'
75
76
  }
@@ -100,7 +101,14 @@ const countFspiopError = (error, options) => {
100
101
  rethrow.countFspiopError(error, options)
101
102
  }
102
103
 
103
- // todo: think better name
104
+ /**
105
+ * An immutable object representing the step state
106
+ * @typedef {Object} StepState
107
+ * @property {string} step - The current step value (read-only getter property)
108
+ * @property {(string) => void} inProgress - Method to update the current step
109
+ */
110
+
111
+ /** @returns {StepState} */
104
112
  const initStepState = (initStep = 'start') => {
105
113
  let step = initStep
106
114
  return Object.freeze({
@@ -1,3 +1,30 @@
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 { randomUUID } = require('node:crypto')
2
29
  const { Enum } = require('@mojaloop/central-services-shared')
3
30
  const isoFixtures = require('./iso')
@@ -20,6 +47,16 @@ const headersDto = ({
20
47
  'content-type': contentType || accept
21
48
  })
22
49
 
50
+ const partiesParamsDto = ({
51
+ Type = 'MSISDN',
52
+ ID = String(Date.now()),
53
+ SubId
54
+ } = {}) => ({
55
+ Type,
56
+ ID,
57
+ ...(SubId && { SubId })
58
+ })
59
+
23
60
  const protocolVersionsDto = () => ({
24
61
  CONTENT: {
25
62
  DEFAULT: '2.1',
@@ -142,6 +179,7 @@ const mockHapiRequestDto = ({ // https://hapi.dev/api/?v=21.3.3#request-properti
142
179
  module.exports = {
143
180
  ...isoFixtures,
144
181
  partiesCallHeadersDto,
182
+ partiesParamsDto,
145
183
  participantsCallHeadersDto,
146
184
  oracleRequestResponseDto,
147
185
  putPartiesSuccessResponseDto,
@@ -1369,7 +1369,7 @@ describe('participant Tests', () => {
1369
1369
 
1370
1370
  // Assert
1371
1371
  expect(logStub.getCall(0).firstArg).toBe(ERROR_MESSAGES.sourceFspNotFound)
1372
- expect(logStub.getCall(3).lastArg).toEqual(cbError)
1372
+ expect(logStub.getCall(2).lastArg).toEqual(cbError)
1373
1373
  })
1374
1374
 
1375
1375
  it('handles error when `oracleBatchRequest` returns no result', async () => {
@@ -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 () => {
@@ -246,7 +248,7 @@ describe('Parties Tests', () => {
246
248
  await partiesDomain.getPartiesByTypeAndID(Helper.getByTypeIdRequest.headers, Helper.getByTypeIdRequest.params, Helper.getByTypeIdRequest.method, Helper.getByTypeIdRequest.query)
247
249
 
248
250
  // Assert
249
- expect(loggerStub.callCount).toBe(2)
251
+ expect(loggerStub.callCount).toBe(1)
250
252
  expect(participant.sendErrorToParticipant.callCount).toBe(1)
251
253
 
252
254
  const { errorInformation } = participant.sendErrorToParticipant.getCall(0).args[2]
@@ -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
  })
@@ -893,7 +901,7 @@ describe('Parties Tests', () => {
893
901
 
894
902
  // Assert
895
903
  expect(participant.sendErrorToParticipant.callCount).toBe(1)
896
- expect(loggerStub.callCount).toBe(2)
904
+ expect(loggerStub.callCount).toBe(1)
897
905
  const sendErrorCallArgs = participant.sendErrorToParticipant.getCall(0).args
898
906
  expect(sendErrorCallArgs[1]).toBe(expectedCallbackEnpointType)
899
907
  })
@@ -914,7 +922,7 @@ describe('Parties Tests', () => {
914
922
 
915
923
  // Assert
916
924
  expect(participant.sendErrorToParticipant.callCount).toBe(1)
917
- expect(loggerStub.callCount).toBe(2)
925
+ expect(loggerStub.callCount).toBe(1)
918
926
  const sendErrorCallArgs = participant.sendErrorToParticipant.getCall(0).args
919
927
  expect(sendErrorCallArgs[1]).toBe(expectedCallbackEnpointType)
920
928
  })
@@ -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
+ })
@@ -3,7 +3,9 @@
3
3
  --------------
4
4
  Copyright © 2020-2025 Mojaloop Foundation
5
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
+
6
7
  http://www.apache.org/licenses/LICENSE-2.0
8
+
7
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.
8
10
 
9
11
  Contributors
@@ -13,46 +15,43 @@
13
15
  should be listed with a '*' in the first column. People who have
14
16
  contributed from an organization can be listed under the organization
15
17
  that actually holds the copyright for their contributions (see the
16
- Mojaloop Foundation organization for an example). Those individuals should have
18
+ Mojaloop Foundation for an example). Those individuals should have
17
19
  their names indented and be marked with a '-'. Email address can be added
18
20
  optionally within square brackets <email>.
19
- * Mojaloop Foundation
20
- - Name Surname <name.surname@mojaloop.io>
21
21
 
22
+ * Mojaloop Foundation
22
23
  * Eugen Klymniuk <eugen.klymniuk@infitx.com>
23
- --------------
24
- **********/
25
-
26
- const mockSendRequest = jest.fn()
27
-
28
- jest.mock('@mojaloop/central-services-shared', () => ({
29
- ...jest.requireActual('@mojaloop/central-services-shared'),
30
- Util: {
31
- ...jest.requireActual('@mojaloop/central-services-shared').Util,
32
- Endpoints: { getEndpoint: jest.fn() },
33
- Request: { sendRequest: mockSendRequest }
34
- }
35
- }))
36
-
37
- const { API_TYPES } = require('@mojaloop/central-services-shared').Util.Hapi
38
- const { logger } = require('../../../../src/lib')
39
- const partiesUtils = require('../../../../src/domain/parties/partiesUtils')
40
- const config = require('../../../../src/lib/config')
41
- const fixtures = require('../../../fixtures')
42
-
43
- describe('parties utils Tests -->', () => {
44
- test('should send error party callback in ISO format', async () => {
45
- const isoConfig = { ...config, API_TYPE: API_TYPES.iso20022 }
46
- const err = new Error('test error')
47
- const source = 'dfsp1'
48
- const headers = fixtures.partiesCallHeadersDto({ source })
49
- const params = { ID: '1234', Type: 'MSISDN' }
50
24
 
51
- const handleError = partiesUtils.createErrorHandlerOnSendingCallback(isoConfig, logger)
52
- await handleError(err, headers, params, source)
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
+ })
53
39
 
54
- expect(mockSendRequest).toHaveBeenCalledTimes(1)
55
- const { payload } = mockSendRequest.mock.calls[0][0]
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.mock.calls.length).toBe(1)
52
+ // eslint-disable-next-line no-unused-vars
53
+ const [sentTo, _, payload] = participantMock.sendErrorToParticipant.mock.lastCall
54
+ expect(sentTo).toBe(source)
56
55
  expect(payload.Rpt.Rsn.Cd).toBe('2001')
57
56
  expect(payload.Rpt.OrgnlId).toBe(`${params.Type}/${params.ID}`)
58
57
  expect(payload.Assgnmt.Assgnr.Agt.FinInstnId.Othr.Id).toBe(source)