feat: add double elimination match mode
This commit is contained in:
1 parent
b9aaf55193
commit
e12f182e7f
19 files changed
+3415
-58
No files matched your search
@@ -28,10 +28,11 @@ function createService() {
|
||||
|
||||
interface MatchOverrides {
|
||||
gameCount?: number;
|
||||
gameMode?: 'pair' | 'bracket' | 'round-robin';
|
||||
gameMode?: 'pair' | 'bracket' | 'round-robin' | 'double-elimination';
|
||||
roundRobinMaxRounds?: number;
|
||||
participants?: Array<{ excluded?: boolean }>;
|
||||
teams?: Array<{ teamIndex: number }>;
|
||||
doubleElimination?: MatchDocument['doubleElimination'];
|
||||
gameSchedule?: Array<{
|
||||
gameNumber: number;
|
||||
roundNumber?: number;
|
||||
@@ -51,6 +52,7 @@ function createMatch(overrides: MatchOverrides): MatchDocument {
|
||||
tournamentCodeIds: [],
|
||||
gameSchedule: [],
|
||||
save: jest.fn().mockResolvedValue(undefined),
|
||||
markModified: jest.fn(),
|
||||
...overrides,
|
||||
} as unknown as MatchDocument;
|
||||
}
|
||||
@@ -206,6 +208,35 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
||||
expect(pair.gameSchedule).toEqual([]);
|
||||
});
|
||||
|
||||
it('creates a double-elimination bracket from built teams', () => {
|
||||
const service = createService();
|
||||
const match = createMatch({
|
||||
gameMode: 'double-elimination',
|
||||
teams: Array.from({ length: 4 }, (_, index) => ({
|
||||
teamIndex: index + 1,
|
||||
})),
|
||||
doubleElimination: {
|
||||
teamCount: 4,
|
||||
resetFinalEnabled: true,
|
||||
resetFinalCreated: false,
|
||||
seeds: [],
|
||||
bracketMatches: [],
|
||||
placements: {},
|
||||
events: [],
|
||||
},
|
||||
});
|
||||
|
||||
service.ensureGameSchedule(match);
|
||||
|
||||
expect(match.doubleElimination?.seeds).toHaveLength(4);
|
||||
expect(match.doubleElimination?.bracketMatches).toHaveLength(6);
|
||||
expect(
|
||||
match.doubleElimination?.bracketMatches.filter(
|
||||
(bracketMatch) => bracketMatch.state === 'ready',
|
||||
),
|
||||
).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('creates a limited round-robin schedule grouped by playable rounds', () => {
|
||||
const service = createService();
|
||||
const roundRobin = createMatch({
|
||||
|
||||
Reference in new issue
Block a user