79 lines
2.9 KiB
TypeScript
79 lines
2.9 KiB
TypeScript
/**
|
|
* E2E Test: Authentication Flow
|
|
* Priority: CRITICAL - Security and access control
|
|
*
|
|
* Tests authentication flows:
|
|
* 1. Guest authentication
|
|
* 2. Admin authentication
|
|
* 3. Session management
|
|
* 4. Logout functionality
|
|
*/
|
|
|
|
import { test, expect, type Page } from '@playwright/test';
|
|
|
|
test.describe('Authentication Flow', () => {
|
|
test('guest authentication flow', async ({ page }: { page: Page }) => {
|
|
// Step 1: Navigate to access page
|
|
await page.goto('http://localhost:3000/rsvp');
|
|
|
|
// Step 2: Enter valid invite code
|
|
await page.fill('input[placeholder*="invite"]', 'TEST123');
|
|
await page.click('button[type="submit"]');
|
|
|
|
// Step 3: Verify authentication and redirect
|
|
await page.waitForURL(/.*dashboard.*/, { timeout: 5000 });
|
|
await expect(page).toHaveURL(/.*dashboard.*/);
|
|
|
|
// Step 4: Verify session persists
|
|
await page.reload();
|
|
await expect(page).toHaveURL(/.*dashboard.*/, { timeout: 3000 });
|
|
});
|
|
|
|
test('handles invalid invite code', async ({ page }: { page: Page }) => {
|
|
await page.goto('http://localhost:3000/rsvp');
|
|
|
|
await page.fill('input[placeholder*="invite"]', 'INVALID123');
|
|
await page.click('button[type="submit"]');
|
|
|
|
await expect(page.locator('text=Invalid invite code')).toBeVisible({ timeout: 3000 });
|
|
await expect(page).toHaveURL(/.*rsvp.*/);
|
|
});
|
|
|
|
test('admin authentication flow', async ({ page }: { page: Page }) => {
|
|
// Step 1: Navigate to admin login
|
|
await page.goto('http://localhost:3000/admin');
|
|
|
|
// Step 2: Enter admin credentials
|
|
await page.fill('input[name="email"]', 'admin@example.com');
|
|
await page.fill('input[name="password"]', 'admin-password');
|
|
await page.click('button[type="submit"]');
|
|
|
|
// Step 3: Verify admin dashboard access
|
|
await page.waitForURL(/.*admin.*dashboard.*/, { timeout: 5000 });
|
|
await expect(page.locator('text=Admin Dashboard')).toBeVisible({ timeout: 3000 });
|
|
});
|
|
|
|
test('handles invalid admin credentials', async ({ page }: { page: Page }) => {
|
|
await page.goto('http://localhost:3000/admin');
|
|
|
|
await page.fill('input[name="email"]', 'invalid@example.com');
|
|
await page.fill('input[name="password"]', 'wrong-password');
|
|
await page.click('button[type="submit"]');
|
|
|
|
await expect(page.locator('text=Invalid credentials')).toBeVisible({ timeout: 3000 });
|
|
});
|
|
|
|
test('session timeout handling', async ({ page }: { page: Page }) => {
|
|
// Authenticate first
|
|
await page.goto('http://localhost:3000/rsvp');
|
|
await page.fill('input[placeholder*="invite"]', 'TEST123');
|
|
await page.click('button[type="submit"]');
|
|
await page.waitForURL(/.*dashboard.*/, { timeout: 5000 });
|
|
|
|
// Simulate session expiry (in real test, would wait for actual timeout)
|
|
// For now, test that protected routes require authentication
|
|
await page.goto('http://localhost:3000/dashboard');
|
|
await expect(page).toHaveURL(/.*dashboard.*/, { timeout: 3000 });
|
|
});
|
|
});
|