Skip to content

Commit

Permalink
Fix prepared maps missing 3rd place match crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Sendouc committed Dec 23, 2024
1 parent 62fafdd commit 1665715
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
35 changes: 31 additions & 4 deletions app/features/tournament-bracket/core/PreparedMaps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { PreparedMaps as PreparedMapsType } from "~/db/tables";
import * as PreparedMaps from "./PreparedMaps";
import { testTournament } from "./tests/test-utils";

describe("PreparedMaps - resolvePreparedForTheBracket", () => {
const tournament = testTournament({
const getTestTournament = (thirdPlaceMatchesForBoth = true) =>
testTournament({
ctx: {
settings: {
bracketProgression: [
Expand All @@ -19,7 +19,9 @@ describe("PreparedMaps - resolvePreparedForTheBracket", () => {
type: "single_elimination",
name: "Top Cut",
requiresCheckIn: false,
settings: {},
settings: {
thirdPlaceMatch: true,
},
sources: [
{
bracketIdx: 0,
Expand All @@ -31,7 +33,9 @@ describe("PreparedMaps - resolvePreparedForTheBracket", () => {
type: "single_elimination",
name: "Underground Bracket",
requiresCheckIn: false,
settings: {},
settings: {
thirdPlaceMatch: thirdPlaceMatchesForBoth,
},
sources: [
{
bracketIdx: 0,
Expand All @@ -44,6 +48,9 @@ describe("PreparedMaps - resolvePreparedForTheBracket", () => {
},
});

describe("PreparedMaps - resolvePreparedForTheBracket", () => {
const tournament = getTestTournament();

test("returns null if no prepared maps at all", () => {
const prepared = PreparedMaps.resolvePreparedForTheBracket({
tournament,
Expand Down Expand Up @@ -106,6 +113,26 @@ describe("PreparedMaps - resolvePreparedForTheBracket", () => {

expect(prepared).not.toBeNull();
});

test("returns null if the sibling does not have third place match while this one does", () => {
const tournament = getTestTournament(false);

const prepared = PreparedMaps.resolvePreparedForTheBracket({
tournament,
bracketIdx: 1,
preparedByBracket: [
null,
null,
{
authorId: 1,
createdAt: 1,
maps: [],
},
],
});

expect(prepared).toBeNull();
});
});

describe("PreparedMaps - eliminationTeamCountOptions", () => {
Expand Down
3 changes: 2 additions & 1 deletion app/features/tournament-bracket/core/PreparedMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export function resolvePreparedForTheBracket({
compare(
bracket.sources?.map((s) => s.bracketIdx),
bracketPreparingFor.sources?.map((s) => s.bracketIdx),
)
) &&
compare(bracket.settings, bracketPreparingFor.settings)
) {
const bracketMaps = preparedByBracket?.[anotherBracketIdx];

Expand Down

0 comments on commit 1665715

Please sign in to comment.