From 486412aa7eab9b2179c319edc57f93a587f90c9d Mon Sep 17 00:00:00 2001 From: Douglas DUTEIL Date: Fri, 31 Jan 2025 10:11:39 +0100 Subject: [PATCH] fix(moderation): existing email response --- ...ser_with_existing_pc_account.test.tsx.snap | 41 ++++++- .../user_with_existing_pc_account.test.tsx | 103 +++++++++++++++++- .../user_with_existing_pc_account.tsx | 35 +++++- 3 files changed, 171 insertions(+), 8 deletions(-) diff --git a/packages/~/moderations/ui/src/Actions/responses/__snapshots__/user_with_existing_pc_account.test.tsx.snap b/packages/~/moderations/ui/src/Actions/responses/__snapshots__/user_with_existing_pc_account.test.tsx.snap index 1c8b025f..4fdd84cc 100644 --- a/packages/~/moderations/ui/src/Actions/responses/__snapshots__/user_with_existing_pc_account.test.tsx.snap +++ b/packages/~/moderations/ui/src/Actions/responses/__snapshots__/user_with_existing_pc_account.test.tsx.snap @@ -1,11 +1,48 @@ // Bun Snapshot v1, https://goo.gl/fbAQLP -exports[`returns user with existing pc account 1`] = ` +exports[`with one email found 1`] = ` "Bonjour, Nous avons bien reçu votre demande de rattachement à l'organisation « 🦄 » sur ProConnect (anciennement : AgentConnect, MonComptePro). -Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : « 💌 ». +Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : « 🦄@unicorn.xyz ». + +Merci de bien vouloir vous connecter avec le compte déjà existant. + +Votre adresse e-mail associée à un nom de domaine gratuit tel que « 🧨 » ne sera pas autorisée. + +Bien cordialement, +L’équipe ProConnect. +" +`; + +exports[`with three emails found 1`] = ` +"Bonjour, + +Nous avons bien reçu votre demande de rattachement à l'organisation « 🦄 » sur ProConnect (anciennement : AgentConnect, MonComptePro). + +Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : + +- 🦄@unicorn.xyz +- 🐷@unicorn.xyz +- 🧧@unicorn.xyz + +Merci de bien vouloir vous connecter avec le compte déjà existant. + +Votre adresse e-mail associée à un nom de domaine gratuit tel que « 🧨 » ne sera pas autorisée. + +Bien cordialement, +L’équipe ProConnect. +" +`; + +exports[`with no emails found 1`] = ` +"Bonjour, + +Nous avons bien reçu votre demande de rattachement à l'organisation « 🦄 » sur ProConnect (anciennement : AgentConnect, MonComptePro). + +Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : « ???? ». + Merci de bien vouloir vous connecter avec le compte déjà existant. Votre adresse e-mail associée à un nom de domaine gratuit tel que « 🧨 » ne sera pas autorisée. diff --git a/packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.test.tsx b/packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.test.tsx index 7d734952..b33343ca 100644 --- a/packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.test.tsx +++ b/packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.test.tsx @@ -1,13 +1,55 @@ // import { render_md } from "@~/app.ui/testing"; +import type { SuggestSameUserEmailsHandler } from "@~/users.lib/usecase/SuggestSameUserEmails"; import { expect, test } from "bun:test"; import { context, type Values } from "../context"; import user_with_existing_pc_account from "./user_with_existing_pc_account"; // -test("returns user with existing pc account", async () => { +test("with one email found", async () => { + const query_suggest_same_user_emails: SuggestSameUserEmailsHandler = + async () => ["🦄@unicorn.xyz"]; + + expect( + await render_md( + + + , + ), + ).toMatchInlineSnapshot(` + "Bonjour, + + Nous avons bien reçu votre demande de rattachement à l'organisation « 🦄 » sur ProConnect (anciennement : AgentConnect, MonComptePro). + + Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : « 🦄@unicorn.xyz ». + + Merci de bien vouloir vous connecter avec le compte déjà existant. + + Votre adresse e-mail associée à un nom de domaine gratuit tel que « 🧨 » ne sera pas autorisée. + + Bien cordialement, + L’équipe ProConnect. + " + `); +}); + +test("with three emails found", async () => { + const query_suggest_same_user_emails: SuggestSameUserEmailsHandler = + async () => ["🦄@unicorn.xyz", "🐷@unicorn.xyz", "🧧@unicorn.xyz"]; + expect( await render_md( { organization: { cached_libelle: "🦄" }, user: { email: "💌" }, }, + query_suggest_same_user_emails, } as Values } > , ), - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(` + "Bonjour, + + Nous avons bien reçu votre demande de rattachement à l'organisation « 🦄 » sur ProConnect (anciennement : AgentConnect, MonComptePro). + + Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : + + - 🦄@unicorn.xyz + - 🐷@unicorn.xyz + - 🧧@unicorn.xyz + + Merci de bien vouloir vous connecter avec le compte déjà existant. + + Votre adresse e-mail associée à un nom de domaine gratuit tel que « 🧨 » ne sera pas autorisée. + + Bien cordialement, + L’équipe ProConnect. + " + `); +}); + +test("with no emails found", async () => { + const query_suggest_same_user_emails: SuggestSameUserEmailsHandler = + async () => []; + + expect( + await render_md( + + + , + ), + ).toMatchInlineSnapshot(` + "Bonjour, + + Nous avons bien reçu votre demande de rattachement à l'organisation « 🦄 » sur ProConnect (anciennement : AgentConnect, MonComptePro). + + Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : « ???? ». + + Merci de bien vouloir vous connecter avec le compte déjà existant. + + Votre adresse e-mail associée à un nom de domaine gratuit tel que « 🧨 » ne sera pas autorisée. + + Bien cordialement, + L’équipe ProConnect. + " + `); }); function Response() { diff --git a/packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.tsx b/packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.tsx index dd44f29c..b2166dab 100644 --- a/packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.tsx +++ b/packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.tsx @@ -6,22 +6,30 @@ import { context } from "../context"; export const label = "Utilisateur possédant déjà un compte ProConnect"; -export default function template() { +export default async function template() { const { domain, moderation: { - organization: { cached_libelle: organization_name }, - user: { email }, + organization: { cached_libelle: organization_name, id: organization_id }, + user: { family_name }, }, + query_suggest_same_user_emails, } = useContext(context); + const members_email = await query_suggest_same_user_emails({ + family_name: family_name ?? "", + organization_id: organization_id, + }); + + const possible_emails = list_possible_emails(members_email); return dedent` Bonjour, Nous avons bien reçu votre demande de rattachement à l'organisation « ${organization_name} » sur ProConnect (anciennement : AgentConnect, MonComptePro). - Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : « ${email} ». + ${possible_emails} + Merci de bien vouloir vous connecter avec le compte déjà existant. Votre adresse e-mail associée à un nom de domaine gratuit tel que « ${domain} » ne sera pas autorisée. @@ -30,3 +38,22 @@ export default function template() { L’équipe ProConnect. `; } + +function list_possible_emails(emails: string[]) { + if (emails.length === 0) { + return dedent` + Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : « ???? ». + `; + } + + if (emails.length === 1) { + return dedent` + Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : « ${emails[0]} ». + `; + } + + return dedent` + Vous possédez déjà un compte ProConnect associé à l’adresse e-mail professionnelle : + - ${emails.join("\n- ")} + `; +}