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

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.16",
4
+ "version": "17.8.0-snapshot.17",
5
5
  "license": "Apache-2.0",
6
6
  "author": "ModusBox",
7
7
  "contributors": [
@@ -32,20 +32,22 @@ class PutPartiesErrorService extends BasePartiesService {
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?
35
- const isPending = await this.deps.proxyCache.isPendingCallback(alsReq)
35
+ const isInterSchemeDiscoveryCase = await this.deps.proxyCache.isPendingCallback(alsReq)
36
36
 
37
- if (!isPending) {
38
- // not initial inter-scheme discovery case. Cleanup oracle and trigger inter-scheme discovery
39
- this.log.warn('Need to cleanup oracle and trigger new inter-scheme discovery flow')
40
- await this.cleanupOracle()
41
- await this.removeProxyGetPartiesTimeoutCache(alsReq)
42
- return true // need to trigger inter-scheme discovery
43
- }
44
-
45
- const isLast = await this.checkLastProxyCallback(alsReq)
46
- if (!isLast) {
47
- this.log.verbose('putPartiesErrorByTypeAndID proxy callback was processed')
48
- return
37
+ if (isInterSchemeDiscoveryCase) {
38
+ const isLast = await this.checkLastProxyCallback(alsReq)
39
+ if (!isLast) {
40
+ this.log.verbose('putPartiesErrorByTypeAndID proxy callback was processed')
41
+ return
42
+ }
43
+ } else {
44
+ const schemeParticipant = await this.validateParticipant(this.state.destination)
45
+ if (schemeParticipant) {
46
+ this.log.warn('Need to cleanup oracle and trigger new inter-scheme discovery flow')
47
+ await this.cleanupOracle()
48
+ await this.removeProxyGetPartiesTimeoutCache(alsReq)
49
+ return true // need to trigger inter-scheme discovery
50
+ }
49
51
  }
50
52
  }
51
53
 
@@ -26,10 +26,11 @@
26
26
  ******/
27
27
 
28
28
  const { randomUUID } = require('node:crypto')
29
- const { Enum } = require('@mojaloop/central-services-shared')
29
+ const { Enum, Util } = jest.requireActual('@mojaloop/central-services-shared')
30
30
  const isoFixtures = require('./iso')
31
31
 
32
32
  const { Headers } = Enum.Http
33
+ const { encodePayload } = Util.StreamingProtocol
33
34
 
34
35
  const headersDto = ({
35
36
  source = 'fromDfsp',
@@ -145,6 +146,8 @@ const postParticipantsPayloadDto = ({
145
146
  ...(currency && { currency })
146
147
  })
147
148
 
149
+ const dataUriDto = (payload = {}) => encodePayload(JSON.stringify(payload), 'application/json')
150
+
148
151
  const errorCallbackResponseDto = ({
149
152
  errorCode = '1234',
150
153
  errorDescription = 'Error description',
@@ -195,6 +198,7 @@ module.exports = {
195
198
  oracleRequestResponseDto,
196
199
  putPartiesSuccessResponseDto,
197
200
  postParticipantsPayloadDto,
201
+ dataUriDto,
198
202
  errorCallbackResponseDto,
199
203
  expiredCacheKeyDto,
200
204
  mockAlsRequestDto,
@@ -935,6 +935,7 @@ describe('Parties Tests', () => {
935
935
  const proxy = `proxy-${Date.now()}`
936
936
  const headers = fixtures.partiesCallHeadersDto({ source, proxy })
937
937
  const { params } = Helper.putByTypeIdRequest
938
+ participant.validateParticipant = sandbox.stub().resolves({})
938
939
  participant.sendRequest = sandbox.stub().resolves()
939
940
  participant.sendErrorToParticipant = sandbox.stub().resolves()
940
941
  oracleEndpointCached.getOracleEndpointByType = sandbox.stub().resolves([
@@ -948,9 +949,7 @@ describe('Parties Tests', () => {
948
949
  expect(oracle.oracleRequest.callCount).toBe(1)
949
950
  const [, method] = oracle.oracleRequest.getCall(0).args
950
951
  expect(method).toBe(RestMethods.DELETE)
951
- // todo: think, how to stub getPartiesByTypeAndID call
952
- // expect(partiesDomain.getPartiesByTypeAndID.callCount).toBe(1)
953
- // expect(participant.sendErrorToParticipant.callCount).toBe(0)
952
+ expect(Util.proxies.getAllProxiesNames.callCount).toBe(1) // inter-scheme discovery flow was triggered
954
953
  })
955
954
  })
956
955
  })
@@ -25,7 +25,7 @@
25
25
  --------------
26
26
  ******/
27
27
 
28
- const { createMockDeps, oracleMock } = require('./deps')
28
+ 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')
@@ -38,13 +38,35 @@ describe('PutPartiesErrorService Tests -->', () => {
38
38
  })
39
39
 
40
40
  test('should cleanup oracle and trigger discovery flow for party from external dfsp', async () => {
41
+ participantMock.validateParticipant = jest.fn().mockResolvedValue({})
41
42
  const headers = fixtures.partiesCallHeadersDto({ proxy: 'proxyA' })
42
43
  const params = fixtures.partiesParamsDto()
43
44
  const service = new PutPartiesErrorService(createMockDeps(), { headers, params })
44
45
 
45
46
  const needDiscovery = await service.handleRequest()
46
47
  expect(needDiscovery).toBe(true)
47
- expect(oracleMock.oracleRequest.mock.calls.length).toBe(1)
48
+ expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(1)
48
49
  expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
49
50
  })
51
+
52
+ test('should NOT cleanup oracle if destination is external', async () => {
53
+ const destination = 'externalDfsp'
54
+ const proxyDest = 'proxyDest'
55
+ const deps = createMockDeps()
56
+ deps.participant.validateParticipant = jest.fn().mockResolvedValue(null)
57
+ deps.proxyCache.lookupProxyByDfspId = jest.fn().mockResolvedValue(proxyDest)
58
+
59
+ const headers = fixtures.partiesCallHeadersDto({
60
+ destination, proxy: 'proxyA'
61
+ })
62
+ const params = fixtures.partiesParamsDto()
63
+ const dataUri = fixtures.dataUriDto()
64
+ const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
65
+
66
+ const needDiscovery = await service.handleRequest()
67
+ expect(needDiscovery).toBeUndefined()
68
+ expect(oracleMock.oracleRequest).not.toHaveBeenCalled()
69
+ expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
70
+ expect(participantMock.sendErrorToParticipant.mock.lastCall[0]).toBe(proxyDest)
71
+ })
50
72
  })