mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-11 13:46:10 -05:00
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:
@@ -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")
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user