Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history

auth.spec.ts

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

auth.spec.tsBlame167 lines · 1 contributor
a014defClaude1/**
2 * E2E — Auth flows
3 *
4 * Covers: registration, login, logout, wrong password.
5 * Each test creates its own isolated user to avoid cross-test state.
6 */
7
8import { test, expect } from "@playwright/test";
9import { uid, TEST_PASSWORD } from "./fixtures";
10
11// ---------------------------------------------------------------------------
12// Register
13// ---------------------------------------------------------------------------
14
15test.describe("Registration", () => {
16 test("happy path — new user registers and lands on dashboard", async ({ page }) => {
17 const username = uid("reg");
18 const email = `${username}@test.example`;
19
20 await page.goto("/register");
21 await page.fill('input[name="username"]', username);
22 await page.fill('input[name="email"]', email);
23 await page.fill('input[name="password"]', TEST_PASSWORD);
24 await page.click('button[type="submit"]');
25
26 // Expect redirect away from /register
27 await expect(page).not.toHaveURL(/\/register/);
28
29 // Should surface the username somewhere on the page (nav, dashboard, etc.)
30 await expect(page.locator("body")).toContainText(username, { timeout: 8_000 });
31 });
32
33 test("duplicate username — shows error message", async ({ page }) => {
34 const username = uid("dup");
35 const email = `${username}@test.example`;
36
37 // Register once
38 await page.goto("/register");
39 await page.fill('input[name="username"]', username);
40 await page.fill('input[name="email"]', email);
41 await page.fill('input[name="password"]', TEST_PASSWORD);
42 await page.click('button[type="submit"]');
43 await page.waitForURL(/\/(dashboard|[a-z])/);
44
45 // Navigate away, then try registering again with same username
46 await page.goto("/register");
47 await page.fill('input[name="username"]', username);
48 await page.fill('input[name="email"]', `other-${email}`);
49 await page.fill('input[name="password"]', TEST_PASSWORD);
50 await page.click('button[type="submit"]');
51
52 // Should stay on /register (or show an error URL) with an error message
53 const body = page.locator("body");
54 await expect(body).toContainText(/already|taken|exists/i, { timeout: 5_000 });
55 });
56
57 test("missing fields — stays on register page", async ({ page }) => {
58 await page.goto("/register");
59 // Submit with no data — browser or server should block/redirect back
60 await page.click('button[type="submit"]');
61
62 // We either stay on /register or get an error param
63 const url = page.url();
64 const onRegisterOrError =
65 url.includes("/register") ||
66 url.includes("error") ||
67 (await page.locator(".auth-error, [role=alert]").count()) > 0;
68 expect(onRegisterOrError).toBeTruthy();
69 });
70});
71
72// ---------------------------------------------------------------------------
73// Login
74// ---------------------------------------------------------------------------
75
76test.describe("Login", () => {
77 test("happy path — existing user logs in", async ({ page }) => {
78 const username = uid("login");
79 const email = `${username}@test.example`;
80
81 // Pre-register
82 await page.goto("/register");
83 await page.fill('input[name="username"]', username);
84 await page.fill('input[name="email"]', email);
85 await page.fill('input[name="password"]', TEST_PASSWORD);
86 await page.click('button[type="submit"]');
87 await page.waitForURL(/\/(dashboard|[a-z])/);
88
89 // Logout then log back in
90 await page.goto("/logout");
91 await page.waitForURL(/\/(login|register|)/);
92
93 await page.goto("/login");
94 await page.fill('input[name="username"]', username);
95 await page.fill('input[name="password"]', TEST_PASSWORD);
96 await page.click('button[type="submit"]');
97
98 await expect(page).not.toHaveURL(/\/login/);
99 await expect(page.locator("body")).toContainText(username, { timeout: 8_000 });
100 });
101
102 test("wrong password — shows error, stays on login page", async ({ page }) => {
103 const username = uid("badpw");
104 const email = `${username}@test.example`;
105
106 // Pre-register
107 await page.goto("/register");
108 await page.fill('input[name="username"]', username);
109 await page.fill('input[name="email"]', email);
110 await page.fill('input[name="password"]', TEST_PASSWORD);
111 await page.click('button[type="submit"]');
112 await page.waitForURL(/\/(dashboard|[a-z])/);
113
114 // Logout
115 await page.goto("/logout");
116
117 // Try wrong password
118 await page.goto("/login");
119 await page.fill('input[name="username"]', username);
120 await page.fill('input[name="password"]', "WrongPassword999!");
121 await page.click('button[type="submit"]');
122
123 // Should stay on login or get an error
124 const body = page.locator("body");
125 await expect(body).toContainText(/invalid|incorrect|wrong|failed/i, {
126 timeout: 5_000,
127 });
128 });
129
130 test("unknown username — shows error", async ({ page }) => {
131 await page.goto("/login");
132 await page.fill('input[name="username"]', "totally_nonexistent_xyz_abc");
133 await page.fill('input[name="password"]', TEST_PASSWORD);
134 await page.click('button[type="submit"]');
135
136 const body = page.locator("body");
137 await expect(body).toContainText(/invalid|not found|incorrect/i, {
138 timeout: 5_000,
139 });
140 });
141});
142
143// ---------------------------------------------------------------------------
144// Logout
145// ---------------------------------------------------------------------------
146
147test.describe("Logout", () => {
148 test("logged-in user can log out and is redirected", async ({ page }) => {
149 const username = uid("lgout");
150 const email = `${username}@test.example`;
151
152 await page.goto("/register");
153 await page.fill('input[name="username"]', username);
154 await page.fill('input[name="email"]', email);
155 await page.fill('input[name="password"]', TEST_PASSWORD);
156 await page.click('button[type="submit"]');
157 await page.waitForURL(/\/(dashboard|[a-z])/);
158
159 // Logout
160 await page.goto("/logout");
161 await page.waitForURL(/\/(login|register|)/);
162
163 // Accessing a protected route should redirect to login
164 await page.goto("/settings");
165 await expect(page).toHaveURL(/\/login/);
166 });
167});