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

throw new error

parent ead22cc2
No related branches found
No related tags found
1 merge request!36fix(insee): handle parsing partial cities
Pipeline #54137 passed
...@@ -50,6 +50,13 @@ describe('getInseeCode', () => { ...@@ -50,6 +50,13 @@ describe('getInseeCode', () => {
'69153' '69153'
) )
}) })
it('should throw USER_ACTION_NEEDED when city is not precise enough', async () => {
try {
await getInseeCode(26600, 'e')
} catch (error) {
expect(error).toEqual(errors.USER_ACTION_NEEDED)
}
})
}) })
it("should return insee code for: L'isle d'abeau", async () => { it("should return insee code for: L'isle d'abeau", async () => {
......
...@@ -27,6 +27,12 @@ async function getInseeCode(postalCode, city) { ...@@ -27,6 +27,12 @@ async function getInseeCode(postalCode, city) {
sanitizeCity(commune.nomCommune).includes(parsedCity) sanitizeCity(commune.nomCommune).includes(parsedCity)
) )
if (filteredResponse.length > 1) {
throw new Error(
'Input city is not precise enough, more than one city was found'
)
}
return filteredResponse[0].codeCommune return filteredResponse[0].codeCommune
} }
} catch (error) { } catch (error) {
......
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