Skip to content
Snippets Groups Projects
Commit 4371435d authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

fix: coverage to 100

parent 733d76fa
No related branches found
No related tags found
2 merge requests!12Feat/donnes tech debut contrat,!10Feat/rechercher point
Pipeline #39783 failed
......@@ -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',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment