merged tests
This commit is contained in:
parent
4be45f8f7c
commit
67ffe6a823
7 changed files with 212 additions and 599 deletions
|
|
@ -44,43 +44,39 @@ test.describe("Authentication Flow", () => {
|
|||
await clearAuth(page);
|
||||
});
|
||||
|
||||
test("redirects to login when not authenticated", async ({ page }) => {
|
||||
test("redirects to login when not authenticated and auth pages have correct UI", async ({
|
||||
page,
|
||||
}) => {
|
||||
// Test redirect
|
||||
await page.goto("/");
|
||||
await expect(page).toHaveURL("/login");
|
||||
});
|
||||
|
||||
test("login page has correct form elements", async ({ page }) => {
|
||||
// Test login page UI
|
||||
await page.goto("/login");
|
||||
await expect(page.locator("h1")).toHaveText("Welcome back");
|
||||
await expect(page.locator('input[type="email"]')).toBeVisible();
|
||||
await expect(page.locator('input[type="password"]')).toBeVisible();
|
||||
await expect(page.locator('button[type="submit"]')).toHaveText("Sign in");
|
||||
await expect(page.locator('a[href="/signup"]')).toBeVisible();
|
||||
});
|
||||
|
||||
test("signup page has invite code form", async ({ page }) => {
|
||||
await page.goto("/signup");
|
||||
// Test navigation to signup
|
||||
await page.click('a[href="/signup"]');
|
||||
await expect(page).toHaveURL("/signup");
|
||||
|
||||
// Test signup page UI
|
||||
await expect(page.locator("h1")).toHaveText("Join with Invite");
|
||||
await expect(page.locator("input#inviteCode")).toBeVisible();
|
||||
await expect(page.locator('button[type="submit"]')).toHaveText("Continue");
|
||||
await expect(page.locator('a[href="/login"]')).toBeVisible();
|
||||
});
|
||||
|
||||
test("can navigate from login to signup", async ({ page }) => {
|
||||
await page.goto("/login");
|
||||
await page.click('a[href="/signup"]');
|
||||
await expect(page).toHaveURL("/signup");
|
||||
});
|
||||
|
||||
test("can navigate from signup to login", async ({ page }) => {
|
||||
await page.goto("/signup");
|
||||
// Test navigation back to login
|
||||
await page.click('a[href="/login"]');
|
||||
await expect(page).toHaveURL("/login");
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Logged-in User Visiting Invite URL", () => {
|
||||
test("redirects to exchange when logged-in user visits direct invite URL", async ({
|
||||
test("redirects to exchange when logged-in user visits invite URL or signup page", async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
|
|
@ -105,26 +101,6 @@ test.describe("Logged-in User Visiting Invite URL", () => {
|
|||
// Visit invite URL while logged in - should redirect to exchange
|
||||
await page.goto(`/signup/${anotherInvite}`);
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
});
|
||||
|
||||
test("redirects to exchange when logged-in user visits signup page", async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
const email = uniqueEmail();
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
// Sign up and stay logged in
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", inviteCode);
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
await page.fill("input#email", email);
|
||||
await page.fill("input#password", "password123");
|
||||
await page.fill("input#confirmPassword", "password123");
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
|
||||
// Try to visit signup page while logged in - should redirect to exchange
|
||||
await page.goto("/signup");
|
||||
|
|
@ -194,37 +170,29 @@ test.describe("Signup with Invite", () => {
|
|||
await expect(page.getByText(/not found/i)).toBeVisible();
|
||||
});
|
||||
|
||||
test("shows error for password mismatch", async ({ page, request }) => {
|
||||
test("shows validation errors for password mismatch and short password", async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", inviteCode);
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
// Test password mismatch
|
||||
await page.fill("input#email", uniqueEmail());
|
||||
await page.fill("input#password", "password123");
|
||||
await page.fill("input#confirmPassword", "differentpassword");
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.getByText("Passwords do not match")).toBeVisible();
|
||||
});
|
||||
|
||||
test("shows error for short password", async ({ page, request }) => {
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", inviteCode);
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
// Test short password
|
||||
await page.fill("input#email", uniqueEmail());
|
||||
await page.fill("input#password", "short");
|
||||
await page.fill("input#confirmPassword", "short");
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.getByText("Password must be at least 6 characters")).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
|
@ -263,21 +231,19 @@ test.describe("Login", () => {
|
|||
await expect(page.getByRole("heading", { name: "Exchange Bitcoin" })).toBeVisible();
|
||||
});
|
||||
|
||||
test("shows error for wrong password", async ({ page }) => {
|
||||
test("shows error for wrong password and non-existent user", async ({ page }) => {
|
||||
// Test wrong password
|
||||
await page.goto("/login");
|
||||
await page.fill('input[type="email"]', testEmail);
|
||||
await page.fill('input[type="password"]', "wrongpassword");
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.getByText("Incorrect email or password")).toBeVisible();
|
||||
});
|
||||
|
||||
test("shows error for non-existent user", async ({ page }) => {
|
||||
// Test non-existent user
|
||||
await page.goto("/login");
|
||||
await page.fill('input[type="email"]', "nonexistent@example.com");
|
||||
await page.fill('input[type="password"]', "password123");
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.getByText("Incorrect email or password")).toBeVisible();
|
||||
});
|
||||
|
||||
|
|
@ -293,7 +259,7 @@ test.describe("Login", () => {
|
|||
});
|
||||
|
||||
test.describe("Logout", () => {
|
||||
test("can logout", async ({ page, request }) => {
|
||||
test("can logout and cannot access protected pages after logout", async ({ page, request }) => {
|
||||
const email = uniqueEmail();
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
|
|
@ -311,29 +277,6 @@ test.describe("Logout", () => {
|
|||
|
||||
// Click logout
|
||||
await page.click("text=Sign out");
|
||||
|
||||
// Should redirect to login
|
||||
await expect(page).toHaveURL("/login");
|
||||
});
|
||||
|
||||
test("cannot access home after logout", async ({ page, request }) => {
|
||||
const email = uniqueEmail();
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
// Sign up
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", inviteCode);
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
await page.fill("input#email", email);
|
||||
await page.fill("input#password", "password123");
|
||||
await page.fill("input#confirmPassword", "password123");
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
|
||||
// Logout
|
||||
await page.click("text=Sign out");
|
||||
await expect(page).toHaveURL("/login");
|
||||
|
||||
// Try to access exchange (protected page)
|
||||
|
|
@ -343,7 +286,10 @@ test.describe("Logout", () => {
|
|||
});
|
||||
|
||||
test.describe("Session Persistence", () => {
|
||||
test("session persists after page reload", async ({ page, request }) => {
|
||||
test("session persists after page reload and cookies are managed correctly", async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
const email = uniqueEmail();
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
|
|
@ -360,56 +306,23 @@ test.describe("Session Persistence", () => {
|
|||
await expect(page).toHaveURL("/exchange");
|
||||
await expect(page.getByRole("heading", { name: "Exchange Bitcoin" })).toBeVisible();
|
||||
|
||||
// Reload page
|
||||
await page.reload();
|
||||
|
||||
// Should still be logged in on exchange page
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
await expect(page.getByRole("heading", { name: "Exchange Bitcoin" })).toBeVisible();
|
||||
});
|
||||
|
||||
test("auth cookie is set after signup", async ({ page, request }) => {
|
||||
const email = uniqueEmail();
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", inviteCode);
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
await page.fill("input#email", email);
|
||||
await page.fill("input#password", "password123");
|
||||
await page.fill("input#confirmPassword", "password123");
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
|
||||
// Check cookies
|
||||
const cookies = await page.context().cookies();
|
||||
const authCookie = cookies.find((c) => c.name === "auth_token");
|
||||
// Check cookies are set after signup
|
||||
let cookies = await page.context().cookies();
|
||||
let authCookie = cookies.find((c) => c.name === "auth_token");
|
||||
expect(authCookie).toBeTruthy();
|
||||
expect(authCookie!.httpOnly).toBe(true);
|
||||
});
|
||||
|
||||
test("auth cookie is cleared on logout", async ({ page, request }) => {
|
||||
const email = uniqueEmail();
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", inviteCode);
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
await page.fill("input#email", email);
|
||||
await page.fill("input#password", "password123");
|
||||
await page.fill("input#confirmPassword", "password123");
|
||||
await page.click('button[type="submit"]');
|
||||
// Reload page - session should persist
|
||||
await page.reload();
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
await expect(page.getByRole("heading", { name: "Exchange Bitcoin" })).toBeVisible();
|
||||
|
||||
// Logout and verify cookie is cleared
|
||||
await page.click("text=Sign out");
|
||||
await expect(page).toHaveURL("/login");
|
||||
|
||||
const cookies = await page.context().cookies();
|
||||
const authCookie = cookies.find((c) => c.name === "auth_token");
|
||||
cookies = await page.context().cookies();
|
||||
authCookie = cookies.find((c) => c.name === "auth_token");
|
||||
expect(!authCookie || authCookie.value === "").toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue