diff --git a/app/features/tournament-bracket/core/Bracket/DoubleEliminationBracket.ts b/app/features/tournament-bracket/core/Bracket/DoubleEliminationBracket.ts index 9026069f4..cab6d4296 100644 --- a/app/features/tournament-bracket/core/Bracket/DoubleEliminationBracket.ts +++ b/app/features/tournament-bracket/core/Bracket/DoubleEliminationBracket.ts @@ -124,12 +124,12 @@ export class DoubleEliminationBracket extends Bracket { } // edge case: 1 match only - const noLosersRounds = !losersGroupId; + const noLosersRounds = losersGroupId === undefined; const grandFinalsNumber = noLosersRounds ? 1 : 3; const grandFinalsGroupId = this.data.group.find( (g) => g.number === grandFinalsNumber, )?.id; - invariant(grandFinalsGroupId, "GF group not found"); + invariant(grandFinalsGroupId !== undefined, "GF group not found"); const grandFinalMatches = this.data.match.filter( (match) => match.groupId === grandFinalsGroupId, ); @@ -137,6 +137,7 @@ export class DoubleEliminationBracket extends Bracket { // if opponent1 won in DE it means that bracket reset is not played if ( grandFinalMatches[0].opponent1 && + grandFinalMatches[0].winnerSide && (noLosersRounds || grandFinalMatches[0].winnerSide === "opponent1") ) { const loser = @@ -163,7 +164,7 @@ export class DoubleEliminationBracket extends Bracket { team: winnerTeam, placement: 1, }); - } else if (grandFinalMatches[1].winnerSide) { + } else if (grandFinalMatches[1]?.winnerSide) { const loser = grandFinalMatches[1].winnerSide === "opponent1" ? "opponent2" diff --git a/app/features/tournament-bracket/core/Tournament.test.ts b/app/features/tournament-bracket/core/Tournament.test.ts index 27e6ac4f0..11138c0a1 100644 --- a/app/features/tournament-bracket/core/Tournament.test.ts +++ b/app/features/tournament-bracket/core/Tournament.test.ts @@ -204,6 +204,19 @@ describe("Follow-up bracket progression", () => { } }); + test("initializes an unstarted DE + underground tournament with exactly 2 teams", () => { + const tournament = testTournament({ + ctx: { + settings: { + bracketProgression: progressions.doubleEliminationWithUnderground, + }, + teams: [tournamentCtxTeam(1), tournamentCtxTeam(2)], + }, + }); + + expect(tournament.brackets).toHaveLength(2); + }); + // TODO: handle LUTI bracket progression // test("avoids rematches in RR -> SE (LUTI S16 Div 1) - avoid as long as possible", () => { // https://github.com/sendou-ink/sendou.ink/pull/2192