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

wip: fail test ok

parent 27938c05
No related branches found
No related tags found
2 merge requests!12Feat/donnes tech debut contrat,!10Feat/rechercher point
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(() => {
......
......@@ -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) {
......
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