Skip to content

Commit

Permalink
fix(moderation): existing email response
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Jan 31, 2025
1 parent 682b16e commit c423fe0
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,65 @@
//

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(
<context.Provider
value={
{
domain: "🧨",
moderation: {
organization: { cached_libelle: "🦄" },
user: { email: "💌" },
},
query_suggest_same_user_emails,
} as Values
}
>
<Response />
</context.Provider>,
),
).toMatchSnapshot();
});

test("with three emails found", async () => {
const query_suggest_same_user_emails: SuggestSameUserEmailsHandler =
async () => ["🦄@unicorn.xyz", "🐷@unicorn.xyz", "🧧@unicorn.xyz"];

expect(
await render_md(
<context.Provider
value={
{
domain: "🧨",
moderation: {
organization: { cached_libelle: "🦄" },
user: { email: "💌" },
},
query_suggest_same_user_emails,
} as Values
}
>
<Response />
</context.Provider>,
),
).toMatchSnapshot();
});

test("with no emails found", async () => {
const query_suggest_same_user_emails: SuggestSameUserEmailsHandler =
async () => [];

expect(
await render_md(
<context.Provider
Expand All @@ -18,6 +70,7 @@ test("returns user with existing pc account", async () => {
organization: { cached_libelle: "🦄" },
user: { email: "💌" },
},
query_suggest_same_user_emails,
} as Values
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: { email, family_name },

Check failure on line 14 in packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.tsx

View workflow job for this annotation

GitHub Actions / e2e (moderations)

'email' is declared but its value is never read.

Check failure on line 14 in packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.tsx

View workflow job for this annotation

GitHub Actions / e2e (moderations)

'email' is declared but its value is never read.

Check failure on line 14 in packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.tsx

View workflow job for this annotation

GitHub Actions / e2e (organizations)

'email' is declared but its value is never read.

Check failure on line 14 in packages/~/moderations/ui/src/Actions/responses/user_with_existing_pc_account.tsx

View workflow job for this annotation

GitHub Actions / e2e (organizations)

'email' is declared but its value is never read.
},
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.
Expand All @@ -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- ")}
`;
}

0 comments on commit c423fe0

Please sign in to comment.