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

fix: increase coverage

parent abb720e9
No related branches found
No related tags found
1 merge request!9Feat/insee code
...@@ -8,6 +8,10 @@ describe('getInseeCode', () => { ...@@ -8,6 +8,10 @@ describe('getInseeCode', () => {
expect(await getInseeCode(69013)).toEqual(null) expect(await getInseeCode(69013)).toEqual(null)
}) })
it('should return null for post code 69290 when city is not provided', async () => {
expect(await getInseeCode(69290)).toEqual(null)
})
it('should return Craponne insee code for post code 69290', async () => { it('should return Craponne insee code for post code 69290', async () => {
expect(await getInseeCode(69290, 'CRAPONNE')).toEqual('69069') expect(await getInseeCode(69290, 'CRAPONNE')).toEqual('69069')
}) })
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
const { default: axios } = require('axios') const { default: axios } = require('axios')
const { log } = require('cozy-konnector-libs') const { log } = require('cozy-konnector-libs')
const API_URL = 'https://apicarto.ign.fr/api' const API_URL = 'https://apicarto.ign.fr/api/codes-postaux/communes'
/** /**
* Return inseeCode given a postalCode * Return inseeCode given a postalCode
...@@ -12,9 +12,7 @@ const API_URL = 'https://apicarto.ign.fr/api' ...@@ -12,9 +12,7 @@ const API_URL = 'https://apicarto.ign.fr/api'
*/ */
async function getInseeCode(postalCode, city) { async function getInseeCode(postalCode, city) {
try { try {
const response = await axios.get( const response = await axios.get(`${API_URL}/${postalCode}`)
`${API_URL}/codes-postaux/communes/${postalCode}`
)
log('info', `Query getInseeCode for postalCode ${postalCode} / ${city}`) log('info', `Query getInseeCode for postalCode ${postalCode} / ${city}`)
if (response.data.length === 1) { if (response.data.length === 1) {
......
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