Files
gridpilot.gg/tests/integration/website/RouteContractSpec.test.ts
2026-01-17 18:28:10 +01:00

54 lines
2.1 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { getWebsiteRouteContracts } from '../../shared/website/RouteContractSpec';
import { WebsiteRouteManager } from '../../shared/website/WebsiteRouteManager';
describe('RouteContractSpec', () => {
const contracts = getWebsiteRouteContracts();
const manager = new WebsiteRouteManager();
const inventory = manager.getWebsiteRouteInventory();
it('should cover all inventory routes', () => {
expect(contracts.length).toBe(inventory.length);
const inventoryPaths = inventory.map(def =>
manager.resolvePathTemplate(def.pathTemplate, def.params)
);
const contractPaths = contracts.map(c => c.path);
// Ensure every path in inventory has a corresponding contract
inventoryPaths.forEach(path => {
expect(contractPaths).toContain(path);
});
});
it('should have expectedStatus set for every contract', () => {
contracts.forEach(contract => {
expect(contract.expectedStatus).toBeDefined();
expect(['ok', 'redirect', 'notFoundAllowed', 'errorRoute']).toContain(contract.expectedStatus);
});
});
it('should have expectedRedirectTo set for protected routes (unauth scenario)', () => {
const protectedContracts = contracts.filter(c => c.accessLevel !== 'public');
// Filter out routes that might have overrides to not be 'redirect'
const redirectingContracts = protectedContracts.filter(c => c.expectedStatus === 'redirect');
expect(redirectingContracts.length).toBeGreaterThan(0);
redirectingContracts.forEach(contract => {
expect(contract.expectedRedirectTo).toBeDefined();
expect(contract.expectedRedirectTo).toMatch(/^\//);
});
});
it('should include default SSR sanity markers', () => {
contracts.forEach(contract => {
expect(contract.ssrMustContain).toContain('<!DOCTYPE html>');
expect(contract.ssrMustContain).toContain('<body');
expect(contract.ssrMustNotContain).toContain('__NEXT_ERROR__');
expect(contract.ssrMustNotContain).toContain('Application error: a client-side exception has occurred');
});
});
});