Some checks failed
Validation applicative / TypeScript, tests et build (push) Failing after 2m22s
52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
import { readFileSync } from "node:fs";
|
||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||
import { replaceEmailVariables } from "../emailTemplateUtils";
|
||
|
||
const getEmailTemplateByType = vi.fn();
|
||
|
||
vi.mock("../db", () => ({ getEmailTemplateByType }));
|
||
|
||
const databaseHelpers = readFileSync(new URL("../db.ts", import.meta.url), "utf8");
|
||
const emailService = readFileSync(new URL("../emailService.ts", import.meta.url), "utf8");
|
||
|
||
describe("modèle d’e-mail de réinitialisation", () => {
|
||
it("conserve un lien unique sous forme de variable dans le modèle par défaut", () => {
|
||
expect(databaseHelpers).toContain('type: "reset_password"');
|
||
expect(databaseHelpers).toContain("{{lienReinitialisation}}");
|
||
expect(emailService).toContain("lienReinitialisation: params.resetLink");
|
||
});
|
||
|
||
it("substitue le lien de réinitialisation dans le contenu du modèle", () => {
|
||
const link = "https://formations.recette.santinova-soft.org/reset-password?token=abc123";
|
||
const result = replaceEmailVariables(
|
||
'<a href="{{lienReinitialisation}}">Réinitialiser</a>',
|
||
{ lienReinitialisation: link },
|
||
);
|
||
|
||
expect(result).toContain(`href="${link}"`);
|
||
expect(result).not.toContain("{{lienReinitialisation}}");
|
||
});
|
||
|
||
it("ajoute le contenu de secours lorsque le modèle existant ne contient pas de lien", async () => {
|
||
getEmailTemplateByType.mockResolvedValue({
|
||
type: "reset_password",
|
||
titre: "Réinitialisation",
|
||
bodyContent: "<p>Réinitialisation mot de passe</p>",
|
||
couleurPrincipale: "#283581",
|
||
couleurSecondaire: "#0578BE",
|
||
piedDePage: null,
|
||
});
|
||
|
||
const { generateEmailFromTemplate } = await import("../emailTemplateGenerator");
|
||
const resetLink = "https://formations.recette.santinova-soft.org/reset-password?token=abc123";
|
||
const html = await generateEmailFromTemplate(
|
||
"reset_password",
|
||
`<a href="${resetLink}">Réinitialiser</a>`,
|
||
{ lienReinitialisation: resetLink },
|
||
);
|
||
|
||
expect(html).toContain("Réinitialisation mot de passe");
|
||
expect(html).toContain(`href="${resetLink}"`);
|
||
});
|
||
});
|