🧑‍💻 Use mailpit as dev/test smtp server (#1486)

This commit is contained in:
Luke Vella 2025-01-10 14:27:08 +00:00 committed by GitHub
parent b00b685bbd
commit 285860ec9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 124 additions and 242 deletions

View file

@ -1,33 +1,24 @@
import { expect, test } from "@playwright/test";
import { prisma } from "@rallly/database";
import { load } from "cheerio";
import smtpTester from "smtp-tester";
import { captureEmailHTML } from "./mailpit/mailpit";
const testUserEmail = "test@example.com";
let mailServer: smtpTester.MailServer;
/**
* Get the 6-digit code from the email
* @returns 6-digit code
*/
const getCode = async () => {
const { email } = await mailServer.captureOne(testUserEmail, {
wait: 5000,
});
const html = await captureEmailHTML(testUserEmail);
if (!email.html) {
throw new Error("Email doesn't contain HTML");
}
const $ = load(email.html);
const $ = load(html);
return $("#code").text().trim();
};
test.describe.serial(() => {
test.beforeAll(() => {
mailServer = smtpTester.init(4025);
});
test.afterAll(async () => {
try {
await prisma.user.deleteMany({
@ -38,8 +29,6 @@ test.describe.serial(() => {
} catch {
// User doesn't exist
}
mailServer.stop(() => {});
});
test.describe("new user", () => {
@ -110,15 +99,9 @@ test.describe.serial(() => {
await page.getByRole("button", { name: "Login with Email" }).click();
const { email } = await mailServer.captureOne(testUserEmail, {
wait: 5000,
});
const html = await captureEmailHTML(testUserEmail);
if (!email.html) {
throw new Error("Email doesn't contain HTML");
}
const $ = load(email.html);
const $ = load(html);
const magicLink = $("#magicLink").attr("href");