74 lines
3.0 KiB
TypeScript
74 lines
3.0 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { WebsiteRouteManager } from '../../shared/website/WebsiteRouteManager';
|
|
import { routes } from '../../../apps/website/lib/routing/RouteConfig';
|
|
|
|
describe('WebsiteRouteManager - Route Classification Contract', () => {
|
|
const routeManager = new WebsiteRouteManager();
|
|
|
|
describe('getAccessLevel()', () => {
|
|
it('should correctly classify public routes', () => {
|
|
expect(routeManager.getAccessLevel('/')).toBe('public');
|
|
expect(routeManager.getAccessLevel('/auth/login')).toBe('public');
|
|
expect(routeManager.getAccessLevel('/leagues')).toBe('public');
|
|
});
|
|
|
|
it('should correctly classify dashboard routes as auth', () => {
|
|
expect(routeManager.getAccessLevel('/dashboard')).toBe('auth');
|
|
expect(routeManager.getAccessLevel('/profile')).toBe('auth');
|
|
});
|
|
|
|
it('should correctly classify admin routes', () => {
|
|
expect(routeManager.getAccessLevel('/admin')).toBe('admin');
|
|
expect(routeManager.getAccessLevel('/admin/users')).toBe('admin');
|
|
});
|
|
|
|
it('should correctly classify sponsor routes', () => {
|
|
expect(routeManager.getAccessLevel('/sponsor')).toBe('sponsor');
|
|
expect(routeManager.getAccessLevel('/sponsor/dashboard')).toBe('sponsor');
|
|
});
|
|
|
|
it('should correctly classify dynamic route patterns', () => {
|
|
// League detail is public
|
|
expect(routeManager.getAccessLevel('/leagues/any-id')).toBe('public');
|
|
expect(routeManager.getAccessLevel('/races/any-id')).toBe('public');
|
|
|
|
// Nested protected routes
|
|
expect(routeManager.getAccessLevel('/leagues/any-id/settings')).toBe('auth');
|
|
});
|
|
});
|
|
|
|
describe('RouteConfig Contract', () => {
|
|
it('should fail loudly if RouteConfig paths change unexpectedly', () => {
|
|
// These assertions act as a contract. If the paths change in RouteConfig,
|
|
// these tests will fail, forcing a conscious update of the contract.
|
|
expect(routes.public.home).toBe('/');
|
|
expect(routes.auth.login).toBe('/auth/login');
|
|
expect(routes.protected.dashboard).toBe('/dashboard');
|
|
expect(routes.admin.root).toBe('/admin');
|
|
expect(routes.sponsor.root).toBe('/sponsor');
|
|
|
|
// Dynamic patterns
|
|
expect(routes.league.detail('test-id')).toBe('/leagues/test-id');
|
|
expect(routes.league.scheduleAdmin('test-id')).toBe('/leagues/test-id/schedule/admin');
|
|
});
|
|
});
|
|
|
|
describe('Representative Subset Verification', () => {
|
|
const testCases = [
|
|
{ path: '/', expected: 'public' },
|
|
{ path: '/auth/login', expected: 'public' },
|
|
{ path: '/dashboard', expected: 'auth' },
|
|
{ path: '/admin', expected: 'admin' },
|
|
{ path: '/sponsor', expected: 'sponsor' },
|
|
{ path: '/leagues/123', expected: 'public' },
|
|
{ path: '/races/456', expected: 'public' },
|
|
];
|
|
|
|
testCases.forEach(({ path, expected }) => {
|
|
it(`should classify ${path} as ${expected}`, () => {
|
|
expect(routeManager.getAccessLevel(path)).toBe(expected);
|
|
});
|
|
});
|
|
});
|
|
});
|