diff --git a/__tests__/findUserPdl.spec.ts b/__tests__/findUserPdl.spec.ts index 2c521a09dda96b68fca98c7934f2fdc137d6259b..56fcfb8bfc635495e96c32d736340cc34779b4ae 100644 --- a/__tests__/findUserPdl.spec.ts +++ b/__tests__/findUserPdl.spec.ts @@ -1,12 +1,31 @@ const { errors } = require('cozy-konnector-libs') const { findUserPdl } = require('../src/findUserPdl') +const xml2js = require('xml2js') var mockParsePdl: jest.Mock +// Function to mock in order to test findUserPdl() jest.mock('../src/parsing', () => ({ parseUserPdl: mockParsePdl = jest.fn(), })) +// Dependencies + +jest.mock('easy-soap-request', () => + jest.fn().mockResolvedValue({ + response: { + body: 'test', + }, + }) +) + +jest.mock('../src/requests/sge', () => ({ + rechercherPoint: jest.fn().mockResolvedValue('response'), +})) + +//OK +jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValue('response') + describe('recherchePoint', () => { it('should throw LOGIN_FAILED for too many responses', async () => { mockParsePdl.mockImplementationOnce(() => { diff --git a/src/findUserPdl.js b/src/findUserPdl.js index 69154781afed80dd69a6dffbcd92f63b43713ac3..3a49017668509b217478c7d96d8ce4850ad5e379 100644 --- a/src/findUserPdl.js +++ b/src/findUserPdl.js @@ -29,25 +29,26 @@ async function findUserPdl( 'Content-Type': 'text/xml;charset=UTF-8', apikey: apiAuthKey, } - // const { response } = await soapRequest({ - // url: url, - // headers: sgeHeaders, - // xml: rechercherPoint(appLogin, name, postalCode, inseeCode, address), - // }).catch(err => { - // log('error', 'rechercherPointResponse') - // log('error', err) - // throw errors.LOGIN_FAILED - // }) - // const parsedReply = await xml2js.parseStringPromise(response.body, { - // tagNameProcessors: [parseTags], - // valueProcessors: [parseValue], - // explicitArray: false, - // }) + const { response } = await soapRequest({ + url: url, + headers: sgeHeaders, + xml: rechercherPoint(appLogin, name, postalCode, inseeCode, address), + }).catch(err => { + log('error', 'rechercherPointResponse') + log('error', err) + throw errors.LOGIN_FAILED + }) + + const parsedReply = await xml2js.parseStringPromise(response.body, { + tagNameProcessors: [parseTags], + valueProcessors: [parseValue], + explicitArray: false, + }) try { - console.log('parsedReply') - const pdl = parseUserPdl('parsedReply') + console.log(parsedReply) + const pdl = parseUserPdl(parsedReply) console.log('pdl: ' + pdl) return pdl } catch (error) {