Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
enedis_sge_konnector
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
LLLE_Project
enedis_sge_konnector
Commits
9b8a491f
Commit
9b8a491f
authored
2 years ago
by
Bastien DUMONT
Browse files
Options
Downloads
Patches
Plain Diff
fix: insee now throws errors
parent
8cc7e810
No related branches found
No related tags found
2 merge requests
!12
Feat/donnes tech debut contrat
,
!10
Feat/rechercher point
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
__tests__/requests/insee.spec.js
+13
-4
13 additions, 4 deletions
__tests__/requests/insee.spec.js
src/index.js
+2
-2
2 additions, 2 deletions
src/index.js
src/requests/insee.js
+4
-4
4 additions, 4 deletions
src/requests/insee.js
with
19 additions
and
10 deletions
__tests__/requests/insee.spec.js
+
13
−
4
View file @
9b8a491f
const
{
errors
}
=
require
(
'
cozy-konnector-libs
'
)
const
{
getInseeCode
}
=
require
(
'
../../src/requests/insee
'
)
describe
(
'
getInseeCode
'
,
()
=>
{
it
(
'
should return a valid insee code for Lyon 7
'
,
async
()
=>
{
expect
(
await
getInseeCode
(
69007
)).
toEqual
(
'
69387
'
)
})
it
(
'
should return null for a unexisting post code
'
,
async
()
=>
{
expect
(
await
getInseeCode
(
69069
)).
toEqual
(
null
)
it
(
'
should throw USER_ACTION_NEEDED for a unexisting post code
'
,
async
()
=>
{
try
{
await
getInseeCode
(
69069
)
}
catch
(
error
)
{
expect
(
error
).
toEqual
(
errors
.
USER_ACTION_NEEDED
)
}
})
it
(
'
should return null for post code 69290 when city is not provided
'
,
async
()
=>
{
expect
(
await
getInseeCode
(
69290
)).
toEqual
(
null
)
it
(
'
should throw USER_ACTION_NEEDED for post code 69290 when city is not provided
'
,
async
()
=>
{
try
{
await
getInseeCode
(
69290
)
}
catch
(
error
)
{
expect
(
error
).
toEqual
(
errors
.
USER_ACTION_NEEDED
)
}
})
it
(
'
should return Craponne insee code for post code 69290
'
,
async
()
=>
{
...
...
This diff is collapsed.
Click to expand it.
src/index.js
+
2
−
2
View file @
9b8a491f
...
...
@@ -97,6 +97,7 @@ async function start(fields, cozyParameters) {
await
commanderCollectePublicationMesures
()
await
updateBoConsent
()
}
else
{
//AlternateStart
await
getBoConsent
()
if
(
!
(
await
verifyUserIdentity
(
fields
)))
{
await
deleteBoConsent
()
...
...
@@ -116,14 +117,13 @@ async function start(fields, cozyParameters) {
* @param {string} apiAuthKey
* @param {string} loginUtilisateur
*/
async
function
verifyUserIdentity
(
export
async
function
verifyUserIdentity
(
fields
,
baseUrl
,
apiAuthKey
,
loginUtilisateur
)
{
const
inseeCode
=
await
getInseeCode
(
fields
.
postalCode
)
if
(
!
inseeCode
)
throw
errors
.
USER_ACTION_NEEDED
const
pdl
=
await
findUserPdl
(
`
${
baseUrl
}
/enedis_SDE_recherche-point/1.0`
,
...
...
This diff is collapsed.
Click to expand it.
src/requests/insee.js
+
4
−
4
View file @
9b8a491f
// @ts-check
const
{
default
:
axios
}
=
require
(
'
axios
'
)
const
{
log
}
=
require
(
'
cozy-konnector-libs
'
)
const
{
log
,
errors
}
=
require
(
'
cozy-konnector-libs
'
)
const
API_URL
=
'
https://apicarto.ign.fr/api/codes-postaux/communes
'
...
...
@@ -8,7 +8,7 @@ const API_URL = 'https://apicarto.ign.fr/api/codes-postaux/communes'
* Return inseeCode given a postalCode
* @param {string} postalCode
* @param {string} [city]
* @return {Promise<string
| null
>} inseeCode
* @return {Promise<string>} inseeCode
*/
async
function
getInseeCode
(
postalCode
,
city
)
{
try
{
...
...
@@ -18,7 +18,7 @@ async function getInseeCode(postalCode, city) {
if
(
response
.
data
.
length
===
1
)
{
return
response
.
data
[
0
].
codeCommune
}
else
{
if
(
!
city
)
return
null
if
(
!
city
)
throw
errors
.
USER_ACTION_NEEDED
const
filteredResponse
=
response
.
data
.
filter
(
town
=>
town
.
nomCommune
.
toLowerCase
()
===
city
.
toLowerCase
()
...
...
@@ -30,7 +30,7 @@ async function getInseeCode(postalCode, city) {
'
error
'
,
`Query getInseeCode failed for postalCode
${
postalCode
}
/
${
city
}
`
)
return
null
throw
errors
.
USER_ACTION_NEEDED
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment