Skip to content
Snippets Groups Projects
Commit c97ec9fc authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat: add TU

parent ee923652
No related branches found
No related tags found
1 merge request!21US878 feat(rechercherpoint): add two fallback in case of no rechercher point match
......@@ -5,20 +5,6 @@ const { findUserPdl } = require('../../src/core/findUserPdl')
const mockSoapRequest = jest.fn()
jest.mock('easy-soap-request', () => async () => mockSoapRequest())
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValue({
Envelope: {
Body: {
Fault: { detail: { erreur: { resultat: { $: { code: 401 } } } } },
faultstring: 'Mock error',
},
},
})
const mockParseUserPdl = jest.fn()
jest.mock('../../src/helpers/parsing', () => ({
parseUserPdl: () => mockParseUserPdl(),
}))
const responseMock = {
response: {
body: 'mockedBody',
......@@ -26,7 +12,23 @@ const responseMock = {
}
describe('recherchePoint', () => {
afterEach(() => {
jest.clearAllMocks()
})
it('should throw LOGIN_FAIL if soapRequest fails', async () => {
const mockParseUserPdl = jest.fn()
jest.mock('../../src/helpers/parsing', () => ({
parseUserPdl: () => mockParseUserPdl(),
}))
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValueOnce({
Envelope: {
Body: {
Fault: { detail: { erreur: { resultat: { $: { code: 401 } } } } },
faultstring: 'Mock error',
},
},
})
mockSoapRequest.mockRejectedValueOnce('reject')
try {
await findUserPdl()
......@@ -37,21 +39,48 @@ describe('recherchePoint', () => {
})
it('should return a correct pdl number', async () => {
const mockParseUserPdl = jest.fn()
jest.mock('../../src/helpers/parsing', () => ({
parseUserPdl: () => mockParseUserPdl(),
}))
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValueOnce({
Envelope: {
Body: {
rechercherPointResponse: {
points: { point: { $: { id: '191919119' } } },
},
},
},
})
mockSoapRequest.mockResolvedValueOnce(responseMock)
mockParseUserPdl.mockResolvedValueOnce('12345')
expect(await findUserPdl()).toBe('12345')
expect(await findUserPdl()).toBe('191919119')
})
it('should handle issue on parsing', async () => {
const cozyKonnectorsLib = require('cozy-konnector-libs')
const spyer = jest.spyOn(cozyKonnectorsLib, 'log')
jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValueOnce({
Envelope: {
Body: {
Fault: {
detail: {
erreur: {
resultat: {
$: {
code: 401,
},
},
},
},
},
},
},
})
mockSoapRequest.mockResolvedValueOnce(responseMock)
mockParseUserPdl.mockRejectedValue(new Error('Async error'))
try {
await findUserPdl()
expect(true).toBe(false)
} catch (error) {
expect(error).toBe(errors.LOGIN_FAILED)
}
await findUserPdl()
// Only verifing that we are going through logs
expect(spyer).toBeCalledTimes(3)
})
})
......@@ -2,5 +2,29 @@
"io.cozy.files": [],
"com.grandlyon.enedis.year": [],
"com.grandlyon.enedis.month": [],
"com.grandlyon.enedis.minute": []
"com.grandlyon.enedis.minute": [],
"io.cozy.accounts": [
{
"cozyMetadata": {
"doctypeVersion": 1,
"metadataVersion": 1,
"createdAt": "2022-10-04T11:27:21.432Z",
"createdByApp": "enedis-sge-grandlyon",
"createdByAppVersion": "1.0.1",
"updatedAt": "2022-10-04T11:27:21.432Z",
"updatedByApps": [
{
"slug": "enedis-sge-grandlyon",
"date": "2022-10-04T11:27:21.432Z",
"version": "1.0.1"
}
]
},
"_id": "1111111",
"account_type": "1111111",
"data": {
"name": "pouet"
}
}
]
}
\ No newline at end of file
......@@ -58,7 +58,6 @@ async function findUserPdl(
return parseUserPdl(parsedReply)
} catch (error) {
log('error', 'Error while parsing user PDL: ' + error)
console.log(error)
if (parsedReply.Envelope.Body.Fault) {
log(
'error',
......
......@@ -43,7 +43,7 @@ async function verifyUserIdentity(
)
if (!pdl) {
log('warn', 'Second change for sge onboarding')
log('warn', 'Second chance for sge onboarding')
// Backup verification
const userAddress = await findUserAddress(
baseUrl,
......@@ -69,7 +69,7 @@ async function verifyUserIdentity(
// Third try, remove address number because it's buggy on SGE side
if (!pdl) {
log('warn', 'Lastchance onboarding for sge')
log('warn', 'Last chance onboarding for sge')
pdl = await findUserPdl(
`${baseUrl}/enedis_SDE_recherche-point/1.0`,
apiAuthKey,
......
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