From e38b80221cef17f7229a29ce16f3fd3356c802d1 Mon Sep 17 00:00:00 2001
From: Bastien DUMONT <bdumont@grandlyon.com>
Date: Tue, 24 Jan 2023 17:11:24 +0100
Subject: [PATCH] fix(insee): cleaner regexp

---
 __tests__/requests/insee.spec.js | 9 +++++++++
 src/requests/insee.js            | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/__tests__/requests/insee.spec.js b/__tests__/requests/insee.spec.js
index 5eff0f2..1519957 100644
--- a/__tests__/requests/insee.spec.js
+++ b/__tests__/requests/insee.spec.js
@@ -76,6 +76,15 @@ describe('getInseeCode', () => {
       it('should return insee code for: Puget-Rostang', async () => {
         expect(await getInseeCode('06260', 'Puget-Rostang')).toEqual('06098')
       })
+      it('should return insee code for: Rostrenen', async () => {
+        expect(await getInseeCode(22110, 'Rostrenen')).toEqual('22266')
+      })
+      it('should return insee code for: Kergrist Moëlou', async () => {
+        expect(await getInseeCode(22110, 'Kergrist Moëlou')).toEqual('22087')
+      })
+      it('should return insee code for: castets', async () => {
+        expect(await getInseeCode(40260, 'castets')).toEqual('40075')
+      })
       it('should return insee code for: St léger', async () => {
         expect(await getInseeCode('06260', 'St léger')).toEqual('06124')
       })
diff --git a/src/requests/insee.js b/src/requests/insee.js
index 932be38..a0a3dda 100644
--- a/src/requests/insee.js
+++ b/src/requests/insee.js
@@ -45,7 +45,7 @@ async function getInseeCode(postalCode, city) {
 function sanitizeCity(city) {
   return city
     .toLowerCase()
-    .replace(/st/g, 'saint')
+    .replace(/\bst\b/i, 'saint')
     .replace(/[âêîôûäëïü-\sʼ'éèç]/g, match => REPLACE_CHARS[match])
     .trim()
 }
-- 
GitLab