Add a "phasingOut" minigame status and an `estimatedRemovalDate` field so a game can be announced as leaving soon while staying fully playable and keeping scoring periods (unlike retired games). Visibility is the only difference: - Sidebar badge + tooltip (amber "Phasing out", countdown to removal) in NavMinigames, via new phasingOutTooltip in countdown.ts. - In-game banner (PhasingOutBanner) on all 9 game pages, wired from getMinigameReleaseState (added the fetch to call-for-fire, which lacked it). - registry.ts status union + field; loadRegistry.ts maps the field; config status select + estimatedRemovalDate date field added. - Migration adds the enum value and column (idempotent); types + db schema regenerated. Adds tests for visibility, round-trip, and period scoring; updates the minigames domain guide.
129 lines
4.4 KiB
TypeScript
129 lines
4.4 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");
|
|
});
|
|
|
|
it("keeps a phasing-out game playable: round-trips the removal date and leaderboard row", async () => {
|
|
await clearMinigameData();
|
|
await createGame({
|
|
key: "retire-me",
|
|
label: "Retire Me",
|
|
status: "phasingOut",
|
|
order: 1,
|
|
estimatedRemovalDate: RELEASE,
|
|
});
|
|
|
|
const games = await loadMinigameRegistry(payload);
|
|
const leaving = games.find((game) => game.key === "retire-me");
|
|
expect(leaving?.estimatedRemovalDate).toBe(RELEASE);
|
|
|
|
// Not a coming-soon gate: it renders the arena rather than the coming-soon screen.
|
|
const gate = await getMinigameReleaseState(payload, "retire-me");
|
|
expect(gate.upcoming).toBe(false);
|
|
|
|
// Still scores periods while it is playable.
|
|
const data = await buildLeaderboardPayload(payload, { scope: "period" });
|
|
expect(data.boards.map((board) => board.key)).toContain("retire-me");
|
|
});
|
|
|
|
async function createGame(data: {
|
|
key: string;
|
|
label: string;
|
|
status: "active" | "upcoming" | "retired" | "phasingOut";
|
|
order: number;
|
|
estimatedReleaseDate?: string;
|
|
estimatedRemovalDate?: 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 });
|
|
}
|
|
}
|
|
});
|