Fix seeding not applied Closes #1665

This commit is contained in:
Kalle 2024-02-14 23:52:17 +02:00
parent 9de30094d8
commit 1b4d0df7a7
4 changed files with 22 additions and 19 deletions

View File

@ -25,6 +25,10 @@ interface CreateBracketArgs {
bracketIdx: number;
placements: number[];
}[];
seeding?: {
id: number;
name: string;
}[];
}
export interface Standing {
@ -52,6 +56,7 @@ export abstract class Bracket {
tournament;
sources;
createdAt;
seeding;
constructor({
id,
@ -63,6 +68,7 @@ export abstract class Bracket {
tournament,
sources,
createdAt,
seeding,
}: Omit<CreateBracketArgs, "format">) {
this.id = id;
this.preview = preview;
@ -73,6 +79,7 @@ export abstract class Bracket {
this.tournament = tournament;
this.sources = sources;
this.createdAt = createdAt;
this.seeding = seeding;
this.createdSimulation();
}

View File

@ -144,18 +144,14 @@ export class Tournament {
});
if (checkedInTeams.length >= TOURNAMENT.ENOUGH_TEAMS_TO_START) {
const seeding = checkedInTeams.map((team) => ({
name: team.name,
id: team.id,
}));
manager.create({
tournamentId: this.ctx.id,
name,
type,
seeding:
type === "round_robin"
? seeding
: fillWithNullTillPowerOfTwo(seeding),
? checkedInTeams
: fillWithNullTillPowerOfTwo(checkedInTeams),
settings: this.bracketSettings(type, checkedInTeams.length),
});
}
@ -164,6 +160,7 @@ export class Tournament {
Bracket.create({
id: -1 * bracketIdx,
tournament: this,
seeding: checkedInTeams,
preview: true,
name,
data: manager.get.tournamentData(this.ctx.id),

View File

@ -90,22 +90,21 @@ export const action: ActionFunction = async ({ params, request }) => {
const bracket = tournament.bracketByIdx(data.bracketIdx);
invariant(bracket, "Bracket not found");
const seeding = bracket.seeding;
invariant(seeding, "Seeding not found");
validate(bracket.canBeStarted, "Bracket is not ready to be started");
sql.transaction(() => {
const participants = bracket.data.participant.map((p) => p.name);
const stage = manager.create({
tournamentId,
name: bracket.name,
type: bracket.type,
seeding:
bracket.type === "round_robin"
? participants
: fillWithNullTillPowerOfTwo(participants),
settings: tournament.bracketSettings(
bracket.type,
participants.length,
),
? seeding
: fillWithNullTillPowerOfTwo(seeding),
settings: tournament.bracketSettings(bracket.type, seeding.length),
});
const matches = findAllMatchesByStageId(stage.id);

View File

@ -126,8 +126,8 @@ test.describe("Tournament bracket", () => {
});
// 1)
await page.locator('[data-match-id="5"]').click();
await reportResult({ page, amountOfMapsToReport: tournamentId });
await navigateToMatch(page, 6);
await reportResult({ page, amountOfMapsToReport: 2 });
await backToBracket(page);
// 2)
@ -136,7 +136,7 @@ test.describe("Tournament bracket", () => {
page,
url: tournamentBracketsPage({ tournamentId }),
});
await navigateToMatch(page, 6);
await navigateToMatch(page, 5);
await reportResult({ page, amountOfMapsToReport: 2 });
await backToBracket(page);
@ -150,7 +150,7 @@ test.describe("Tournament bracket", () => {
await backToBracket(page);
// 4)
await navigateToMatch(page, 5);
await navigateToMatch(page, 6);
await isNotVisible(page.getByTestId("reopen-match-button"));
await backToBracket(page);
@ -161,7 +161,7 @@ test.describe("Tournament bracket", () => {
await backToBracket(page);
// 6)
await navigateToMatch(page, 5);
await navigateToMatch(page, 6);
await page.getByTestId("reopen-match-button").click();
await expectScore(page, [1, 0]);
@ -171,7 +171,7 @@ test.describe("Tournament bracket", () => {
page,
url: tournamentBracketsPage({ tournamentId }),
});
await navigateToMatch(page, 5);
await navigateToMatch(page, 6);
await page.getByTestId("undo-score-button").click();
await expectScore(page, [0, 0]);
await reportResult({