mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-12 14:16:04 -05:00
Fix unit tests depending on season being open
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
26
app/features/sendouq/tests/season-clock.ts
Normal file
26
app/features/sendouq/tests/season-clock.ts
Normal 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();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user