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

fix: handle communes with "St"

parent 58938747
Branches
Tags
1 merge request!30Resolve "[SGE] Traiter les communes avec ST"
Pipeline #50939 passed
...@@ -42,6 +42,45 @@ describe('getInseeCode', () => { ...@@ -42,6 +42,45 @@ describe('getInseeCode', () => {
expect(await getInseeCode(38080, "L'isle d'abeau")).toEqual('38193') expect(await getInseeCode(38080, "L'isle d'abeau")).toEqual('38193')
}) })
describe('should handle communes with "Saint" or "St"', () => {
it("should return insee code for: Saint Romain au Mont d'Or", async () => {
expect(await getInseeCode(69270, "Saint Romain au Mont d'Or")).toEqual(
'69233'
)
})
it("should return insee code for: St Romain au Mont d'Or", async () => {
expect(await getInseeCode(69270, "St Romain au Mont d'Or")).toEqual(
'69233'
)
})
it('should return insee code for: Saint Genis les Ollières', async () => {
expect(await getInseeCode(69290, 'Saint Genis les Ollières')).toEqual(
'69205'
)
})
it('should return insee code for: St Genis les Ollières', async () => {
expect(await getInseeCode(69290, 'St Genis les Ollières')).toEqual(
'69205'
)
})
it('should return insee code for: St Priest', async () => {
// 69800 has only a single commune
expect(await getInseeCode(69800, 'st priest')).toEqual('69290')
})
// No regression test with replacement of st
it('should return insee code for: Puget-Rostang', async () => {
expect(await getInseeCode('06260', 'Puget-Rostang')).toEqual('06098')
})
it('should return insee code for: St léger', async () => {
expect(await getInseeCode('06260', 'St léger')).toEqual('06124')
})
})
describe("should return correct insee code for Couzon-au-Mont-d'Or", () => { describe("should return correct insee code for Couzon-au-Mont-d'Or", () => {
it("should return insee code for: Couzon au mont d'or", async () => { it("should return insee code for: Couzon au mont d'or", async () => {
expect(await getInseeCode(69270, "Couzon au mont d'or")).toEqual( expect(await getInseeCode(69270, "Couzon au mont d'or")).toEqual(
... ...
......
...@@ -26,6 +26,7 @@ async function getInseeCode(postalCode, city) { ...@@ -26,6 +26,7 @@ async function getInseeCode(postalCode, city) {
const filteredResponse = response.data.filter( const filteredResponse = response.data.filter(
town => sanitizeCity(town.nomCommune) === parsedCity town => sanitizeCity(town.nomCommune) === parsedCity
) )
return filteredResponse[0].codeCommune return filteredResponse[0].codeCommune
} }
} catch (error) { } catch (error) {
...@@ -44,6 +45,7 @@ async function getInseeCode(postalCode, city) { ...@@ -44,6 +45,7 @@ async function getInseeCode(postalCode, city) {
function sanitizeCity(city) { function sanitizeCity(city) {
return city return city
.toLowerCase() .toLowerCase()
.replace(/st/g, 'saint')
.replace(/[âêîôûäëïü-\sʼ'éèç]/g, match => REPLACE_CHARS[match]) .replace(/[âêîôûäëïü-\sʼ'éèç]/g, match => REPLACE_CHARS[match])
.trim() .trim()
} }
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment