40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
import "../setup.ts";
|
|
import { assertFalse, assertStringIncludes } from "@std/assert";
|
|
import { renderWelcomeEmail } from "../../mail/welcome.ts";
|
|
import { renderPasswordResetEmail } from "../../mail/password-reset.ts";
|
|
import { i18n } from "../../mail/i18n.ts";
|
|
|
|
Deno.test("renderWelcomeEmail: fills the built-in body, in both parts", () => {
|
|
const email = renderWelcomeEmail("newbie");
|
|
assertStringIncludes(email.subject, "Welcome to gerbeur");
|
|
assertStringIncludes(email.text, "Hi **newbie**");
|
|
assertFalse(email.text.includes("{{"));
|
|
assertStringIncludes(email.html, "newbie</b>");
|
|
assertStringIncludes(email.html, "Welcome to gerbeur!</h1>");
|
|
});
|
|
|
|
Deno.test("renderPasswordResetEmail: the button and the raw link carry the URL", () => {
|
|
const url = "http://gerbeur.test/reset-password?token=a.b&x=<y>";
|
|
const email = renderPasswordResetEmail("bob", url, 1);
|
|
assertStringIncludes(email.text, "# Reset your password");
|
|
assertStringIncludes(email.text, `[Reset password](${url})`);
|
|
assertStringIncludes(email.text, "for 1 hour");
|
|
assertStringIncludes(
|
|
email.html,
|
|
`href="http://gerbeur.test/reset-password?token=a.b&x=<y>"`,
|
|
);
|
|
assertFalse(email.html.includes("<y>"));
|
|
});
|
|
|
|
Deno.test("the emails speak the catalog's language", () => {
|
|
i18n.activate("fr");
|
|
try {
|
|
const email = renderPasswordResetEmail("bob", "http://g.test/r", 2);
|
|
assertStringIncludes(email.subject, "Réinitialisez votre mot de passe");
|
|
assertStringIncludes(email.text, "pendant 2 heures");
|
|
assertStringIncludes(renderWelcomeEmail("bob").text, "Bonjour **bob**");
|
|
} finally {
|
|
i18n.activate("en");
|
|
}
|
|
});
|