From deda1418c27897de9c35f4f39e1e709b746245eb Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Mon, 24 Aug 2026 21:05:54 +0300 Subject: [PATCH] Fix unit tests depending on season being open --- .../sendouq/core/ready-check.server.test.ts | 3 +++ app/features/sendouq/routes/q.ready.test.ts | 3 +++ app/features/sendouq/tests/season-clock.ts | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 app/features/sendouq/tests/season-clock.ts diff --git a/app/features/sendouq/core/ready-check.server.test.ts b/app/features/sendouq/core/ready-check.server.test.ts index f73fd2c2e..e1dd9651b 100644 --- a/app/features/sendouq/core/ready-check.server.test.ts +++ b/app/features/sendouq/core/ready-check.server.test.ts @@ -21,6 +21,7 @@ import { SENDOUQ_LOOKING_ROOM, sqGroupWebsocketRoom, } from "../q-constants"; +import { pinClockInsideSeason } from "../tests/season-clock"; import * as ReadyCheck from "./ready-check.server"; import { refreshSendouQInstance, SendouQ } from "./SendouQ.server"; @@ -86,6 +87,8 @@ const confirmEveryoneReady = async (groupId: number) => { }; describe("SendouQ ready check", () => { + pinClockInsideSeason(); + let groups: Awaited>; beforeEach(async () => { diff --git a/app/features/sendouq/routes/q.ready.test.ts b/app/features/sendouq/routes/q.ready.test.ts index e83f89ddf..00ab9cf4a 100644 --- a/app/features/sendouq/routes/q.ready.test.ts +++ b/app/features/sendouq/routes/q.ready.test.ts @@ -20,6 +20,7 @@ import * as ReadyCheck from "../core/ready-check.server"; import { refreshSendouQInstance, SendouQ } from "../core/SendouQ.server"; import type { readySchema } from "../q-action-schemas"; import { FULL_GROUP_SIZE, SENDOUQ } from "../q-constants"; +import { pinClockInsideSeason } from "../tests/season-clock"; import { action as rawReadyAction, loader as rawReadyLoader } from "./q.ready"; const readyLoader = wrappedLoader>>({ @@ -55,6 +56,8 @@ const setupReadyCheck = async () => { }; describe("SendouQ ready check page", () => { + pinClockInsideSeason(); + afterEach(() => { Seasons.DANGEROUS_setSeasonEndedOverride(false); }); diff --git a/app/features/sendouq/tests/season-clock.ts b/app/features/sendouq/tests/season-clock.ts new file mode 100644 index 000000000..e7a2e4dfb --- /dev/null +++ b/app/features/sendouq/tests/season-clock.ts @@ -0,0 +1,26 @@ +import { afterAll, beforeAll, vi } from "vitest"; +import * as Seasons from "~/features/mmr/core/Seasons"; +import invariant from "~/utils/invariant"; + +const lastSeason = Seasons.list[Seasons.list.length - 1]; +invariant(lastSeason, "Expected at least one season"); + +const insideASeason = new Date( + (lastSeason.starts.getTime() + lastSeason.ends.getTime()) / 2, +); + +/** + * Pins the suite's clock inside a season, for the tests whose subject only happens + * while one is running. Seasons are a fixed list, so between the last one ending and + * the next one being added every such test would otherwise fail. + */ +export function pinClockInsideSeason() { + beforeAll(() => { + vi.useFakeTimers({ toFake: ["Date"] }); + vi.setSystemTime(insideASeason); + }); + + afterAll(() => { + vi.useRealTimers(); + }); +}