-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
2,267 additions
and
3,518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": ["eslint:recommended", "prettier"], | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"rules": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,45 @@ | ||
const test = require('ava') | ||
const {parseLocalizedField, parseErrorCode, getLabel, getErrorLevel} = require('../helpers') | ||
const test = require("ava"); | ||
const { | ||
parseLocalizedField, | ||
parseErrorCode, | ||
getLabel, | ||
getErrorLevel, | ||
} = require("../helpers"); | ||
|
||
test('parseLocalizedField', t => { | ||
t.is(parseLocalizedField('voie_nom'), undefined) | ||
t.deepEqual(parseLocalizedField('voie_nom_bre'), {schemaName: 'voie_nom', locale: 'bre'}) | ||
}) | ||
test("parseLocalizedField", (t) => { | ||
t.is(parseLocalizedField("voie_nom"), undefined); | ||
t.deepEqual(parseLocalizedField("voie_nom_bre"), { | ||
schemaName: "voie_nom", | ||
locale: "bre", | ||
}); | ||
}); | ||
|
||
test('parseErrorCode', t => { | ||
t.deepEqual(parseErrorCode('voie_nom.trop_long'), {schemaName: 'voie_nom', fieldError: 'trop_long'}) | ||
t.deepEqual(parseErrorCode('voie_nom_bre.trop_long'), {schemaName: 'voie_nom', locale: 'bre', fieldName: 'voie_nom_bre', fieldError: 'trop_long'}) | ||
}) | ||
test("parseErrorCode", (t) => { | ||
t.deepEqual(parseErrorCode("voie_nom.trop_long"), { | ||
schemaName: "voie_nom", | ||
fieldError: "trop_long", | ||
}); | ||
t.deepEqual(parseErrorCode("voie_nom_bre.trop_long"), { | ||
schemaName: "voie_nom", | ||
locale: "bre", | ||
fieldName: "voie_nom_bre", | ||
fieldError: "trop_long", | ||
}); | ||
}); | ||
|
||
test('getLabel', t => { | ||
t.is(getLabel('voie_nom.trop_court'), 'Le nom de la voie est trop court (3 caractères minimum)') | ||
t.is(getLabel('voie_nom_bre.trop_court'), 'Le nom de la voie est trop court (3 caractères minimum) [bre]') | ||
t.throws(() => getLabel('voie_nom_toto.trop_court')) | ||
}) | ||
test("getLabel", (t) => { | ||
t.is( | ||
getLabel("voie_nom.trop_court"), | ||
"Le nom de la voie est trop court (3 caractères minimum)", | ||
); | ||
t.is( | ||
getLabel("voie_nom_bre.trop_court"), | ||
"Le nom de la voie est trop court (3 caractères minimum) [bre]", | ||
); | ||
t.throws(() => getLabel("voie_nom_toto.trop_court")); | ||
}); | ||
|
||
test('getErrorLevel', t => { | ||
t.is(getErrorLevel('1.3-relax', 'voie_nom.trop_court'), 'E') | ||
t.is(getErrorLevel('1.3-relax', 'voie_nom_bre.trop_court'), 'W') | ||
}) | ||
test("getErrorLevel", (t) => { | ||
t.is(getErrorLevel("1.3-relax", "voie_nom.trop_court"), "E"); | ||
t.is(getErrorLevel("1.3-relax", "voie_nom_bre.trop_court"), "W"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
const communes = require('../minicog.json') | ||
const communes = require("../minicog.json"); | ||
|
||
const codesCommunesActuelles = new Set(communes.filter(c => !c.chefLieu).map(c => c.code)) | ||
const codesCommunesDeleguees = new Set(communes.filter(c => c.chefLieu).map(c => c.code)) | ||
const codesCommunesActuelles = new Set( | ||
communes.filter((c) => !c.chefLieu).map((c) => c.code), | ||
); | ||
const codesCommunesDeleguees = new Set( | ||
communes.filter((c) => c.chefLieu).map((c) => c.code), | ||
); | ||
|
||
const anciensCodesIndex = new Map() | ||
const anciensCodesIndex = new Map(); | ||
for (const commune of communes) { | ||
const anciensCodes = commune.anciensCodes || [] | ||
const anciensCodes = commune.anciensCodes || []; | ||
for (const ancienCode of anciensCodes) { | ||
anciensCodesIndex.set(ancienCode, commune) | ||
anciensCodesIndex.set(ancienCode, commune); | ||
} | ||
} | ||
|
||
function isCommune(codeCommune) { | ||
return isCommuneActuelle(codeCommune) || isCommuneAncienne(codeCommune) | ||
return isCommuneActuelle(codeCommune) || isCommuneAncienne(codeCommune); | ||
} | ||
|
||
function isCommuneAncienne(codeCommune) { | ||
return anciensCodesIndex.has(codeCommune) | ||
return anciensCodesIndex.has(codeCommune); | ||
} | ||
|
||
function isCommuneActuelle(codeCommune) { | ||
return codesCommunesActuelles.has(codeCommune) | ||
return codesCommunesActuelles.has(codeCommune); | ||
} | ||
|
||
function isCommuneDeleguee(codeCommune) { | ||
return codesCommunesDeleguees.has(codeCommune) | ||
return codesCommunesDeleguees.has(codeCommune); | ||
} | ||
|
||
function getCommuneActuelle(codeCommune) { | ||
return anciensCodesIndex.has(codeCommune) | ||
? anciensCodesIndex.get(codeCommune) | ||
: communes.find(c => c.code === codeCommune && !c.chefLieu) | ||
: communes.find((c) => c.code === codeCommune && !c.chefLieu); | ||
} | ||
|
||
module.exports = {isCommune, isCommuneAncienne, isCommuneActuelle, isCommuneDeleguee, getCommuneActuelle} | ||
module.exports = { | ||
isCommune, | ||
isCommuneAncienne, | ||
isCommuneActuelle, | ||
isCommuneDeleguee, | ||
getCommuneActuelle, | ||
}; |
Oops, something went wrong.