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

wip: findUserPdl test working

parent a9f74347
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')
describe('recherchePoint', () => {
// mock soap request with result
// mock soap request to throw error
it('should throw LOGIN_FAILED for too many responses', () => {
expect(
findUserPdl()
//
// .env
).toBe(errors.LOGIN_FAILED)
})
it('should throw LOGIN_FAILED for empty response', () => {})
it('should return a correct pdl number', () => {
// Test with a given address ?
})
})
const { errors } = require('cozy-konnector-libs')
const { findUserPdl } = require('../src/findUserPdl')
var mockParsePdl: jest.Mock
jest.mock('../src/parsing', () => ({
parseUserPdl: mockParsePdl = jest.fn(),
}))
describe('recherchePoint', () => {
it('should throw LOGIN_FAILED for too many responses', async () => {
mockParsePdl.mockImplementationOnce(() => {
throw new Error('fail')
})
try {
const result = await findUserPdl(
'azertyuiop',
'apiKey',
'login@user.com',
'John',
'1 street',
'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')
expect(
await findUserPdl(
'azertyuiop',
'apiKey',
'login@user.com',
'John',
'1 street',
'69069',
'69069'
)
).toBe('12345')
})
})
...@@ -5,7 +5,6 @@ jest.mock('../src/requests/insee', () => ({ ...@@ -5,7 +5,6 @@ jest.mock('../src/requests/insee', () => ({
getInseeCode: jest.fn().mockResolvedValue(69), getInseeCode: jest.fn().mockResolvedValue(69),
})) }))
// This mock doenst work somehow
jest.mock('../src/findUserPdl', () => ({ jest.mock('../src/findUserPdl', () => ({
findUserPdl: jest.fn().mockResolvedValue('12345'), findUserPdl: jest.fn().mockResolvedValue('12345'),
})) }))
......
...@@ -6,6 +6,13 @@ const { rechercherPoint } = require('./requests/sge') ...@@ -6,6 +6,13 @@ const { rechercherPoint } = require('./requests/sge')
const xml2js = require('xml2js') const xml2js = require('xml2js')
/** /**
* @param {string} url
* @param {string} apiAuthKey
* @param {string} appLogin
* @param {string} name
* @param {string} address
* @param {string} postalCode
* @param {string} inseeCode
* @return {Promise<string | null>} User Pdl * @return {Promise<string | null>} User Pdl
*/ */
async function findUserPdl( async function findUserPdl(
...@@ -22,24 +29,27 @@ async function findUserPdl( ...@@ -22,24 +29,27 @@ async function findUserPdl(
'Content-Type': 'text/xml;charset=UTF-8', 'Content-Type': 'text/xml;charset=UTF-8',
apikey: apiAuthKey, apikey: apiAuthKey,
} }
const { response } = await soapRequest({ // const { response } = await soapRequest({
url: url, // url: url,
headers: sgeHeaders, // headers: sgeHeaders,
xml: rechercherPoint(appLogin, name, postalCode, inseeCode, address), // xml: rechercherPoint(appLogin, name, postalCode, inseeCode, address),
}).catch(err => { // }).catch(err => {
log('error', 'rechercherPointResponse') // log('error', 'rechercherPointResponse')
log('error', err) // log('error', err)
throw errors.LOGIN_FAILED // throw errors.LOGIN_FAILED
}) // })
const parsedReply = await xml2js.parseStringPromise(response.body, { // const parsedReply = await xml2js.parseStringPromise(response.body, {
tagNameProcessors: [parseTags], // tagNameProcessors: [parseTags],
valueProcessors: [parseValue], // valueProcessors: [parseValue],
explicitArray: false, // explicitArray: false,
}) // })
try { try {
return parseUserPdl(parsedReply) console.log('parsedReply')
const pdl = parseUserPdl('parsedReply')
console.log('pdl: ' + pdl)
return pdl
} catch (error) { } catch (error) {
throw errors.LOGIN_FAILED throw errors.LOGIN_FAILED
} }
......
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