account-lookup-service 17.12.4 → 17.12.5

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.
@@ -42,7 +42,7 @@ class PutPartiesErrorService extends BasePartiesService {
42
42
  }
43
43
  } else {
44
44
  const schemeParticipant = await this.validateParticipant(this.state.destination)
45
- if (schemeParticipant) {
45
+ if (!schemeParticipant) {
46
46
  this.log.info('Need to cleanup oracle and forward SERVICE_CURRENTLY_UNAVAILABLE error')
47
47
  await this.cleanupOracle()
48
48
  await this.removeProxyGetPartiesTimeoutCache(alsReq)
@@ -86,6 +86,7 @@ class PutPartiesErrorService extends BasePartiesService {
86
86
  const callbackHeaders = BasePartiesService.createErrorCallbackHeaders(headers, params, this.state.destination)
87
87
  const errorInfo = await this.deps.partiesUtils.makePutPartiesErrorPayload(this.deps.config, error, callbackHeaders, params)
88
88
 
89
+ await this.identifyDestinationForCallback()
89
90
  await super.sendErrorCallback({
90
91
  errorInfo,
91
92
  headers: callbackHeaders,
@@ -951,9 +951,10 @@ describe('Parties Tests', () => {
951
951
  const proxy = `proxy-${Date.now()}`
952
952
  const headers = fixtures.partiesCallHeadersDto({ destination, proxy })
953
953
  const { params } = Helper.putByTypeIdRequest
954
- participant.validateParticipant = sandbox.stub().resolves({})
954
+ participant.validateParticipant = sandbox.stub().resolves(null) // external participant
955
955
  participant.sendRequest = sandbox.stub().resolves()
956
956
  participant.sendErrorToParticipant = sandbox.stub().resolves()
957
+ proxyCache.lookupProxyByDfspId = sandbox.stub().resolves(proxy)
957
958
  oracleEndpointCached.getOracleEndpointByType = sandbox.stub().resolves([
958
959
  { value: 'http://oracle.endpoint' }
959
960
  ])
@@ -966,8 +967,9 @@ describe('Parties Tests', () => {
966
967
  expect(participant.sendRequest.callCount).toBe(0)
967
968
  expect(participant.sendErrorToParticipant.callCount).toBe(1)
968
969
  // eslint-disable-next-line no-unused-vars
969
- const [sentTo, _, data] = participant.sendErrorToParticipant.lastCall.args
970
- expect(sentTo).toBe(destination)
970
+ const [sentTo, _, data, cbHeaders] = participant.sendErrorToParticipant.lastCall.args
971
+ expect(sentTo).toBe(proxy)
972
+ expect(cbHeaders[Headers.FSPIOP.DESTINATION]).toBe(destination)
971
973
  expect(data.errorInformation.errorCode).toBe('2003')
972
974
  })
973
975
  })
@@ -30,7 +30,7 @@ const { createMockDeps, oracleMock, participantMock } = require('./deps')
30
30
  const { PutPartiesErrorService } = require('#src/domain/parties/services/index')
31
31
  const fixtures = require('#test/fixtures/index')
32
32
 
33
- const { RestMethods } = PutPartiesErrorService.enums()
33
+ const { RestMethods, Headers } = PutPartiesErrorService.enums()
34
34
 
35
35
  describe('PutPartiesErrorService Tests -->', () => {
36
36
  beforeEach(() => {
@@ -38,33 +38,34 @@ describe('PutPartiesErrorService Tests -->', () => {
38
38
  })
39
39
 
40
40
  test('should cleanup oracle and forward SERVICE_CURRENTLY_UNAVAILABLE error for party from external dfsp', async () => {
41
- participantMock.validateParticipant = jest.fn().mockResolvedValue({})
42
- const destination = 'destFsp'
41
+ participantMock.validateParticipant = jest.fn().mockRejectedValue(new Error('No participant found')) // external participant
42
+ const destination = 'externalDfsp'
43
+ const proxyDest = 'proxyDest'
44
+ const deps = createMockDeps()
45
+ deps.proxyCache.lookupProxyByDfspId = jest.fn().mockResolvedValue(proxyDest)
46
+
43
47
  const headers = fixtures.partiesCallHeadersDto({ destination, proxy: 'proxyA' })
44
48
  const params = fixtures.partiesParamsDto()
45
49
  const dataUri = fixtures.dataUriDto()
46
- const service = new PutPartiesErrorService(createMockDeps(), { headers, params, dataUri })
50
+ const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
47
51
 
48
52
  await service.handleRequest()
49
53
  expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(1)
50
54
  expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
51
55
  expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
52
56
  // eslint-disable-next-line no-unused-vars
53
- const [sentTo, _, payload] = participantMock.sendErrorToParticipant.mock.lastCall
54
- expect(sentTo).toBe(destination)
57
+ const [sentTo, _, payload, cbHeaders] = participantMock.sendErrorToParticipant.mock.lastCall
58
+ expect(sentTo).toBe(proxyDest)
59
+ expect(cbHeaders[Headers.FSPIOP.DESTINATION]).toBe(destination)
55
60
  expect(payload.errorInformation.errorCode).toBe('2003')
56
61
  })
57
62
 
58
- test('should NOT cleanup oracle if destination is external', async () => {
59
- const destination = 'externalDfsp'
60
- const proxyDest = 'proxyDest'
63
+ test('should NOT cleanup oracle if destination is local', async () => {
64
+ const destination = 'localDfsp'
61
65
  const deps = createMockDeps()
62
- deps.participant.validateParticipant = jest.fn().mockResolvedValue(null)
63
- deps.proxyCache.lookupProxyByDfspId = jest.fn().mockResolvedValue(proxyDest)
66
+ deps.participant.validateParticipant = jest.fn().mockResolvedValue({})
64
67
 
65
- const headers = fixtures.partiesCallHeadersDto({
66
- destination, proxy: 'proxyA'
67
- })
68
+ const headers = fixtures.partiesCallHeadersDto({ destination })
68
69
  const params = fixtures.partiesParamsDto()
69
70
  const dataUri = fixtures.dataUriDto()
70
71
  const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
@@ -72,6 +73,6 @@ describe('PutPartiesErrorService Tests -->', () => {
72
73
  await service.handleRequest()
73
74
  expect(oracleMock.oracleRequest).not.toHaveBeenCalled()
74
75
  expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
75
- expect(participantMock.sendErrorToParticipant.mock.lastCall[0]).toBe(proxyDest)
76
+ expect(participantMock.sendErrorToParticipant.mock.lastCall[0]).toBe(destination)
76
77
  })
77
78
  })
@@ -27,12 +27,11 @@
27
27
 
28
28
  const { createMockDeps, participantMock } = require('./deps')
29
29
  // ↑ should be first require to mock external deps ↑
30
- const { Enum } = require('@mojaloop/central-services-shared')
31
30
  const { PutPartiesService } = require('#src/domain/parties/services/index')
32
31
  const config = require('#src/lib/config')
33
32
  const fixtures = require('#test/fixtures/index')
34
33
 
35
- const { Headers } = Enum.Http
34
+ const { Headers } = PutPartiesService.enums()
36
35
 
37
36
  describe('PutPartiesService Tests -->', () => {
38
37
  beforeEach(() => {
@@ -97,4 +96,22 @@ describe('PutPartiesService Tests -->', () => {
97
96
  expect(cbHeaders[Headers.FSPIOP.SOURCE]).toBe(config.HUB_NAME)
98
97
  expect(cbHeaders[Headers.FSPIOP.DESTINATION]).toBe(source)
99
98
  })
99
+
100
+ test('should just log error in case handleError failed', async () => {
101
+ const headers = fixtures.partiesCallHeadersDto()
102
+ const params = fixtures.partiesParamsDto()
103
+ const dataUri = fixtures.dataUriDto()
104
+ const service = new PutPartiesService(createMockDeps(), { headers, params, dataUri })
105
+
106
+ service.handleRequest = jest.fn().mockRejectedValue(new Error('handleRequest failed'))
107
+ service.identifyDestinationForCallback = jest.fn()
108
+ service.sendErrorCallback = jest.fn().mockRejectedValue(new Error('sendErrorCallback failed'))
109
+ const logSpy = jest.spyOn(service.log.mlLogger, 'error')
110
+
111
+ const result = await service.handleRequest()
112
+ .catch(err => service.handleError(err))
113
+
114
+ expect(result).toBeUndefined()
115
+ expect(logSpy.mock.lastCall[0]).toBe('failed to handleError. No further processing! ')
116
+ })
100
117
  })