Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

fix(data formatting): trim firstNames & lastNames #151

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/services/__tests__/ds-parse-psychologists.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ describe("parseDossierMetadata", () => {
${"valid@email.com"} | ${"valid@email.com"}
${"vaLiD@EMAIL.com"} | ${"valid@email.com"}
`("should parse email champs for $input", async ({ input, resultValue }) => {
const dossierWithWebsite = createDossier();
dossierWithWebsite.champs.push({
const dossierWithEmail = createDossier();
dossierWithEmail.champs.push({
id: "Q2hhbXAtMTYwMTE4Ng==",
label: "Votre email",
stringValue: input,
});
const result = await parseDossierMetadata(dossierWithWebsite);
const result = await parseDossierMetadata(dossierWithEmail);

expect(result.email).toEqual(resultValue);
});
Expand All @@ -79,6 +79,10 @@ describe("parseDossierMetadata", () => {
${null} | ${undefined}
${"non"} | ${undefined}
${"doctolib"} | ${undefined}
${"doctolib."} | ${undefined}
${"doctolib. com"} | ${undefined}
${"doctolib/com"} | ${undefined}
${"shouldBeValid.com"} | ${undefined}
${"https://valid.com"} | ${"https://valid.com"}
${"http://valid.com"} | ${"http://valid.com"}
${"http://VALID.com"} | ${"http://valid.com"}
Expand Down Expand Up @@ -139,6 +143,7 @@ describe("parseDossierMetadata", () => {

it.each`
input | resultValue
${" Laurence "} | ${"Laurence"}
${"Laurence"} | ${"Laurence"}
${"lauREnce"} | ${"Laurence"}
${"Marie-Christine"} | ${"Marie-Christine"}
Expand All @@ -149,25 +154,26 @@ describe("parseDossierMetadata", () => {
`(
"should format firsName champs for $input",
async ({ input, resultValue }) => {
const dossierWithLangue = createDossier();
dossierWithLangue.demandeur.prenom = input;
const result = await parseDossierMetadata(dossierWithLangue);
const dossier = createDossier();
dossier.demandeur.prenom = input;
const result = await parseDossierMetadata(dossier);

expect(result.firstName).toEqual(resultValue);
}
);

it.each`
input | resultValue
${" Dupont "} | ${"DUPONT"}
${"Dupont"} | ${"DUPONT"}
${"DuPOnt"} | ${"DUPONT"}
${"DuPOnt de la particule"} | ${"DUPONT DE LA PARTICULE"}
`(
"should format firsName champs for $input",
"should format lastName champs for $input",
async ({ input, resultValue }) => {
const dossierWithLangue = createDossier();
dossierWithLangue.demandeur.nom = input;
const result = await parseDossierMetadata(dossierWithLangue);
const dossier = createDossier();
dossier.demandeur.nom = input;
const result = await parseDossierMetadata(dossier);

expect(result.lastName).toEqual(resultValue);
}
Expand Down
3 changes: 2 additions & 1 deletion src/services/demarchesSimplifiees/parse-psychologists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const capitalizeFirstLetter = (word) =>

function formatFirstName(string) {
return string
.trim()
.split(" ")
.map((word) => word.split("-").map(capitalizeFirstLetter).join("-"))
.join(" ");
Expand Down Expand Up @@ -90,7 +91,7 @@ export const parseDossierMetadata = async (
firstName: formatFirstName(dossier.demandeur.prenom),
id: dossier.number,
instructorId: dossier.groupeInstructeur.id,
lastName: dossier.demandeur.nom.toUpperCase(),
lastName: dossier.demandeur.nom.toUpperCase().trim(),
state: dossier.state,
};

Expand Down