Fix unit tests depending on season being open

This commit is contained in:
Kalle
2026-08-24 21:05:54 +03:00
parent de6e8a4ffa
commit deda1418c2
3 changed files with 32 additions and 0 deletions

View File

@@ -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<ReturnType<typeof setupMatchedUpGroups>>;
beforeEach(async () => {

View File

@@ -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<Awaited<ReturnType<typeof rawReadyLoader>>>({
@@ -55,6 +56,8 @@ const setupReadyCheck = async () => {
};
describe("SendouQ ready check page", () => {
pinClockInsideSeason();
afterEach(() => {
Seasons.DANGEROUS_setSeasonEndedOverride(false);
});

View File

@@ -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();
});
}