mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
refactor: consolidate auth logic into helper, add letter E2E tests,
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { MailpitHelper } from "./utils/mailpit";
|
||||
import { AuthHelper } from "./utils/auth";
|
||||
|
||||
test.describe("Authentication Flow (Real Backend)", () => {
|
||||
// Use unique email for each run to avoid conflicts in shared DB
|
||||
@@ -11,61 +11,8 @@ test.describe("Authentication Flow (Real Backend)", () => {
|
||||
test("should register, activate via email, and login successfully", async ({
|
||||
page,
|
||||
}) => {
|
||||
// 1. Registration
|
||||
console.log(">>--- Navigating to Onboard Page...");
|
||||
await page.goto("/onboard");
|
||||
|
||||
// Fill the registration form
|
||||
await page.getByLabel(/full name/i).fill(fullName);
|
||||
await page.getByLabel("Email", { exact: true }).fill(email);
|
||||
await page.getByLabel("Password", { exact: true }).fill(password);
|
||||
await page.getByLabel(/confirm password/i).fill(password);
|
||||
|
||||
// Submit Registration
|
||||
await page.getByRole("button", { name: /^register$/i }).click();
|
||||
|
||||
// Verify redirect to check-email page
|
||||
console.log(">>--- Verifying redirect to check-email...");
|
||||
await expect(page).toHaveURL(/\/verify-email/);
|
||||
await expect(page.getByText(/check your email/i)).toBeVisible();
|
||||
|
||||
// 2. Activation via Mailpit
|
||||
console.log(`>>--- Polling Mailpit for activation email for ${email}...`);
|
||||
const activationLink = await MailpitHelper.getActivationLink(email);
|
||||
console.log(`>>--- Found activation link: ${activationLink}`);
|
||||
|
||||
// Navigate to the activation link (this should activate and redirect to login)
|
||||
await page.goto(activationLink);
|
||||
|
||||
// Verify activation success
|
||||
console.log(">>--- Verifying activation success...");
|
||||
await expect(page.getByText(/account activated/i)).toBeVisible();
|
||||
|
||||
// Click "Start Writing" to go to Login
|
||||
await page.getByRole("button", { name: /start writing/i }).click();
|
||||
|
||||
// Verify redirect to login
|
||||
console.log(">>--- Verifying redirect to login...");
|
||||
await expect(page).toHaveURL(/\/login/);
|
||||
|
||||
// 3. Login
|
||||
console.log(">>--- Navigated to Login. Handling Welcome Modal...");
|
||||
const welcomeButton = page.getByRole("button", { name: /i understand/i });
|
||||
await welcomeButton.waitFor({ state: "visible", timeout: 10000 });
|
||||
await welcomeButton.click();
|
||||
await expect(welcomeButton).toBeHidden();
|
||||
|
||||
console.log(">>--- Performing Login...");
|
||||
const loginButton = page.getByRole("button", { name: /sign in/i });
|
||||
await expect(loginButton).toBeVisible();
|
||||
|
||||
await page.getByLabel("Email", { exact: true }).fill(email);
|
||||
await page.getByLabel("Password", { exact: true }).fill(password);
|
||||
await loginButton.click();
|
||||
|
||||
// 4. Verify Success - Redirect to Drawer
|
||||
console.log(">>--- Verifying redirect to Drawer...");
|
||||
await expect(page).toHaveURL(/\/drawer/);
|
||||
// Perform full auth cycle using helper
|
||||
await AuthHelper.registerAndLogin(page, email, fullName, password);
|
||||
|
||||
// 5. Verify Zero-Knowledge Artifacts in IndexedDB
|
||||
console.log(">>--- Verifying MasterKey in IndexedDB...");
|
||||
|
||||
Reference in New Issue
Block a user