- Optional `estimatedReleaseDate` (date and time) on the minigames registry,
with a named migration and regenerated types.
- Sidebar: an `upcoming` game renders greyed out and non-interactive, with a
tooltip carrying the estimate and a live countdown. It is a hoverable row
rather than a disabled menu item, because a disabled Radix item sets
`pointer-events: none` and would swallow the tooltip.
- Page gate: each minigame page checks its registry status and renders
`MinigameComingSoon` instead of the arena while the game is upcoming, so a
typed URL cannot reach unfinished gameplay. The date is display only: the
game goes live when an admin flips `status` to active.
- Leaderboards exclude upcoming games, so they get neither a tab nor a board.
- Pure `countdown.ts` formatter plus a client ticker that computes the
remaining time only after mount, avoiding an SSR hydration mismatch.
Note: `registry.ts`, `payload-types.ts` and `migrations/index.ts` also carry
the Call for Fire registry row and its generated types. That feature was
committed as 6d6a5fb and announced a separate commit for those files; they are
included here because they are entangled with these edits in the same files.
Tests: pure countdown unit tests, registry/gate/leaderboard integration tests,
and an e2e that seeds an upcoming row, hovers the disabled sidebar entry to
assert the tooltip, and checks the coming-soon gate.
105 lines
3.5 KiB
TypeScript
105 lines
3.5 KiB
TypeScript
import { getPayload, Payload } from "payload";
|
|
import config from "@/payload.config";
|
|
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { loadMinigameRegistry, getMinigameReleaseState } from "@/lib/minigames/loadRegistry";
|
|
import { buildLeaderboardPayload } from "@/lib/minigames/periods/standings";
|
|
|
|
const RUN = `mgup-${Date.now().toString(36)}`;
|
|
const RELEASE = "2026-12-03T18:00:00.000Z";
|
|
|
|
let payload: Payload;
|
|
let originalRules: Record<string, unknown> | null = null;
|
|
|
|
describe("Upcoming minigames", () => {
|
|
beforeAll(async () => {
|
|
const payloadConfig = await config;
|
|
payload = await getPayload({ config: payloadConfig });
|
|
await clearMinigameData();
|
|
|
|
originalRules = (await payload.findGlobal({
|
|
slug: "minigame-rules",
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
})) as unknown as Record<string, unknown> | null;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await clearMinigameData();
|
|
if (!originalRules) return;
|
|
await payload
|
|
.updateGlobal({
|
|
slug: "minigame-rules",
|
|
data: {
|
|
enabled: Boolean(originalRules.enabled),
|
|
anchorDate: originalRules.anchorDate as string,
|
|
periodLengthDays: (originalRules.periodLengthDays as number) ?? 14,
|
|
placementLadderTopN: (originalRules.placementLadderTopN as number) ?? 10,
|
|
precisionMinAttempts: (originalRules.precisionMinAttempts as number) ?? 5,
|
|
},
|
|
overrideAccess: true,
|
|
})
|
|
.catch(() => undefined);
|
|
});
|
|
|
|
it("round-trips the estimated release date and reports the gate state", async () => {
|
|
await createGame({ key: "signals", label: "Signals Intercept", status: "upcoming", order: 1, estimatedReleaseDate: RELEASE });
|
|
await createGame({ key: "flappy", label: "Flight Simulator", status: "active", order: 2 });
|
|
|
|
const games = await loadMinigameRegistry(payload);
|
|
const signals = games.find((game) => game.key === "signals");
|
|
expect(signals?.estimatedReleaseDate).toBe(RELEASE);
|
|
|
|
const upcoming = await getMinigameReleaseState(payload, "signals");
|
|
expect(upcoming.upcoming).toBe(true);
|
|
expect(upcoming.game?.label).toBe("Signals Intercept");
|
|
|
|
const active = await getMinigameReleaseState(payload, "flappy");
|
|
expect(active.upcoming).toBe(false);
|
|
|
|
const missing = await getMinigameReleaseState(payload, "does-not-exist");
|
|
expect(missing.upcoming).toBe(false);
|
|
expect(missing.game).toBeNull();
|
|
});
|
|
|
|
it("leaves an upcoming game off the leaderboards", async () => {
|
|
const data = await buildLeaderboardPayload(payload, { scope: "period" });
|
|
const keys = data.boards.map((board) => board.key);
|
|
expect(keys).toContain("flappy");
|
|
expect(keys).not.toContain("signals");
|
|
});
|
|
|
|
async function createGame(data: {
|
|
key: string;
|
|
label: string;
|
|
status: "active" | "upcoming" | "retired";
|
|
order: number;
|
|
estimatedReleaseDate?: string;
|
|
}) {
|
|
await payload.create({
|
|
collection: "minigames",
|
|
data: {
|
|
...data,
|
|
route: `/minigames/${data.key}`,
|
|
icon: "Radio",
|
|
category: "core",
|
|
scoreLabel: "Score",
|
|
description: "",
|
|
countsForPeriods: false,
|
|
},
|
|
overrideAccess: true,
|
|
depth: 0,
|
|
});
|
|
}
|
|
|
|
async function clearMinigameData() {
|
|
for (const collection of [
|
|
"achievements",
|
|
"minigame-entries",
|
|
"minigame-periods",
|
|
"minigames",
|
|
] as const) {
|
|
await payload.delete({ collection, where: { id: { greater_than: 0 } }, overrideAccess: true });
|
|
}
|
|
}
|
|
});
|