mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-28 16:26:24 +02:00
🧑💻 Use mailpit as dev/test smtp server (#1486)
This commit is contained in:
parent
b00b685bbd
commit
285860ec9e
12 changed files with 124 additions and 242 deletions
|
@ -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");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue