website refactor
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { WebsiteAuthManager } from '../../shared/website/WebsiteAuthManager';
|
||||
|
||||
const WEBSITE_BASE_URL = process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:3000';
|
||||
|
||||
test.describe('Role-based Access Sanity', () => {
|
||||
|
||||
test('admin can access admin dashboard', async ({ browser, request }) => {
|
||||
const admin = await WebsiteAuthManager.createAuthContext(browser, request, 'admin');
|
||||
try {
|
||||
await admin.page.goto(`${WEBSITE_BASE_URL}/admin`);
|
||||
expect(admin.page.url()).toContain('/admin');
|
||||
await expect(admin.page.locator('body')).toBeVisible();
|
||||
} finally {
|
||||
await admin.context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('regular user is redirected from admin dashboard', async ({ browser, request }) => {
|
||||
const auth = await WebsiteAuthManager.createAuthContext(browser, request, 'auth');
|
||||
try {
|
||||
await auth.page.goto(`${WEBSITE_BASE_URL}/admin`);
|
||||
// Should be redirected to dashboard or home
|
||||
expect(auth.page.url()).not.toContain('/admin');
|
||||
expect(auth.page.url()).toContain('/dashboard');
|
||||
} finally {
|
||||
await auth.context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('sponsor can access sponsor dashboard', async ({ browser, request }) => {
|
||||
const sponsor = await WebsiteAuthManager.createAuthContext(browser, request, 'sponsor');
|
||||
try {
|
||||
await sponsor.page.goto(`${WEBSITE_BASE_URL}/sponsor/dashboard`);
|
||||
expect(sponsor.page.url()).toContain('/sponsor/dashboard');
|
||||
await expect(sponsor.page.locator('body')).toBeVisible();
|
||||
} finally {
|
||||
await sponsor.context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('unauthenticated user is redirected to login', async ({ page }) => {
|
||||
await page.goto(`${WEBSITE_BASE_URL}/dashboard`);
|
||||
expect(page.url()).toContain('/auth/login');
|
||||
});
|
||||
});
|
||||
@@ -63,8 +63,8 @@ test.describe('Website Route Coverage & Failure Modes', () => {
|
||||
expect(capture.getUnexpectedErrors(), capture.format()).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('Role-Based Access (Admin & Sponsor)', async ({ browser, request }) => {
|
||||
const roles: ScenarioRole[] = ['admin', 'sponsor'];
|
||||
test('Role-Based Access (Auth, Admin & Sponsor)', async ({ browser, request }) => {
|
||||
const roles: ScenarioRole[] = ['auth', 'admin', 'sponsor'];
|
||||
|
||||
for (const role of roles) {
|
||||
const { context, page } = await WebsiteAuthManager.createAuthContext(browser, request, role as any);
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { ConsoleErrorCapture } from '../../shared/website/ConsoleErrorCapture';
|
||||
|
||||
const WEBSITE_BASE_URL = process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:3000';
|
||||
|
||||
const CRITICAL_ROUTES = [
|
||||
'/',
|
||||
'/dashboard',
|
||||
'/leagues',
|
||||
'/teams',
|
||||
'/drivers',
|
||||
];
|
||||
|
||||
const ALLOWED_WARNINGS = [
|
||||
'hydration',
|
||||
'text content does not match',
|
||||
'warning:',
|
||||
'download the react devtools',
|
||||
'connection refused',
|
||||
'failed to load resource',
|
||||
'network error',
|
||||
'cors',
|
||||
'react does not recognize the `%s` prop on a dom element',
|
||||
];
|
||||
|
||||
test.describe('Runtime Health', () => {
|
||||
for (const path of CRITICAL_ROUTES) {
|
||||
test(`route ${path} should have no unexpected console errors`, async ({ page }) => {
|
||||
const capture = new ConsoleErrorCapture(page);
|
||||
capture.setAllowlist(ALLOWED_WARNINGS);
|
||||
|
||||
const response = await page.goto(`${WEBSITE_BASE_URL}${path}`);
|
||||
|
||||
// Some routes might redirect to login if not authenticated, which is fine for health check
|
||||
// as long as the page itself doesn't crash.
|
||||
expect(response?.status()).toBeLessThan(500);
|
||||
|
||||
// Wait a bit for client-side errors to surface
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
if (capture.hasUnexpectedErrors()) {
|
||||
throw new Error(`Found unexpected console errors on ${path}:\n${capture.format()}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { routeMatchers, routes } from '../../../apps/website/lib/routing/RouteConfig';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { routeMatchers } from '../../../apps/website/lib/routing/RouteConfig';
|
||||
|
||||
describe('RouteConfig - routeMatchers Invariants', () => {
|
||||
describe('isPublic()', () => {
|
||||
|
||||
Reference in New Issue
Block a user