more merging
This commit is contained in:
parent
67ffe6a823
commit
d6f955d2d9
5 changed files with 107 additions and 251 deletions
|
|
@ -75,107 +75,68 @@ test.describe("Authentication Flow", () => {
|
|||
});
|
||||
});
|
||||
|
||||
test.describe("Logged-in User Visiting Invite URL", () => {
|
||||
test("redirects to exchange when logged-in user visits invite URL or signup page", async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
const email = uniqueEmail();
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
// First sign up to create a user
|
||||
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");
|
||||
|
||||
// Create another invite
|
||||
const anotherInvite = await createInvite(request);
|
||||
|
||||
// Visit invite URL while logged in - should redirect to exchange
|
||||
await page.goto(`/signup/${anotherInvite}`);
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
|
||||
// Try to visit signup page while logged in - should redirect to exchange
|
||||
await page.goto("/signup");
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Signup with Invite", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await clearAuth(page);
|
||||
});
|
||||
|
||||
test("can create a new account with valid invite", async ({ page, request }) => {
|
||||
const email = uniqueEmail();
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
await page.goto("/signup");
|
||||
|
||||
// Step 1: Enter invite code
|
||||
await page.fill("input#inviteCode", inviteCode);
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Wait for form to transition to registration form
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
// Step 2: Fill registration form
|
||||
await page.fill("input#email", email);
|
||||
await page.fill("input#password", "password123");
|
||||
await page.fill("input#confirmPassword", "password123");
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Should redirect to exchange after signup (regular user home)
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
// Should see Exchange page heading
|
||||
await expect(page.getByRole("heading", { name: "Exchange Bitcoin" })).toBeVisible();
|
||||
});
|
||||
|
||||
test("signup with direct invite URL works", async ({ page, request }) => {
|
||||
const email = uniqueEmail();
|
||||
const inviteCode = await createInvite(request);
|
||||
|
||||
// Use direct URL with code
|
||||
await page.goto(`/signup/${inviteCode}`);
|
||||
|
||||
// Should redirect to signup with code in query and validate
|
||||
await page.waitForURL(/\/signup\?code=/);
|
||||
|
||||
// Wait for form to transition to registration form
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
// Fill registration form
|
||||
await page.fill("input#email", email);
|
||||
await page.fill("input#password", "password123");
|
||||
await page.fill("input#confirmPassword", "password123");
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Should redirect to exchange
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
});
|
||||
|
||||
test("shows error for invalid invite code", async ({ page }) => {
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", "fake-code-99");
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Should show error
|
||||
await expect(page.getByText(/not found/i)).toBeVisible();
|
||||
});
|
||||
|
||||
test("shows validation errors for password mismatch and short password", async ({
|
||||
test("can create account with valid invite via form and direct URL, and logged-in users are redirected", async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
const inviteCode = await createInvite(request);
|
||||
// Test signup via form
|
||||
const email1 = uniqueEmail();
|
||||
const inviteCode1 = await createInvite(request);
|
||||
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", inviteCode1);
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
await page.fill("input#email", email1);
|
||||
await page.fill("input#password", "password123");
|
||||
await page.fill("input#confirmPassword", "password123");
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
await expect(page.getByRole("heading", { name: "Exchange Bitcoin" })).toBeVisible();
|
||||
|
||||
// Test logged-in user visiting invite URL - should redirect to exchange
|
||||
const anotherInvite = await createInvite(request);
|
||||
await page.goto(`/signup/${anotherInvite}`);
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
|
||||
// Test logged-in user visiting signup page - should redirect to exchange
|
||||
await page.goto("/signup");
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
|
||||
// Test signup via direct URL (new session)
|
||||
await clearAuth(page);
|
||||
const email2 = uniqueEmail();
|
||||
const inviteCode2 = await createInvite(request);
|
||||
|
||||
await page.goto(`/signup/${inviteCode2}`);
|
||||
await page.waitForURL(/\/signup\?code=/);
|
||||
await expect(page.locator("h1")).toHaveText("Create account");
|
||||
|
||||
await page.fill("input#email", email2);
|
||||
await page.fill("input#password", "password123");
|
||||
await page.fill("input#confirmPassword", "password123");
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
});
|
||||
|
||||
test("shows errors for invalid invite code and password validation", async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
// Test invalid invite code
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", "fake-code-99");
|
||||
await page.click('button[type="submit"]');
|
||||
await expect(page.getByText(/not found/i)).toBeVisible();
|
||||
|
||||
// Test password validation with valid invite
|
||||
const inviteCode = await createInvite(request);
|
||||
await page.goto("/signup");
|
||||
await page.fill("input#inviteCode", inviteCode);
|
||||
await page.click('button[type="submit"]');
|
||||
|
|
@ -220,11 +181,15 @@ test.describe("Login", () => {
|
|||
await clearAuth(page);
|
||||
});
|
||||
|
||||
test("can login with valid credentials", async ({ page }) => {
|
||||
test("can login with valid credentials and shows loading state", async ({ page }) => {
|
||||
// Test loading state
|
||||
await page.goto("/login");
|
||||
await page.fill('input[type="email"]', testEmail);
|
||||
await page.fill('input[type="password"]', testPassword);
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
const submitPromise = page.click('button[type="submit"]');
|
||||
await expect(page.locator('button[type="submit"]')).toHaveText("Signing in...");
|
||||
await submitPromise;
|
||||
|
||||
// Regular user redirects to exchange
|
||||
await expect(page).toHaveURL("/exchange");
|
||||
|
|
@ -246,16 +211,6 @@ test.describe("Login", () => {
|
|||
await page.click('button[type="submit"]');
|
||||
await expect(page.getByText("Incorrect email or password")).toBeVisible();
|
||||
});
|
||||
|
||||
test("shows loading state while submitting", async ({ page }) => {
|
||||
await page.goto("/login");
|
||||
await page.fill('input[type="email"]', testEmail);
|
||||
await page.fill('input[type="password"]', testPassword);
|
||||
|
||||
const submitPromise = page.click('button[type="submit"]');
|
||||
await expect(page.locator('button[type="submit"]')).toHaveText("Signing in...");
|
||||
await submitPromise;
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Logout", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue