refactor: refactor E2E auth helper and mail parsing logic

This commit is contained in:
ramvignesh-b
2026-04-28 19:54:22 +05:30
parent df73fb6b6a
commit f2a1abe7eb
3 changed files with 8 additions and 10 deletions
+1 -1
View File
@@ -185,7 +185,7 @@ test.describe("Letter Drafting (Real Backend)", () => {
await expect(page.getByText(/your letter is sealed/i)).toBeVisible({ await expect(page.getByText(/your letter is sealed/i)).toBeVisible({
timeout: 10000, timeout: 10000,
}); });
await page.getByRole("button", { name: /keep it/i }).click(); await page.getByRole("button", { name: /keep it to myself/i }).click();
// Open "Kept" section - search for the section with id='kept' and click its toggle button // Open "Kept" section - search for the section with id='kept' and click its toggle button
logger.info(">> [Drawer] Opening Kept section..."); logger.info(">> [Drawer] Opening Kept section...");
+5 -7
View File
@@ -14,13 +14,13 @@ const logger = pino({
/** /**
* Completes the full registration -> activation -> login cycle. * Completes the full registration -> activation -> login cycle.
*/ */
export async function registerAndLogin( async function registerAndLogin(
page: Page, page: Page,
email: string, email: string,
fullName: string, fullName: string,
password: string, password: string,
) { ) {
// 1. Registration // Register the User
logger.info(`[Auth] Registering user: ${email}`); logger.info(`[Auth] Registering user: ${email}`);
await page.goto("/onboard"); await page.goto("/onboard");
await page.getByLabel(/pen name/i).fill(fullName); await page.getByLabel(/pen name/i).fill(fullName);
@@ -31,7 +31,7 @@ export async function registerAndLogin(
await expect(page).toHaveURL(/\/verify-email/); await expect(page).toHaveURL(/\/verify-email/);
// 2. Activation via Mailpit // Get activation URL from Mailpit and activate user
logger.info(`[Auth] Polling Mailpit for activation email...`); logger.info(`[Auth] Polling Mailpit for activation email...`);
const activationLink = await MailpitHelper.getActivationLink(email); const activationLink = await MailpitHelper.getActivationLink(email);
@@ -40,11 +40,11 @@ export async function registerAndLogin(
await expect(page.getByText(/account activated/i)).toBeVisible(); await expect(page.getByText(/account activated/i)).toBeVisible();
await page.getByRole("button", { name: /start writing/i }).click(); await page.getByRole("button", { name: /start writing/i }).click();
// 3. Login // Dismiss the Welcom Modal and Perform Login
logger.info(`[Auth] Logging in...`); logger.info(`[Auth] Logging in...`);
await expect(page).toHaveURL(/\/login/); await expect(page).toHaveURL(/\/login/);
const welcomeButton = page.getByRole("button", { name: /i understand/i }); const welcomeButton = page.getByRole("button", { name: /I'll remember/i });
await welcomeButton.waitFor({ state: "visible", timeout: 10000 }); await welcomeButton.waitFor({ state: "visible", timeout: 10000 });
await welcomeButton.click(); await welcomeButton.click();
await expect(welcomeButton).toBeHidden(); await expect(welcomeButton).toBeHidden();
@@ -56,6 +56,4 @@ export async function registerAndLogin(
await expect(page).toHaveURL(/\/drawer/); await expect(page).toHaveURL(/\/drawer/);
logger.info(`[Auth] Successfully authenticated ${email}`); logger.info(`[Auth] Successfully authenticated ${email}`);
} }
// Maintain backward compatibility if needed, or update callers
export const AuthHelper = { registerAndLogin }; export const AuthHelper = { registerAndLogin };
+2 -2
View File
@@ -31,8 +31,8 @@ export const MailpitHelper = {
); );
const details = await detailRes.json(); const details = await detailRes.json();
const body = details.HTML || details.Text || ""; const body = details.Text || "";
const match = body.match(/https?:\/\/\S+activate\/\S+/); const match = body.match(/https?:\/\/\S*activate\S*/);
if (match) return match[0]; if (match) return match[0];
} }