Skip to content

Commit 987b634

Browse files
committed
fixed login test since the demo api now supports login + additional test with existing user with bad password (the other login failure tests checks a non-existing user)
1 parent 766c1a7 commit 987b634

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

e2e/auth.spec.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,94 +4,80 @@ import { register, login, logout, generateUniqueUser } from './helpers/auth';
44
test.describe('Authentication', () => {
55
test('should register a new user', async ({ page }) => {
66
const user = generateUniqueUser();
7-
87
await register(page, user.username, user.email, user.password);
9-
108
// Should be redirected to home page
119
await expect(page).toHaveURL('/');
12-
1310
// Should see username in header
1411
await expect(page.locator(`a[href="/profile/${user.username}"]`)).toBeVisible();
15-
1612
// Should be able to access editor
1713
await page.click('a[href="/editor"]');
1814
await expect(page).toHaveURL('/editor');
1915
});
2016

21-
test.fixme('should login with existing user', async ({ page }) => {
22-
// TODO: Temporarily disabled - requires persistent backend
23-
// The demo API (api.realworld.show) doesn't persist test users between sessions.
24-
// This test works with local backend or production API with user persistence.
25-
//
26-
// To re-enable:
27-
// 1. Set up local backend OR
28-
// 2. Use production API with persistent test accounts OR
29-
// 3. Change test to use pre-existing demo account
30-
//
31-
// Track: Create GitHub issue to re-enable when backend is available
32-
17+
test('should login with existing user', async ({ page }) => {
3318
const user = generateUniqueUser();
34-
3519
// First register a user
3620
await register(page, user.username, user.email, user.password);
37-
3821
// Logout
3922
await logout(page);
40-
4123
// Should see Sign in link
4224
await expect(page.locator('a[href="/login"]')).toBeVisible();
43-
4425
// Login again
4526
await login(page, user.email, user.password);
46-
4727
// Should be logged in
4828
await expect(page.locator(`a[href="/profile/${user.username}"]`)).toBeVisible();
4929
});
5030

5131
test('should show error for invalid login', async ({ page }) => {
5232
await page.goto('/login');
53-
5433
await page.fill('input[formControlName="email"]', 'nonexistent@example.com');
5534
await page.fill('input[formControlName="password"]', 'wrongpassword');
5635
await page.click('button[type="submit"]');
36+
// Should show error message
37+
await expect(page.locator('.error-messages')).toBeVisible();
38+
});
5739

40+
test('should fail login with wrong password', async ({ page }) => {
41+
const user = generateUniqueUser();
42+
// First register a user with correct credentials
43+
await register(page, user.username, user.email, user.password);
44+
// Logout
45+
await logout(page);
46+
// Try to login with correct email but wrong password
47+
await page.goto('/login');
48+
await page.fill('input[formControlName="email"]', user.email);
49+
await page.fill('input[formControlName="password"]', 'wrongpassword123');
50+
await page.click('button[type="submit"]');
5851
// Should show error message
5952
await expect(page.locator('.error-messages')).toBeVisible();
53+
// Should still be on login page (not redirected)
54+
await expect(page).toHaveURL('/login');
6055
});
6156

6257
test('should logout successfully', async ({ page }) => {
6358
const user = generateUniqueUser();
64-
6559
await register(page, user.username, user.email, user.password);
66-
6760
// User should be logged in
6861
await expect(page.locator(`a[href="/profile/${user.username}"]`)).toBeVisible();
69-
7062
// Logout
7163
await logout(page);
72-
7364
// Should see Sign in link (user is logged out)
7465
await expect(page.locator('a[href="/login"]')).toBeVisible();
75-
7666
// Should not see profile link
7767
await expect(page.locator(`a[href="/profile/${user.username}"]`)).not.toBeVisible();
7868
});
7969

8070
test('should prevent accessing editor when not logged in', async ({ page }) => {
8171
await page.goto('/editor');
82-
8372
// Should be redirected to login or home
8473
await expect(page).not.toHaveURL('/editor');
8574
});
8675

8776
test('should maintain session after page reload', async ({ page }) => {
8877
const user = generateUniqueUser();
89-
9078
await register(page, user.username, user.email, user.password);
91-
9279
// Reload the page
9380
await page.reload();
94-
9581
// Should still be logged in
9682
await expect(page.locator(`a[href="/profile/${user.username}"]`)).toBeVisible();
9783
});

0 commit comments

Comments
 (0)