mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
feat: implement end-to-end testing infrastructure with Playwright and automated containerized database setup
This commit is contained in:
@@ -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}`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user