From 9157a06a6b6bca9eff6107781a5eabfe9814024c Mon Sep 17 00:00:00 2001 From: carolineBda Date: Tue, 12 Apr 2022 21:45:49 +0200 Subject: [PATCH] fix(data formatting): trim firstNames & lastNames --- .../__tests__/ds-parse-psychologists.spec.ts | 26 ++++++++++++------- .../parse-psychologists.ts | 3 ++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/services/__tests__/ds-parse-psychologists.spec.ts b/src/services/__tests__/ds-parse-psychologists.spec.ts index 5d75d917..199e3d96 100644 --- a/src/services/__tests__/ds-parse-psychologists.spec.ts +++ b/src/services/__tests__/ds-parse-psychologists.spec.ts @@ -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); }); @@ -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"} @@ -139,6 +143,7 @@ describe("parseDossierMetadata", () => { it.each` input | resultValue + ${" Laurence "} | ${"Laurence"} ${"Laurence"} | ${"Laurence"} ${"lauREnce"} | ${"Laurence"} ${"Marie-Christine"} | ${"Marie-Christine"} @@ -149,9 +154,9 @@ 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); } @@ -159,15 +164,16 @@ describe("parseDossierMetadata", () => { 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); } diff --git a/src/services/demarchesSimplifiees/parse-psychologists.ts b/src/services/demarchesSimplifiees/parse-psychologists.ts index 7550c62a..2b8df7fe 100644 --- a/src/services/demarchesSimplifiees/parse-psychologists.ts +++ b/src/services/demarchesSimplifiees/parse-psychologists.ts @@ -30,6 +30,7 @@ const capitalizeFirstLetter = (word) => function formatFirstName(string) { return string + .trim() .split(" ") .map((word) => word.split("-").map(capitalizeFirstLetter).join("-")) .join(" "); @@ -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, };