feat: project competition results by team identity

This commit is contained in:
dahyeon committed 2026-07-12 19:01:22 +00:00
1 parent 39112ff7ff
commit 5d4fe443d0
9 files changed
+3408

No files matched your search

@@ -0,0 +1,93 @@
import { generateSeriesGraph } from './series-graph';
describe('generateSeriesGraph', () => {
it('generates a deterministic graph with stable opaque ids', () => {
const input = {
competitionId: 'competition-deterministic',
teams: Array.from({ length: 8 }, (_, index) => ({
teamId: `team-${index + 1}`,
displayOrder: index + 1,
seedNumber: index + 1,
})),
format: {
type: 'double-elimination' as const,
resetFinalEnabled: true,
rules: {
upper: firstTo(2, 3),
lower: firstTo(1, 1),
grandFinal: firstTo(1, 1),
resetFinal: firstTo(1, 1),
},
},
};
const first = generateSeriesGraph(input);
const second = generateSeriesGraph(input);
expect(second).toEqual(first);
expect(first.map((series) => series.id)).toHaveLength(15);
expect(new Set(first.map((series) => series.id))).toHaveProperty(
'size',
15,
);
expect(first.every((series) => series.id.length > 0)).toBe(true);
});
it('predefines a conditional grand-final reset node using only slot sources', () => {
const graph = generateSeriesGraph({
competitionId: 'competition-reset-node',
teams: Array.from({ length: 4 }, (_, index) => ({
teamId: `team-${index + 1}`,
displayOrder: index + 1,
seedNumber: index + 1,
})),
format: {
type: 'double-elimination' as const,
resetFinalEnabled: true,
rules: {
upper: firstTo(2, 3),
lower: firstTo(1, 1),
grandFinal: firstTo(1, 1),
resetFinal: firstTo(1, 1),
},
},
});
const grandFinal = graph.find((series) => series.code === 'GF');
const resetFinal = graph.find((series) => series.code === 'GF_RESET');
expect(grandFinal).toBeDefined();
expect(resetFinal).toMatchObject({
stage: { type: 'reset-final' },
activation: {
type: 'grand-final-reset-required',
grandFinalSeriesId: grandFinal!.id,
},
slots: [
{
position: 'A',
source: {
type: 'series-slot',
seriesId: grandFinal!.id,
slot: 'A',
},
},
{
position: 'B',
source: {
type: 'series-slot',
seriesId: grandFinal!.id,
slot: 'B',
},
},
],
});
for (const series of graph) {
expect(series).not.toHaveProperty('winnerAdvancesTo');
expect(series).not.toHaveProperty('loserAdvancesTo');
}
});
});
function firstTo(winsRequired: number, maxGames: number) {
return { type: 'first-to' as const, winsRequired, maxGames };
}