47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
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');
|
|
});
|
|
});
|