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') ...@@ -5,20 +5,6 @@ const { findUserPdl } = require('../../src/core/findUserPdl')
const mockSoapRequest = jest.fn() const mockSoapRequest = jest.fn()
jest.mock('easy-soap-request', () => async () => mockSoapRequest()) 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 = { const responseMock = {
response: { response: {
body: 'mockedBody', body: 'mockedBody',
...@@ -26,7 +12,23 @@ const responseMock = { ...@@ -26,7 +12,23 @@ const responseMock = {
} }
describe('recherchePoint', () => { describe('recherchePoint', () => {
afterEach(() => {
jest.clearAllMocks()
})
it('should throw LOGIN_FAIL if soapRequest fails', async () => { 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') mockSoapRequest.mockRejectedValueOnce('reject')
try { try {
await findUserPdl() await findUserPdl()
...@@ -37,21 +39,48 @@ describe('recherchePoint', () => { ...@@ -37,21 +39,48 @@ describe('recherchePoint', () => {
}) })
it('should return a correct pdl number', async () => { 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) mockSoapRequest.mockResolvedValueOnce(responseMock)
mockParseUserPdl.mockResolvedValueOnce('12345')
expect(await findUserPdl()).toBe('12345') expect(await findUserPdl()).toBe('191919119')
}) })
it('should handle issue on parsing', async () => { 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) mockSoapRequest.mockResolvedValueOnce(responseMock)
mockParseUserPdl.mockRejectedValue(new Error('Async error'))
try { await findUserPdl()
await findUserPdl() // Only verifing that we are going through logs
expect(true).toBe(false) expect(spyer).toBeCalledTimes(3)
} catch (error) {
expect(error).toBe(errors.LOGIN_FAILED)
}
}) })
}) })
...@@ -2,5 +2,29 @@ ...@@ -2,5 +2,29 @@
"io.cozy.files": [], "io.cozy.files": [],
"com.grandlyon.enedis.year": [], "com.grandlyon.enedis.year": [],
"com.grandlyon.enedis.month": [], "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( ...@@ -58,7 +58,6 @@ async function findUserPdl(
return parseUserPdl(parsedReply) return parseUserPdl(parsedReply)
} catch (error) { } catch (error) {
log('error', 'Error while parsing user PDL: ' + error) log('error', 'Error while parsing user PDL: ' + error)
console.log(error)
if (parsedReply.Envelope.Body.Fault) { if (parsedReply.Envelope.Body.Fault) {
log( log(
'error', 'error',
......
...@@ -43,7 +43,7 @@ async function verifyUserIdentity( ...@@ -43,7 +43,7 @@ async function verifyUserIdentity(
) )
if (!pdl) { if (!pdl) {
log('warn', 'Second change for sge onboarding') log('warn', 'Second chance for sge onboarding')
// Backup verification // Backup verification
const userAddress = await findUserAddress( const userAddress = await findUserAddress(
baseUrl, baseUrl,
...@@ -69,7 +69,7 @@ async function verifyUserIdentity( ...@@ -69,7 +69,7 @@ async function verifyUserIdentity(
// Third try, remove address number because it's buggy on SGE side // Third try, remove address number because it's buggy on SGE side
if (!pdl) { if (!pdl) {
log('warn', 'Lastchance onboarding for sge') log('warn', 'Last chance onboarding for sge')
pdl = await findUserPdl( pdl = await findUserPdl(
`${baseUrl}/enedis_SDE_recherche-point/1.0`, `${baseUrl}/enedis_SDE_recherche-point/1.0`,
apiAuthKey, apiAuthKey,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment