account-lookup-service 17.8.0-snapshot.17 → 17.8.0-snapshot.18

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "account-lookup-service",
3
3
  "description": "Account Lookup Service is used to validate Party and Participant lookups.",
4
- "version": "17.8.0-snapshot.17",
4
+ "version": "17.8.0-snapshot.18",
5
5
  "license": "Apache-2.0",
6
6
  "author": "ModusBox",
7
7
  "contributors": [
package/src/constants.js CHANGED
@@ -29,6 +29,7 @@ const { API_TYPES } = require('@mojaloop/central-services-shared').Util.Hapi
29
29
 
30
30
  const ERROR_MESSAGES = Object.freeze({
31
31
  emptyFilteredPartyList: 'Empty oracle partyList, filtered based on callbackEndpointType',
32
+ externalPartyError: 'External party error', // todo: think better message
32
33
  failedToCacheSendToProxiesList: 'Failed to cache sendToProxiesList',
33
34
  noDiscoveryRequestsForwarded: 'No discovery requests forwarded to participants',
34
35
  sourceFspNotFound: 'Requester FSP not found',
@@ -97,15 +97,7 @@ const putPartiesErrorByTypeAndID = async (headers, params, payload, dataUri, spa
97
97
  let fspiopError
98
98
 
99
99
  try {
100
- const needDiscovery = await service.handleRequest()
101
- if (needDiscovery) {
102
- const getPartiesService = new services.GetPartiesService(deps, inputs)
103
- await getPartiesService.triggerInterSchemeDiscoveryFlow(
104
- services.GetPartiesService.headersWithoutDestination(headers)
105
- )
106
- // think, if we need to start the whole processing with getPartiesService.handleRequest() ?
107
- }
108
-
100
+ await service.handleRequest()
109
101
  logger.info('putPartiesErrorByTypeAndID is done')
110
102
  histTimerEnd({ success: true })
111
103
  } catch (error) {
@@ -186,6 +186,11 @@ class BasePartiesService {
186
186
  return ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PARTY_NOT_FOUND, errMessage)
187
187
  }
188
188
 
189
+ createFspiopServiceUnavailableError (errMessage, log = this.log) {
190
+ log.warn(errMessage)
191
+ return ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.SERVICE_CURRENTLY_UNAVAILABLE, errMessage)
192
+ }
193
+
189
194
  stepInProgress (stepName) {
190
195
  this.log.debug('step is in progress', { stepName })
191
196
  this.state.stepState?.inProgress(stepName)
@@ -26,9 +26,9 @@
26
26
  ******/
27
27
 
28
28
  const BasePartiesService = require('./BasePartiesService')
29
+ const { ERROR_MESSAGES } = require('../../../constants')
29
30
 
30
31
  class PutPartiesErrorService extends BasePartiesService {
31
- /** @returns {Promise<true | undefined>} - If true, need to trigger inter-scheme discovery. */
32
32
  async handleRequest () {
33
33
  if (this.state.proxyEnabled && this.state.proxy) {
34
34
  const alsReq = this.deps.partiesUtils.alsRequestDto(this.state.destination, this.inputs.params) // or source?
@@ -37,23 +37,24 @@ class PutPartiesErrorService extends BasePartiesService {
37
37
  if (isInterSchemeDiscoveryCase) {
38
38
  const isLast = await this.checkLastProxyCallback(alsReq)
39
39
  if (!isLast) {
40
- this.log.verbose('putPartiesErrorByTypeAndID proxy callback was processed')
40
+ this.log.verbose('proxy error callback was processed (not last)')
41
41
  return
42
42
  }
43
43
  } else {
44
44
  const schemeParticipant = await this.validateParticipant(this.state.destination)
45
45
  if (schemeParticipant) {
46
- this.log.warn('Need to cleanup oracle and trigger new inter-scheme discovery flow')
46
+ const err = super.createFspiopServiceUnavailableError(ERROR_MESSAGES.externalPartyError)
47
+ this.log.info('Need to cleanup oracle and throw SERVICE_CURRENTLY_UNAVAILABLE error')
47
48
  await this.cleanupOracle()
48
49
  await this.removeProxyGetPartiesTimeoutCache(alsReq)
49
- return true // need to trigger inter-scheme discovery
50
+ throw err
50
51
  }
51
52
  }
52
53
  }
53
54
 
54
55
  await this.identifyDestinationForCallback()
55
56
  await this.sendErrorCallbackToParticipant()
56
- this.log.info('putPartiesByTypeAndID is done')
57
+ this.log.info('handleRequest is done')
57
58
  }
58
59
 
59
60
  async cleanupOracle () {
@@ -927,7 +927,7 @@ describe('Parties Tests', () => {
927
927
  expect(sendErrorCallArgs[1]).toBe(expectedCallbackEnpointType)
928
928
  })
929
929
 
930
- it('should handle notValidPayeeIdentifier case, and delete partyId from oracle', async () => {
930
+ it('should handle external party error callback, and delete partyId from oracle', async () => {
931
931
  Config.PROXY_CACHE_CONFIG.enabled = true
932
932
  const errorCode = MojaloopApiErrorCodes.PAYEE_IDENTIFIER_NOT_VALID.code
933
933
  const payload = fixtures.errorCallbackResponseDto({ errorCode })
@@ -945,11 +945,14 @@ describe('Parties Tests', () => {
945
945
 
946
946
  await partiesDomain.putPartiesErrorByTypeAndID(headers, params, payload, '', null, null, proxyCache)
947
947
 
948
- expect(participant.sendRequest.callCount).toBe(0)
949
948
  expect(oracle.oracleRequest.callCount).toBe(1)
950
- const [, method] = oracle.oracleRequest.getCall(0).args
951
- expect(method).toBe(RestMethods.DELETE)
952
- expect(Util.proxies.getAllProxiesNames.callCount).toBe(1) // inter-scheme discovery flow was triggered
949
+ expect(oracle.oracleRequest.lastCall.args[1]).toBe(RestMethods.DELETE)
950
+ expect(participant.sendRequest.callCount).toBe(0)
951
+ expect(participant.sendErrorToParticipant.callCount).toBe(1)
952
+ // eslint-disable-next-line no-unused-vars
953
+ const [sentTo, _, data] = participant.sendErrorToParticipant.lastCall.args
954
+ expect(sentTo).toBe(source)
955
+ expect(data.errorInformation.errorCode).toBe('2003')
953
956
  })
954
957
  })
955
958
  })
@@ -29,6 +29,7 @@ const { createMockDeps, oracleMock, participantMock } = require('./deps')
29
29
  // ↑ should be first require to mock external deps ↑
30
30
  const { PutPartiesErrorService } = require('#src/domain/parties/services/index')
31
31
  const fixtures = require('#test/fixtures/index')
32
+ const { ERROR_MESSAGES } = require('#src/constants')
32
33
 
33
34
  const { RestMethods } = PutPartiesErrorService.enums()
34
35
 
@@ -37,16 +38,21 @@ describe('PutPartiesErrorService Tests -->', () => {
37
38
  jest.clearAllMocks()
38
39
  })
39
40
 
40
- test('should cleanup oracle and trigger discovery flow for party from external dfsp', async () => {
41
+ test('should cleanup oracle and throw SERVICE_CURRENTLY_UNAVAILABLE error for party from external dfsp', async () => {
42
+ expect.hasAssertions()
41
43
  participantMock.validateParticipant = jest.fn().mockResolvedValue({})
42
44
  const headers = fixtures.partiesCallHeadersDto({ proxy: 'proxyA' })
43
45
  const params = fixtures.partiesParamsDto()
44
- const service = new PutPartiesErrorService(createMockDeps(), { headers, params })
46
+ const dataUri = fixtures.dataUriDto()
47
+ const service = new PutPartiesErrorService(createMockDeps(), { headers, params, dataUri })
45
48
 
46
- const needDiscovery = await service.handleRequest()
47
- expect(needDiscovery).toBe(true)
48
- expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(1)
49
- expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
49
+ await service.handleRequest()
50
+ .catch(err => {
51
+ expect(err).toEqual(service.createFspiopServiceUnavailableError(ERROR_MESSAGES.externalPartyError))
52
+ expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(1)
53
+ expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
54
+ expect(participantMock.sendErrorToParticipant).not.toHaveBeenCalled()
55
+ })
50
56
  })
51
57
 
52
58
  test('should NOT cleanup oracle if destination is external', async () => {
@@ -63,8 +69,7 @@ describe('PutPartiesErrorService Tests -->', () => {
63
69
  const dataUri = fixtures.dataUriDto()
64
70
  const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
65
71
 
66
- const needDiscovery = await service.handleRequest()
67
- expect(needDiscovery).toBeUndefined()
72
+ await service.handleRequest()
68
73
  expect(oracleMock.oracleRequest).not.toHaveBeenCalled()
69
74
  expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
70
75
  expect(participantMock.sendErrorToParticipant.mock.lastCall[0]).toBe(proxyDest)