feat: support double-elimination series games

This commit is contained in:
dahyeon committed 2026-07-07 17:34:59 -07:00
1 parent 2ee8c3807b
commit e188828423
16 files changed
+1176 -234

No files matched your search

@@ -4,6 +4,7 @@ import {
} from '../global/database/schema';
import mongoose from 'mongoose';
import { TournamentCodeService } from './tournament-code.service';
import { buildDoubleEliminationBracket } from '../double-elimination/double-elimination.util';
type TournamentCodeServiceInternals = TournamentCodeService & {
resolveRequiredSlots(match: MatchDocument): number;
@@ -229,6 +230,7 @@ describe('TournamentCodeService round-robin scheduling', () => {
const service = createService();
const match = createMatch({
gameMode: 'double-elimination',
gameCount: 3,
teams: Array.from({ length: 4 }, (_, index) => ({
teamIndex: index + 1,
})),
@@ -252,6 +254,70 @@ describe('TournamentCodeService round-robin scheduling', () => {
(bracketMatch) => bracketMatch.state === 'ready',
),
).toHaveLength(2);
expect(
match.doubleElimination?.bracketMatches.find(
(bracketMatch) => bracketMatch.bracketMatchId === 'WB_R1_M1',
),
).toMatchObject({ gameCount: 3, requiredWins: 2 });
});
it('expands double-elimination winner bracket series into code slots', async () => {
const TournamentCodeModel = {
find: jest.fn().mockReturnValue({
exec: jest.fn().mockResolvedValue([]),
}),
};
const service = new TournamentCodeService(
{ getModel: jest.fn().mockResolvedValue(TournamentCodeModel) } as never,
createAuctionRedisService() as never,
) as unknown as TournamentCodeServiceInternals;
const match = createMatch({
gameMode: 'double-elimination',
gameCount: 3,
teams: Array.from({ length: 4 }, (_, index) => ({
teamIndex: index + 1,
})),
doubleElimination: buildDoubleEliminationBracket([1, 2, 3, 4], {
resetFinalEnabled: true,
}),
});
const slots = await service.buildSlots(match);
expect(slots.slice(0, 6)).toEqual([
expect.objectContaining({
gameNumber: 1,
seriesGameNumber: 1,
seriesGameCount: 3,
seriesRequiredWins: 2,
bracketMatchId: 'WB_R1_M1',
}),
expect.objectContaining({
gameNumber: 2,
seriesGameNumber: 2,
bracketMatchId: 'WB_R1_M1',
}),
expect.objectContaining({
gameNumber: 3,
seriesGameNumber: 3,
bracketMatchId: 'WB_R1_M1',
}),
expect.objectContaining({
gameNumber: 4,
seriesGameNumber: 1,
bracketMatchId: 'WB_R1_M2',
}),
expect.objectContaining({
gameNumber: 5,
seriesGameNumber: 2,
bracketMatchId: 'WB_R1_M2',
}),
expect.objectContaining({
gameNumber: 6,
seriesGameNumber: 3,
bracketMatchId: 'WB_R1_M2',
}),
]);
});
it('creates a limited round-robin schedule grouped by playable rounds', () => {
@@ -374,7 +440,7 @@ describe('TournamentCodeService round-robin scheduling', () => {
});
describe('TournamentCodeService bulk upload', () => {
it('defines unique slot and riot match indexes for multi-instance safety', () => {
it('defines slot and riot match indexes for multi-instance safety', () => {
const indexes = TournamentCodeSchema.indexes();
expect(indexes).toContainEqual([
@@ -391,7 +457,6 @@ describe('TournamentCodeService bulk upload', () => {
expect(indexes).toContainEqual([
{ matchId: 1, bracketMatchId: 1 },
expect.objectContaining({
unique: true,
partialFilterExpression: {
matchId: { $exists: true },
bracketMatchId: { $exists: true },