diff --git a/__tests__/core/findUserAddress.spec.js b/__tests__/core/findUserAddress.spec.js index edc130eeb0f6c6ca752edf5b7a3913d9eeedeb42..683f8ab085bca35297ff20004268bd94038c120e 100644 --- a/__tests__/core/findUserAddress.spec.js +++ b/__tests__/core/findUserAddress.spec.js @@ -15,8 +15,10 @@ jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValue({ }) const mockParseUserPdl = jest.fn() +const mockParseUserAddress = jest.fn() jest.mock('../../src/helpers/parsing', () => ({ parseUserPdl: () => mockParseUserPdl(), + parseUserAddress: () => mockParseUserAddress(), })) const responseMock = { @@ -26,7 +28,7 @@ const responseMock = { } describe('findUserAddress', () => { - it('should throw LOGIN_FAIL if soapRequest fails', async () => { + it('should throw VENDOR_DOWN if soapRequest fails', async () => { mockSoapRequest.mockRejectedValueOnce('reject') try { await findUserAddress() @@ -36,15 +38,17 @@ describe('findUserAddress', () => { } }) - it('should return a correct pdl number', async () => { + it('should throw VENDOR_DOWN if parsing user address fails', async () => { mockSoapRequest.mockResolvedValue(responseMock) - mockParseUserPdl.mockResolvedValue('12345') + mockParseUserAddress.mockImplementation(() => { + throw new Error('error') + }) try { await findUserAddress() expect(true).toBe(false) } catch (error) { - expect(error).toBe(errors.LOGIN_FAILED) + expect(error).toBe(errors.VENDOR_DOWN) } }) }) diff --git a/__tests__/core/findUserPdl.spec.js b/__tests__/core/findUserPdl.spec.js index d79e167a8b2f7cf9823a5d9e63dc5159151a9c4f..5ade030d14a1743058cea25029c770c77effc149 100644 --- a/__tests__/core/findUserPdl.spec.js +++ b/__tests__/core/findUserPdl.spec.js @@ -57,7 +57,7 @@ describe('recherchePoint', () => { expect(spyer).toBeCalledTimes(5) }) - it('should throw LOGIN_FAIL if soapRequest fails 🚫', async () => { + it('should throw VENDOR_DOWN if soapRequest fails 🚫', async () => { const mockParseUserPdl = jest.fn() jest.mock('../../src/helpers/parsing', () => ({ parseUserPdl: () => mockParseUserPdl(), @@ -75,7 +75,7 @@ describe('recherchePoint', () => { await findUserPdl() expect(true).toBe(false) } catch (error) { - expect(error).toBe(errors.LOGIN_FAILED) + expect(error).toBe(errors.VENDOR_DOWN) } }) }) diff --git a/src/core/findUserAddress.js b/src/core/findUserAddress.js index fa2ef7138daa3a0c6c0fb2de79089f8fa45a662e..0f426f21368bb94eb8b6faa36a65039c09c099b9 100644 --- a/src/core/findUserAddress.js +++ b/src/core/findUserAddress.js @@ -52,7 +52,7 @@ async function findUserAddress(url, apiAuthKey, userLogin, pointId) { `Enedis issue ${result.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${result.Envelope.Body.Fault.faultstring}` ) Sentry.captureException(errorMessage) - throw errors.LOGIN_FAILED + throw errors.VENDOR_DOWN } } diff --git a/src/core/findUserPdl.js b/src/core/findUserPdl.js index 4af3a6d77c2bedcbc4830cfc7cb904e0b5242abb..11bd63525e5cd737a010d45efb5cfa4ba73d4a6d 100644 --- a/src/core/findUserPdl.js +++ b/src/core/findUserPdl.js @@ -47,7 +47,7 @@ async function findUserPdl( log('error', 'rechercherPointResponse') log('error', err) Sentry.captureException('rechercherPointResponse', err) - throw errors.LOGIN_FAILED + throw errors.VENDOR_DOWN }) const parsedReply = await xml2js.parseStringPromise(response.body, {