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

cleanup

parent dfff97e4
No related branches found
No related tags found
2 merge requests!12Feat/donnes tech debut contrat,!10Feat/rechercher point
Pipeline #39781 failed
......@@ -2,14 +2,15 @@ const { errors } = require('cozy-konnector-libs')
const { findUserPdl } = require('../src/findUserPdl')
const xml2js = require('xml2js')
var mockParsePdl
var mockParseUserPdl
// Function to mock in order to test findUserPdl()
jest.mock('../src/parsing', () => ({
parseUserPdl: (mockParsePdl = jest.fn()),
parseUserPdl: (mockParseUserPdl = jest.fn()),
}))
// Dependencies
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValue('response')
jest.mock('easy-soap-request', () =>
jest.fn().mockResolvedValue({
response: {
......@@ -18,20 +19,14 @@ jest.mock('easy-soap-request', () =>
})
)
jest.mock('../src/requests/sge', () => ({
rechercherPoint: jest.fn().mockResolvedValue('response'),
}))
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValue('response')
describe('recherchePoint', () => {
it('should throw LOGIN_FAILED for too many responses', async () => {
mockParsePdl.mockImplementationOnce(() => {
mockParseUserPdl.mockImplementationOnce(() => {
throw new Error('fail')
})
try {
const result = await findUserPdl(
await findUserPdl(
'azertyuiop',
'apiKey',
'login@user.com',
......@@ -40,16 +35,14 @@ describe('recherchePoint', () => {
'69069',
'69069'
)
console.log('result: ' + result)
expect(true).toBe(false)
} catch (error) {
console.log('error in test file ' + error)
expect(error).toBe(errors.LOGIN_FAILED)
}
})
it('should return a correct pdl number', async () => {
mockParsePdl.mockResolvedValue('12345')
mockParseUserPdl.mockResolvedValue('12345')
expect(
await findUserPdl(
'azertyuiop',
......
......@@ -47,10 +47,7 @@ async function findUserPdl(
})
try {
console.log(parsedReply)
const pdl = parseUserPdl(parsedReply)
console.log('pdl: ' + pdl)
return pdl
return parseUserPdl(parsedReply)
} catch (error) {
throw errors.LOGIN_FAILED
}
......
......@@ -27,7 +27,6 @@ async function verifyUserIdentity(
fields.postalCode,
inseeCode
)
console.log(pdl)
if (fields.pointId != pdl) {
log('error', 'PointId does not match')
......
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