feat: implement end-to-end testing infrastructure with Playwright and automated containerized database setup

This commit is contained in:
ramvignesh-b
2026-04-15 01:00:51 +05:30
parent 0fb31b9f0b
commit c259d98acb
11 changed files with 389 additions and 7 deletions
+46
View File
@@ -0,0 +1,46 @@
import { request } from "@playwright/test";
export interface MailpitMessage {
ID: string;
Subject: string;
Snippet: string;
To: { Address: string }[];
}
const MAILPIT_API_URL = process.env.MAILPIT_API_URL;
export const MailpitHelper = {
getActivationLink: async (
email: string,
timeout = 10000,
): Promise<string> => {
const startTime = Date.now();
const requestContext = await request.newContext();
while (Date.now() - startTime < timeout) {
// Search specifically for the recipient to reduce data transfer
const response = await requestContext.get(`${MAILPIT_API_URL}/search`, {
params: { query: `to:${email}`, limit: 1 },
});
if (response.ok()) {
const data = await response.json();
if (data.messages?.length > 0) {
const msgId = data.messages[0].ID;
const detailRes = await requestContext.get(
`${MAILPIT_API_URL}/message/${msgId}`,
);
const details = await detailRes.json();
const body = details.HTML || details.Text || "";
const match = body.match(/https?:\/\/\S+activate\/\S+/);
if (match) return match[0];
}
}
await new Promise((r) => setTimeout(r, 1000));
}
throw new Error(`Timeout: Could not find activation link for ${email}`);
},
};