wip league admin tools

This commit is contained in:
2025-12-28 12:04:12 +01:00
parent 5dc8c2399c
commit 6edf12fda8
401 changed files with 15365 additions and 6047 deletions

View File

@@ -0,0 +1,73 @@
import { describe, it, expect } from 'vitest';
import * as fs from 'fs/promises';
import * as path from 'path';
describe('Website boundary: pages must consume ViewModels only (no DTO imports)', () => {
it('rejects forbidden imports for specific pages', async () => {
const websiteRoot = path.resolve(__dirname, '../..');
const candidates = [
'app/races/[id]/page.tsx',
'app/leagues/[id]/stewarding/protests/[protestId]/page.tsx',
].map((p) => path.resolve(websiteRoot, p));
const forbiddenImportRegex =
/^\s*import[\s\S]*from\s+['"][^'"]*(\/mappers\/|\/lib\/types\/|\/types\/generated\/)[^'"]*['"]/gm;
const offenders: Array<{ file: string; matches: string[] }> = [];
for (const file of candidates) {
const content = await fs.readFile(file, 'utf-8');
const matches = Array.from(content.matchAll(forbiddenImportRegex))
.map((m) => m[0])
.filter(Boolean);
if (matches.length > 0) {
offenders.push({
file: path.relative(websiteRoot, file),
matches,
});
}
}
expect(
offenders,
`Forbidden imports found:\n${offenders
.map((o) => `- ${o.file}\n${o.matches.map((m) => ` ${m}`).join('\n')}`)
.join('\n')}`,
).toEqual([]);
});
it('rejects DTO identifier usage in these page modules', async () => {
const websiteRoot = path.resolve(__dirname, '../..');
const candidates = [
'app/races/[id]/page.tsx',
'app/leagues/[id]/stewarding/protests/[protestId]/page.tsx',
].map((p) => path.resolve(websiteRoot, p));
const dtoIdentifierRegex = /\b[A-Za-z0-9_]+DTO\b/g;
const offenders: Array<{ file: string; matches: string[] }> = [];
for (const file of candidates) {
const content = await fs.readFile(file, 'utf-8');
const matches = Array.from(content.matchAll(dtoIdentifierRegex)).map((m) => m[0]).filter(Boolean);
if (matches.length > 0) {
offenders.push({
file: path.relative(websiteRoot, file),
matches: Array.from(new Set(matches)).sort(),
});
}
}
expect(
offenders,
`DTO identifiers found:\n${offenders
.map((o) => `- ${o.file}\n${o.matches.map((m) => ` ${m}`).join('\n')}`)
.join('\n')}`,
).toEqual([]);
});
});