Fix tournament page crashing when a DE bracket with a follow-up bracket has exactly 2 teams
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run

This commit is contained in:
Kalle
2026-08-04 18:23:25 +03:00
parent ff60e34c55
commit 0a5c5ece73
2 changed files with 17 additions and 3 deletions

View File

@@ -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"

View File

@@ -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