account-lookup-service 17.12.10 → 17.13.0-snapshot.10

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.
@@ -25,45 +25,54 @@
25
25
  --------------
26
26
  ******/
27
27
 
28
- const { createMockDeps, oracleMock, participantMock } = require('./deps')
29
- // ↑ should be first require to mock external deps ↑
30
28
  const { PutPartiesErrorService } = require('#src/domain/parties/services/index')
29
+ const { createMockDeps, createOracleFacadeMock, createParticipantFacadeMock } = require('./deps')
31
30
  const fixtures = require('#test/fixtures/index')
32
31
 
33
32
  const { RestMethods, Headers } = PutPartiesErrorService.enums()
34
33
 
35
34
  describe('PutPartiesErrorService Tests -->', () => {
35
+ let oracle
36
+ let participant
37
+
36
38
  beforeEach(() => {
37
39
  jest.clearAllMocks()
40
+ oracle = createOracleFacadeMock()
41
+ participant = createParticipantFacadeMock()
38
42
  })
39
43
 
40
- test('should cleanup oracle and forward SERVICE_CURRENTLY_UNAVAILABLE error for party from external dfsp', async () => {
41
- participantMock.validateParticipant = jest.fn().mockRejectedValue(new Error('No participant found')) // external participant
42
- const destination = 'externalDfsp'
44
+ test('should cleanup oracle and forward PARTY_RESOLUTION_FAILURE error for party from external dfsp', async () => {
45
+ participant.validateParticipant = jest.fn().mockRejectedValue(new Error('No participant found')) // external participant
46
+ oracle.oracleRequest = jest.fn().mockResolvedValue({
47
+ data: { partyList: [{ fspId: 'fspId' }] }
48
+ })
49
+ const destination = 'externalDestination'
43
50
  const proxyDest = 'proxyDest'
44
- const deps = createMockDeps()
51
+ const deps = createMockDeps({ oracle, participant })
45
52
  deps.proxyCache.lookupProxyByDfspId = jest.fn().mockResolvedValue(proxyDest)
46
53
 
47
54
  const headers = fixtures.partiesCallHeadersDto({ destination, proxy: 'proxyA' })
48
55
  const params = fixtures.partiesParamsDto()
49
- const dataUri = fixtures.dataUriDto()
50
- const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
56
+ const data = { test: true }
57
+ const dataUri = fixtures.dataUriDto(data)
51
58
 
59
+ const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
52
60
  await service.handleRequest()
53
- expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(1)
54
- expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
55
- expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
56
- // eslint-disable-next-line no-unused-vars
57
- const [sentTo, _, payload, cbHeaders] = participantMock.sendErrorToParticipant.mock.lastCall
61
+
62
+ expect(oracle.oracleRequest).toHaveBeenCalledTimes(2)
63
+ expect(oracle.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
64
+ expect(participant.sendErrorToParticipant).toHaveBeenCalledTimes(1)
65
+
66
+ const [sentTo, , payload, cbHeaders] = participant.sendErrorToParticipant.mock.lastCall
58
67
  expect(sentTo).toBe(proxyDest)
59
68
  expect(cbHeaders[Headers.FSPIOP.DESTINATION]).toBe(destination)
60
- expect(payload.errorInformation.errorCode).toBe('2003')
69
+ expect(payload).toBe(JSON.stringify(data))
61
70
  })
62
71
 
63
72
  test('should NOT cleanup oracle if destination is local', async () => {
64
73
  const destination = 'localDfsp'
65
- const deps = createMockDeps()
66
- deps.participant.validateParticipant = jest.fn().mockResolvedValue({})
74
+ participant.validateParticipant = jest.fn().mockResolvedValue({})
75
+ const deps = createMockDeps({ participant })
67
76
 
68
77
  const headers = fixtures.partiesCallHeadersDto({ destination })
69
78
  const params = fixtures.partiesParamsDto()
@@ -71,8 +80,8 @@ describe('PutPartiesErrorService Tests -->', () => {
71
80
  const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
72
81
 
73
82
  await service.handleRequest()
74
- expect(oracleMock.oracleRequest).not.toHaveBeenCalled()
75
- expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
76
- expect(participantMock.sendErrorToParticipant.mock.lastCall[0]).toBe(destination)
83
+ expect(oracle.oracleRequest).not.toHaveBeenCalled()
84
+ expect(participant.sendErrorToParticipant).toHaveBeenCalledTimes(1)
85
+ expect(participant.sendErrorToParticipant.mock.lastCall[0]).toBe(destination)
77
86
  })
78
87
  })
@@ -32,18 +32,34 @@ const oracleMock = require('#src/models/oracle/facade')
32
32
  const participantMock = require('#src/models/participantEndpoint/facade')
33
33
  const { createDeps } = require('#src/domain/parties/deps')
34
34
  const { logger } = require('#src/lib/index')
35
- const { createProxyCacheMock, createProxiesUtilMock } = require('#test/util/mockDeps')
35
+ const {
36
+ createOracleFacadeMock,
37
+ createParticipantFacadeMock,
38
+ createProxyCacheMock,
39
+ createProxiesUtilMock
40
+ } = require('#test/util/mockDeps')
36
41
 
37
42
  /** @returns {PartiesDeps} */
38
43
  const createMockDeps = ({
44
+ cache,
45
+ oracle,
46
+ participant,
39
47
  proxyCache = createProxyCacheMock(),
40
48
  proxies = createProxiesUtilMock(),
41
- log = logger.child({ test: true }),
42
- cache
43
- } = {}) => createDeps({ cache, proxyCache, proxies, log })
49
+ log = logger.child({ test: true })
50
+ } = {}) => createDeps({
51
+ cache,
52
+ oracle,
53
+ participant,
54
+ proxyCache,
55
+ proxies,
56
+ log
57
+ })
44
58
 
45
59
  module.exports = {
46
60
  createMockDeps,
61
+ createOracleFacadeMock,
62
+ createParticipantFacadeMock,
47
63
  createProxyCacheMock,
48
64
  createProxiesUtilMock,
49
65
  oracleMock,
@@ -66,7 +66,27 @@ const createProxiesUtilMock = ({
66
66
  invalidateProxiesCache
67
67
  })
68
68
 
69
+ const createParticipantFacadeMock = ({
70
+ validateParticipant = jest.fn(),
71
+ sendRequest = jest.fn(),
72
+ sendErrorToParticipant = jest.fn()
73
+ } = {}) => ({
74
+ validateParticipant,
75
+ sendRequest,
76
+ sendErrorToParticipant
77
+ })
78
+
79
+ const createOracleFacadeMock = ({
80
+ oracleRequest = jest.fn(),
81
+ oracleBatchRequest = jest.fn()
82
+ } = {}) => ({
83
+ oracleRequest,
84
+ oracleBatchRequest
85
+ })
86
+
69
87
  module.exports = {
88
+ createOracleFacadeMock,
89
+ createParticipantFacadeMock,
70
90
  createProxyCacheMock,
71
91
  createProxiesUtilMock
72
92
  }