fix(minigames): resolve the current period before building standings boards
The default ?period=current scope arrives as periodId null, and buildLeaderboardPayload built the boards before resolving currentPeriod(), so buildPeriodBoards short-circuited to zero entries: the live period's board was always empty even while ledger rows existed for it. Resolve the period first and feed its id into the boards, and cover the default scope with a real-clock regression test (the suite previously only exercised explicit period ids).
This commit is contained in:
parent
c5b275f427
commit
2a941c5a5b
2 changed files with 36 additions and 9 deletions
|
|
@ -253,15 +253,10 @@ export async function buildLeaderboardPayload(
|
|||
// their sidebar entry is disabled), so they get neither a tab nor rows.
|
||||
const playable = registry.filter((game) => game.status !== "upcoming");
|
||||
|
||||
const boards = allTime
|
||||
? await buildAllTimeBoards(payload, playable)
|
||||
: await buildPeriodBoards(
|
||||
payload,
|
||||
query.periodId ?? null,
|
||||
playable.filter((game) => game.category === "core"),
|
||||
rules.placementLadderTopN,
|
||||
);
|
||||
|
||||
// Resolve the period BEFORE building the boards: the default "current"
|
||||
// scope arrives as periodId null, and the boards must read the resolved
|
||||
// period's ledger rows rather than the null placeholder (which would show
|
||||
// an empty board even while entries exist for the live period).
|
||||
const periods = await listPeriods(payload);
|
||||
let period: PeriodSummary | null = null;
|
||||
if (!allTime) {
|
||||
|
|
@ -271,6 +266,15 @@ export async function buildLeaderboardPayload(
|
|||
: await currentPeriod(payload);
|
||||
}
|
||||
|
||||
const boards = allTime
|
||||
? await buildAllTimeBoards(payload, playable)
|
||||
: await buildPeriodBoards(
|
||||
payload,
|
||||
query.periodId ?? period?.id ?? null,
|
||||
playable.filter((game) => game.category === "core"),
|
||||
rules.placementLadderTopN,
|
||||
);
|
||||
|
||||
return {
|
||||
mode: allTime ? "all-time" : "period",
|
||||
period,
|
||||
|
|
|
|||
|
|
@ -112,6 +112,29 @@ describe("Minigame leaderboard read model", () => {
|
|||
expect(flappy?.rows[0].rank).toBe(1);
|
||||
});
|
||||
|
||||
it("resolves the current period's boards when no periodId is given", async () => {
|
||||
// Real-clock run: lands in the period covering `now` and lazily creates
|
||||
// its period row, exactly like a production submission does. The default
|
||||
// "current" scope must show it even though no periodId is passed.
|
||||
await recordMinigameEntry({
|
||||
payload,
|
||||
userId: userA,
|
||||
game: "flappy",
|
||||
score: 28,
|
||||
durationMs: 34_000,
|
||||
});
|
||||
|
||||
const payloadData = await buildLeaderboardPayload(payload, { scope: "period" });
|
||||
|
||||
expect(payloadData.mode).toBe("period");
|
||||
expect(payloadData.period).not.toBeNull();
|
||||
expect(payloadData.period?.id).not.toBeNull();
|
||||
const flappy = payloadData.boards.find((board) => board.key === "flappy");
|
||||
const row = flappy?.rows.find((entry) => entry.name === "Alpha Operator");
|
||||
expect(row?.bestScore).toBe(28);
|
||||
expect(row?.attempts).toBe(1);
|
||||
});
|
||||
|
||||
it("reads All-Time boards from the untouched profile aggregates", async () => {
|
||||
const rankRes = await payload.find({
|
||||
collection: "ranks",
|
||||
|
|
|
|||
Loading…
Reference in a new issue