Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(moderation): existing email response #768

Merged
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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(
<context.Provider
value={
{
domain: "🧨",
moderation: {
organization: { cached_libelle: "🦄" },
user: { email: "💌" },
},
query_suggest_same_user_emails,
} as Values
}
>
<Response />
</context.Provider>,
),
).toMatchInlineSnapshot(`
"Bonjour,

Nous avons bien reçu votre demande de rattachement à l&#39;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(
<context.Provider
Expand All @@ -18,13 +60,70 @@ test("returns user with existing pc account", async () => {
organization: { cached_libelle: "🦄" },
user: { email: "💌" },
},
query_suggest_same_user_emails,
} as Values
}
>
<Response />
</context.Provider>,
),
).toMatchSnapshot();
).toMatchInlineSnapshot(`
"Bonjour,

Nous avons bien reçu votre demande de rattachement à l&#39;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(
<context.Provider
value={
{
domain: "🧨",
moderation: {
organization: { cached_libelle: "🦄" },
user: { email: "💌" },
},
query_suggest_same_user_emails,
} as Values
}
>
<Response />
</context.Provider>,
),
).toMatchInlineSnapshot(`
"Bonjour,

Nous avons bien reçu votre demande de rattachement à l&#39;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() {
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: { 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.
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- ")}
`;
}