Fix tournament match pages with BYE not responding 404

Closes #3052

This also fixes these BYE matches having a tournament match chat
This commit is contained in:
Kalle
2026-05-09 11:28:27 +03:00
parent eb7adfd7e2
commit 8e6b975e02
2 changed files with 31 additions and 0 deletions

View File

@@ -80,10 +80,18 @@ export async function findMatchById(id: number) {
return {
...row,
opponentOne: normalizeOpponent(row.opponentOne),
opponentTwo: normalizeOpponent(row.opponentTwo),
bestOf: row.roundMaps.count,
};
}
// Kysely's ParseJSONResultsPlugin only parses strings starting with `[` or `{`,
// so the JSON `null` stored for BYE opponents survives as the literal text "null".
function normalizeOpponent<T>(value: T): T | null {
return (value as unknown) === "null" ? null : value;
}
export function findResultById(id: number) {
return db
.selectFrom("TournamentMatchGameResult")

View File

@@ -6,6 +6,7 @@ vi.mock("~/features/chat/ChatSystemMessage.server", () => ({
setMetadata: vi.fn(),
}));
import { db } from "~/db/sql";
import type { adminActionSchema } from "~/features/tournament/tournament-schemas.server";
import {
dbInsertTournament,
@@ -246,4 +247,26 @@ describe("Tournament match page", () => {
expect(res).toBe(null);
});
});
describe("BYE matches", () => {
it("should 404 when accessing a BYE match", async () => {
await db
.updateTable("TournamentMatch")
.set({ opponentTwo: JSON.stringify(null) })
.where("id", "=", 1)
.execute();
await expect(loadMatchData()).rejects.toThrow("404");
});
it("should not 404 when an opponent is a TBD placeholder waiting for an earlier match", async () => {
await db
.updateTable("TournamentMatch")
.set({ opponentTwo: JSON.stringify({ id: null }) })
.where("id", "=", 1)
.execute();
await expect(loadMatchData()).resolves.toBeDefined();
});
});
});