From 4371435d9f14073818810663ce6766641814586b Mon Sep 17 00:00:00 2001
From: Bastien DUMONT <bdumont@grandlyon.com>
Date: Wed, 3 Aug 2022 15:57:14 +0200
Subject: [PATCH] fix: coverage to 100

---
 __tests__/findUserPdl.spec.js | 37 ++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/__tests__/findUserPdl.spec.js b/__tests__/findUserPdl.spec.js
index f694c91..aebbf6e 100644
--- a/__tests__/findUserPdl.spec.js
+++ b/__tests__/findUserPdl.spec.js
@@ -3,24 +3,24 @@ const { findUserPdl } = require('../src/findUserPdl')
 const xml2js = require('xml2js')
 
 var mockParseUserPdl
+var mockSoapRequest
 
-// Function to mock in order to test findUserPdl()
 jest.mock('../src/parsing', () => ({
   parseUserPdl: (mockParseUserPdl = jest.fn()),
 }))
 
-// Dependencies
 jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValue('response')
-jest.mock('easy-soap-request', () =>
-  jest.fn().mockResolvedValue({
-    response: {
-      body: 'test',
-    },
-  })
-)
+jest.mock('easy-soap-request', () => (mockSoapRequest = jest.fn()))
+
+const responseMock = {
+  response: {
+    body: 'mockedBody',
+  },
+}
 
 describe('recherchePoint', () => {
   it('should throw LOGIN_FAILED for too many responses', async () => {
+    mockSoapRequest.mockResolvedValue(responseMock)
     mockParseUserPdl.mockImplementationOnce(() => {
       throw new Error('fail')
     })
@@ -41,8 +41,27 @@ describe('recherchePoint', () => {
     }
   })
 
+  it('should throw LOGIN_FAIL if soapRequest fails', async () => {
+    mockSoapRequest.mockRejectedValueOnce('reject')
+    try {
+      await findUserPdl(
+        'azertyuiop',
+        'apiKey',
+        'login@user.com',
+        'John',
+        '1 street',
+        '69069',
+        '69069'
+      )
+      expect(true).toBe(false)
+    } catch (error) {
+      expect(error).toBe(errors.LOGIN_FAILED)
+    }
+  })
+
   it('should return a correct pdl number', async () => {
     mockParseUserPdl.mockResolvedValue('12345')
+    mockSoapRequest.mockResolvedValue(responseMock)
     expect(
       await findUserPdl(
         'azertyuiop',
-- 
GitLab