9c09210a2a
- Remove unused `response` variable in j8-unauth-access.spec.ts:40 - Move Dashboard route inside ProtectedRoute wrapper in App.tsx - Add VITE_MOCK_AUTH mode to ProtectedRoute: check Zustand isAuthenticated flag instead of calling authClient.useSession() Co-Authored-By: Paperclip <noreply@paperclip.ing>
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('J8: Unauthenticated Access', () => {
|
|
test('redirects /dashboard (/) to /login when not authenticated', async ({ page }) => {
|
|
// No session cookie — start fresh
|
|
await page.context().clearCookies();
|
|
await page.goto('/');
|
|
|
|
await expect(page).toHaveURL(/\/login/);
|
|
await expect(page.getByRole('heading', { name: /cartsnitch/i })).toBeVisible();
|
|
});
|
|
|
|
test('redirects /purchases to /login when not authenticated', async ({ page }) => {
|
|
await page.context().clearCookies();
|
|
await page.goto('/purchases');
|
|
|
|
await expect(page).toHaveURL(/\/login/);
|
|
await expect(page.getByRole('heading', { name: /cartsnitch/i })).toBeVisible();
|
|
});
|
|
|
|
test('redirects /products to /login when not authenticated', async ({ page }) => {
|
|
await page.context().clearCookies();
|
|
await page.goto('/products');
|
|
|
|
await expect(page).toHaveURL(/\/login/);
|
|
await expect(page.getByRole('heading', { name: /cartsnitch/i })).toBeVisible();
|
|
});
|
|
|
|
test('redirects /coupons to /login when not authenticated', async ({ page }) => {
|
|
await page.context().clearCookies();
|
|
await page.goto('/coupons');
|
|
|
|
await expect(page).toHaveURL(/\/login/);
|
|
await expect(page.getByRole('heading', { name: /cartsnitch/i })).toBeVisible();
|
|
});
|
|
|
|
test('shows loading spinner while auth session is pending', async ({ page }) => {
|
|
// Intercept but don't respond — session stays pending
|
|
await page.context().clearCookies();
|
|
await page.request.fetch('/api/auth/session', {
|
|
method: 'GET',
|
|
});
|
|
|
|
// Just navigate to a protected route — ProtectedRoute will show spinner while session is pending
|
|
await page.goto('/purchases');
|
|
// Spinner is visible briefly; once resolved, should redirect to login
|
|
await expect(page).toHaveURL(/\/login/, { timeout: 10_000 });
|
|
});
|
|
});
|