From c77b8f2e3d32d52effdde94d649ac5937c1c9c7e Mon Sep 17 00:00:00 2001
From: Bastien DUMONT <bdumont@grandlyon.com>
Date: Mon, 1 Aug 2022 15:44:52 +0200
Subject: [PATCH] fix: increase coverage

---
 __tests__/requests/insee.spec.js | 4 ++++
 src/requests/insee.js            | 6 ++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/__tests__/requests/insee.spec.js b/__tests__/requests/insee.spec.js
index bdcf8e3..8289cbd 100644
--- a/__tests__/requests/insee.spec.js
+++ b/__tests__/requests/insee.spec.js
@@ -8,6 +8,10 @@ describe('getInseeCode', () => {
     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 () => {
     expect(await getInseeCode(69290, 'CRAPONNE')).toEqual('69069')
   })
diff --git a/src/requests/insee.js b/src/requests/insee.js
index 6aaeeef..62a23d3 100644
--- a/src/requests/insee.js
+++ b/src/requests/insee.js
@@ -2,7 +2,7 @@
 const { default: axios } = require('axios')
 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
@@ -12,9 +12,7 @@ const API_URL = 'https://apicarto.ign.fr/api'
  */
 async function getInseeCode(postalCode, city) {
   try {
-    const response = await axios.get(
-      `${API_URL}/codes-postaux/communes/${postalCode}`
-    )
+    const response = await axios.get(`${API_URL}/${postalCode}`)
     log('info', `Query getInseeCode for postalCode ${postalCode} / ${city}`)
 
     if (response.data.length === 1) {
-- 
GitLab