mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-11 21:56:11 -05:00
Fix tournament page crashing when a DE bracket with a follow-up bracket has exactly 2 teams
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user