Skip to content
Snippets Groups Projects
Commit 1f461867 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

Merge branch 'main' of...

Merge branch 'main' of https://forge.grandlyon.com/web-et-numerique/llle_project/enedis-sge-konnector into feat/US858-Save-expiration-date
parents 8007def6 42179a75
No related branches found
No related tags found
1 merge request!19Feat/us858 save expiration date
Pipeline #43195 passed
......@@ -71,4 +71,25 @@ describe('verifyUserIdentity', () => {
expect(true).toBe(false)
}
})
it('should return void when pdl give and recieved are matching with stored inseecode ✅', async () => {
expect.assertions(1)
try {
await verifyUserIdentity(
{
name: 'John',
address: '1 street',
pointId: '12345',
postalCode: '69069',
},
'azertyuiop',
'apiKey',
'login@user.com',
true,
'69387'
)
expect(true).toBeTruthy()
} catch (error) {
expect(true).toBe(false)
}
})
})
{
"name": "enedis-sge-konnector",
"version": "1.0.0",
"name": "enedissgekonnector",
"version": "1.0.1",
"description": "",
"repository": {
"type": "https",
......
......@@ -72,3 +72,18 @@
* @property {string} mesuresCorrigees
* @property {string} periodiciteTransmission
*/
/**
* Account definition
* @typedef {object} Account
* @property {AccountData} data
* @property {object} auth
* @property {object} cozyMetadata
*/
/**
* AccountData definition
* @typedef {object} AccountData
* @property {number} consentId
* @property {string} inseeCode
*/
......@@ -17,9 +17,14 @@ async function verifyUserIdentity(
baseUrl,
apiAuthKey,
loginUtilisateur,
isAlternateStart = false
isAlternateStart = false,
inseeCode = ''
) {
const inseeCode = await getInseeCode(fields.postalCode, fields.city)
// If first start get InseeCode
log('debug', 'verifyUserIdentity')
if (!isAlternateStart) {
inseeCode = await getInseeCode(fields.postalCode, fields.city)
}
const pdl = await findUserPdl(
`${baseUrl}/enedis_SDE_recherche-point/1.0`,
......
......@@ -169,6 +169,7 @@ async function start(fields, cozyParameters) {
...accountData.data,
consentId: consent.ID,
expirationDate: contractEndDate,
inseeCode: user.inseeCode,
})
} else {
log('info', 'Alternate start...')
......@@ -183,7 +184,8 @@ async function start(fields, cozyParameters) {
baseUrl,
apiAuthKey,
sgeLogin,
true
true,
accountData.data.inseeCode
)
if (!userConsent) {
......@@ -209,6 +211,7 @@ async function start(fields, cozyParameters) {
boBaseUrl,
boToken
)
throw errors.USER_ACTION_NEEDED_OAUTH_OUTDATED
}
}
log('info', 'Successfully logged in')
......
......@@ -14,6 +14,11 @@ async function saveAccountData(accountId, accountData) {
return account
}
/**
* Return account
* @param {string} accountId
* @returns {Account}
*/
async function getAccount(accountId) {
log('info', `getAccount: ${accountId}`)
const accounts = await cozyClient.data.findAll('io.cozy.accounts')
......
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