49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
|
|
const API = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000/api/v1";
|
|
|
|
test.describe("Authentication flow", () => {
|
|
test("route guard redirects unauthenticated /account to /login", async ({ page }) => {
|
|
await page.goto("/account");
|
|
await expect(page).toHaveURL(/\/login/);
|
|
});
|
|
|
|
test("register -> auto login -> reach /account", async ({ page }) => {
|
|
const email = `e2e_${Date.now()}@example.com`;
|
|
const password = "SuperSecret123!";
|
|
|
|
await page.goto("/register");
|
|
await page.getByPlaceholder("you@example.com").fill(email);
|
|
await page.getByLabel(/رمز عبور|Password/).first().fill(password);
|
|
await page.getByLabel(/تکرار رمز عبور|Confirm password/).fill(password);
|
|
await page.getByRole("button", { name: /ثبتنام|Sign Up/ }).click();
|
|
|
|
await expect(page).toHaveURL(/\/account/, { timeout: 15000 });
|
|
await expect(page.getByText(email)).toBeVisible();
|
|
});
|
|
|
|
test("login with existing credentials reaches /account", async ({ page }) => {
|
|
const email = `e2e_login_${Date.now()}@example.com`;
|
|
const password = "SuperSecret123!";
|
|
|
|
// Register first via the API to guarantee a known account.
|
|
await page.request.post(`${API}/auth/register/`, {
|
|
data: {
|
|
email,
|
|
password,
|
|
password_confirm: password,
|
|
full_name: "E2E User",
|
|
},
|
|
headers: { "Content-Type": "application/json" },
|
|
});
|
|
|
|
await page.goto("/login");
|
|
await page.getByPlaceholder("you@example.com").fill(email);
|
|
await page.getByLabel(/رمز عبور|Password/).first().fill(password);
|
|
await page.getByRole("button", { name: /ادامه|Continue|ورود|Sign In/ }).click();
|
|
|
|
await expect(page).toHaveURL(/\/account/, { timeout: 15000 });
|
|
await expect(page.getByText(email)).toBeVisible();
|
|
});
|
|
});
|