("[data-scroll-sentinel]");
+ if (sentinel === this.sentinel) return;
+ this.teardownObserver();
+ this.sentinel = sentinel;
+ if (!sentinel) return;
+ this.observer = new IntersectionObserver((entries) => {
+ for (const entry of entries) {
+ if (!entry.isIntersecting) continue;
+ if (this.loading || this.loadingMore) continue;
+ if (this.nextCursor === null) continue;
+ if (this.appendFailed) continue;
+ void this.load({ append: true });
+ }
+ });
+ this.observer.observe(sentinel);
+ }
+
+ private teardownObserver() {
+ if (this.observer) {
+ this.observer.disconnect();
+ this.observer = null;
+ }
+ this.sentinel = null;
+ }
+
+ private watchReplay(gameId: string) {
+ // Navigation + modal close live in the host modal; just hand it the id.
+ this.dispatchEvent(
+ new CustomEvent<{ gameId: string }>("view-game", {
+ detail: { gameId },
+ bubbles: true,
+ composed: true,
+ }),
+ );
+ }
+
+ // Opens the game-info ranking overlay on top of the account modal. The modal
+ // is a global singleton in the document (queried the same way as Main.ts),
+ // so we don't close the account modal — the overlay layers above it.
+ private showRanking(gameId: string) {
+ const gameInfoModal = document.querySelector(
+ "game-info-modal",
+ ) as GameInfoModal | null;
+ if (!gameInfoModal) {
+ console.warn("Game info modal element not found");
+ return;
+ }
+ void gameInfoModal.loadGame(gameId);
+ gameInfoModal.open();
+ }
+
+ render() {
+ return html`
+ ${this.renderFilters()}${this.renderBody()}
+
`;
+ }
+
+ private renderFilters(): TemplateResult {
+ return html`
+
+ ${this.renderFilterRow(TYPE_TABS, this.typeFilter, (k) =>
+ this.setTypeFilter(k as TypeKey),
+ )}
+ ${this.renderFilterRow(MODE_TABS, this.modeFilter, (k) =>
+ this.setModeFilter(k as ModeKey),
+ )}
+
+ `;
+ }
+
+ private renderFilterRow(
+ tabs: { key: string; labelKey: string }[],
+ active: string,
+ onSelect: (key: string) => void,
+ ): TemplateResult {
+ return html`
+
+ ${tabs.map((tab) => {
+ const isActive = active === tab.key;
+ // "All" gets a full row on mobile (basis-full) and normal sizing on
+ // sm+. The others use basis-20 so longer labels stay comfortable and
+ // flex-wrap drops them to a second line when needed.
+ const basis =
+ tab.key === "all" ? "basis-full sm:basis-20" : "basis-20";
+ return html`
+ onSelect(tab.key)}
+ class="grow ${basis} px-3 py-1.5 text-xs font-bold uppercase tracking-wider whitespace-nowrap rounded-lg transition-colors ${isActive
+ ? "bg-malibu-blue/20 text-aquarius border border-malibu-blue/30"
+ : "text-white/50 hover:text-white hover:bg-white/5 border border-transparent"}"
+ >
+ ${translateText(tab.labelKey)}
+
+ `;
+ })}
+
+ `;
+ }
+
+ private renderBody(): TemplateResult {
+ if (this.loading && this.games.length === 0) {
+ return renderLoadingSpinner();
+ }
+ if (this.loadState === "failed") {
+ return html`
+
+
+ ${translateText("clan_modal.history_unavailable")}
+
+
this.reload()}
+ class="text-xs font-bold text-white/60 hover:text-white uppercase tracking-wider px-3 py-1.5 rounded-lg border border-white/10 hover:border-white/20 hover:bg-white/5 transition-colors"
+ >
+ ${translateText("leaderboard_modal.try_again")}
+
+
+ `;
+ }
+ if (this.games.length === 0) {
+ return html`
+
+
+ ${translateText("clan_modal.history_empty")}
+
+
+ `;
+ }
+
+ // Group consecutive games by their start day. Cached against the `games`
+ // reference; `load()` always assigns a fresh array, so identity comparison
+ // is safe.
+ if (this.groupedFor !== this.games) {
+ this.grouped = groupByDay(this.games);
+ this.groupedFor = this.games;
+ }
+ const groups = this.grouped;
+ return html`
+
+ ${groups.map(
+ (group) => html`
+
+
+
+
+ ${formatDayHeader(group.day)}
+
+
+
+
+ ${group.items.map((game) => this.renderGameRow(game))}
+
+
+ `,
+ )}
+ ${this.renderScrollFooter()}
+
+ `;
+ }
+
+ private renderScrollFooter(): TemplateResult {
+ if (this.nextCursor === null) {
+ return html`
+
+ ${translateText("clan_modal.history_end_of_history")}
+
+ `;
+ }
+ if (this.appendFailed) {
+ return html`
+
+
+ ${translateText("clan_modal.history_load_more_failed")}
+
+
this.load({ append: true })}
+ class="text-xs font-bold text-white/60 hover:text-white uppercase tracking-wider px-3 py-1.5 rounded-lg border border-white/10 hover:border-white/20 hover:bg-white/5 transition-colors"
+ >
+ ${translateText("leaderboard_modal.try_again")}
+
+
+ `;
+ }
+ // Sentinel drives auto-load; the spinner sits adjacent to it (not *as* it)
+ // so the sentinel node identity stays stable across pages — otherwise every
+ // fetch tears down and recreates the IntersectionObserver.
+ return html`
+
+
+ ${this.loadingMore ? renderLoadingSpinner() : ""}
+
+ `;
+ }
+
+ private renderGameRow(game: PublicPlayerGame): TemplateResult {
+ // getMapData() throws for unknown map values — guard so an unmapped server
+ // response doesn't tank the whole history view.
+ let mapWebpPath: string | null = null;
+ if (game.map) {
+ try {
+ mapWebpPath = terrainMapFileLoader.getMapData(
+ game.map as GameMapType,
+ ).webpPath;
+ } catch {
+ mapWebpPath = null;
+ }
+ }
+ const mapDisplayName = game.map ? (getMapName(game.map) ?? game.map) : null;
+
+ return html`
+
+ ${mapWebpPath
+ ? html`
+
+
+ ${mapDisplayName
+ ? html`
+ ${mapDisplayName}
+
`
+ : ""}
+
+ ${this.renderResultBadge(game)}
+
+
+ ${formatAbsoluteTime(game.start)}
+
+
`
+ : ""}
+
+
+ ${translateText("clan_modal.history_game_id")}:
+
+
+
+ this.showRanking(game.gameId)}
+ class="px-3 py-1.5 text-xs font-bold text-white/80 uppercase tracking-wider bg-white/10 hover:bg-white/20 border border-white/10 rounded-lg transition-colors"
+ >
+ ${translateText("game_list.ranking")}
+
+ this.watchReplay(game.gameId)}
+ class="px-3 py-1.5 text-xs font-bold text-white uppercase tracking-wider bg-malibu-blue hover:bg-aquarius active:bg-malibu-blue/80 rounded-lg transition-all"
+ >
+ ${translateText("clan_modal.history_watch_replay")}
+
+
+
+
+ ${this.renderField(
+ translateText("account_modal.games_clan_tag"),
+ game.clanTag ?? "—",
+ )}
+ ${this.renderField(
+ translateText("account_modal.games_username"),
+ game.username,
+ )}
+
+
+ ${this.renderField(
+ translateText("clan_modal.history_game_type"),
+ formatGameType(game),
+ )}
+ ${mapWebpPath
+ ? ""
+ : this.renderField(
+ translateText("clan_modal.history_map"),
+ mapDisplayName ?? "—",
+ )}
+ ${this.renderField(
+ translateText("clan_modal.history_players"),
+ game.totalPlayers === null ? "—" : `${game.totalPlayers}`,
+ )}
+ ${this.renderField(
+ translateText("clan_modal.history_duration"),
+ renderDuration(game.durationSeconds),
+ )}
+
+
+ `;
+ }
+
+ private renderField(label: string, value: string): TemplateResult {
+ return html`
+
+
+ ${label}
+
+
${value}
+
+ `;
+ }
+
+ // The player's own outcome. "incomplete" (no recorded winner) gets a neutral
+ // badge rather than collapsing into Defeat, so an unfinished game isn't
+ // mislabelled as a loss in a personal history.
+ private renderResultBadge(game: PublicPlayerGame): TemplateResult {
+ let label: string;
+ let tint: string;
+ if (game.result === "victory") {
+ label = translateText("clan_modal.history_result_victory");
+ tint = "text-white bg-green-600 border-green-500";
+ } else if (game.result === "defeat") {
+ label = translateText("clan_modal.history_result_defeat");
+ tint = "text-white bg-red-600 border-red-500";
+ } else {
+ label = translateText("account_modal.games_result_incomplete");
+ tint = "text-white bg-gray-500 border-gray-400";
+ }
+ return html`${label} `;
+ }
+}
diff --git a/src/client/components/clan/ClanGameHistoryView.ts b/src/client/components/clan/ClanGameHistoryView.ts
index 657e0c826..cc501f300 100644
--- a/src/client/components/clan/ClanGameHistoryView.ts
+++ b/src/client/components/clan/ClanGameHistoryView.ts
@@ -1,6 +1,6 @@
import { html, LitElement, type TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators.js";
-import { GameMapType, GameMode } from "../../../core/game/Game";
+import { GameMapType } from "../../../core/game/Game";
import {
type ClanGame,
type ClanGameFilter,
@@ -10,6 +10,12 @@ import { ClientEnv } from "../../ClientEnv";
import { terrainMapFileLoader } from "../../TerrainMapFileLoader";
import { getMapName, renderDuration, translateText } from "../../Utils";
import "../CopyButton";
+import {
+ formatAbsoluteTime,
+ formatDayHeader,
+ groupByDay,
+} from "../baseComponents/stats/GameHistoryDates";
+import { formatGameType, isFfa } from "../baseComponents/stats/GameTypeLabels";
import { renderLoadingSpinner, showToast } from "./ClanShared";
type FilterKey = ClanGameFilter | "all";
@@ -60,7 +66,7 @@ export class ClanGameHistoryView extends LitElement {
// triggered by unrelated state (e.g. `loadingMore` flipping) don't
// re-walk the accumulated list each time.
private groupedFor: ClanGame[] | null = null;
- private grouped: DayGroup[] = [];
+ private grouped: ReturnType> = [];
connectedCallback() {
super.connectedCallback();
@@ -279,7 +285,7 @@ export class ClanGameHistoryView extends LitElement {
// standalone date pills. Cached against the `games` reference; `load()`
// always assigns a fresh array, so identity comparison is safe.
if (this.groupedFor !== this.games) {
- this.grouped = groupGamesByDay(this.games);
+ this.grouped = groupByDay(this.games);
this.groupedFor = this.games;
}
const groups = this.grouped;
@@ -300,7 +306,7 @@ export class ClanGameHistoryView extends LitElement {
- ${group.games.map((game) => this.renderGameRow(game))}
+ ${group.items.map((game) => this.renderGameRow(game))}
`,
@@ -430,7 +436,7 @@ export class ClanGameHistoryView extends LitElement {
>
${this.renderField(
translateText("clan_modal.history_game_type"),
- this.formatGameType(game),
+ formatGameType(game),
)}
${mapWebpPath
? ""
@@ -585,132 +591,4 @@ export class ClanGameHistoryView extends LitElement {
}),
);
}
-
- // FFA / Duos / 7 Teams / Humans vs Nations / Ranked 1v1 — derived from
- // the same fields the bucket filter uses, so the label always agrees
- // with the active tab.
- private formatGameType(game: ClanGame): string {
- if (game.rankedType && game.rankedType !== "unranked") {
- return translateText("clan_modal.history_type_ranked", {
- ranked: game.rankedType,
- });
- }
- if (isFfa(game)) {
- return translateText("clan_modal.history_type_ffa");
- }
- const pt = game.playerTeams;
- if (pt === "Humans Vs Nations") {
- return translateText("clan_modal.history_type_hvn");
- }
- if (pt === "Duos" || pt === "Trios" || pt === "Quads") {
- return translateText(`clan_modal.history_type_${pt.toLowerCase()}`);
- }
- if (pt && /^\d+$/.test(pt)) {
- return translateText("clan_modal.history_type_n_teams", {
- count: Number(pt),
- });
- }
- return translateText("clan_modal.history_type_team");
- }
-}
-
-// FFA is "no team grouping". Match the server's `GameMode.FFA` enum
-// literal first, but fall back to absent `playerTeams` so a row that
-// arrives without the mode field (older row, server bug) still labels
-// as FFA instead of silently degrading to "Team" — which would
-// disagree with the FFA filter bucket that already routed it here.
-function isFfa(game: ClanGame): boolean {
- if (game.mode === GameMode.FFA) return true;
- if (
- game.mode === undefined &&
- (game.playerTeams === null || game.playerTeams === undefined)
- ) {
- return true;
- }
- return false;
-}
-
-function formatAbsoluteTime(iso: string): string {
- const date = new Date(iso);
- if (!Number.isFinite(date.getTime())) return iso;
- const now = new Date();
- const time = date.toLocaleTimeString(undefined, {
- hour: "2-digit",
- minute: "2-digit",
- });
- const sameDay =
- date.getFullYear() === now.getFullYear() &&
- date.getMonth() === now.getMonth() &&
- date.getDate() === now.getDate();
- if (sameDay) {
- return translateText("clan_modal.history_today_at", { time });
- }
- return `${date.toLocaleDateString()} ${time}`;
-}
-
-type DayGroup = { day: string; games: ClanGame[] };
-
-// Groups games by local-day key while preserving server order. Server
-// ordering is already newest-first, so within a group we just keep the
-// arrival order.
-function groupGamesByDay(games: ClanGame[]): DayGroup[] {
- const groups: DayGroup[] = [];
- for (const g of games) {
- const day = dayKey(g.start);
- const last = groups[groups.length - 1];
- if (last && last.day === day) {
- last.games.push(g);
- } else {
- groups.push({ day, games: [g] });
- }
- }
- return groups;
-}
-
-function dayKey(iso: string): string {
- const d = new Date(iso);
- if (!Number.isFinite(d.getTime())) return iso;
- // Use local-time YYYY-MM-DD so headers line up with the user's clock,
- // not UTC midnight (which would split late-night games into a "next
- // day" group for most timezones).
- const y = d.getFullYear();
- const m = String(d.getMonth() + 1).padStart(2, "0");
- const day = String(d.getDate()).padStart(2, "0");
- return `${y}-${m}-${day}`;
-}
-
-// Indexed by Date.getMonth() (0–11). Kept as a const list rather than
-// a switch so the translation pipeline picks up every key from a single
-// place.
-const MONTH_KEYS = [
- "common.month_jan",
- "common.month_feb",
- "common.month_mar",
- "common.month_apr",
- "common.month_may",
- "common.month_jun",
- "common.month_jul",
- "common.month_aug",
- "common.month_sep",
- "common.month_oct",
- "common.month_nov",
- "common.month_dec",
-] as const;
-
-function formatDayHeader(day: string): string {
- const d = new Date(`${day}T00:00:00`);
- if (!Number.isFinite(d.getTime())) return day;
- const now = new Date();
- const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
- const dayStart = new Date(d.getFullYear(), d.getMonth(), d.getDate());
- const diffDays = Math.round(
- (today.getTime() - dayStart.getTime()) / (24 * 60 * 60 * 1000),
- );
- if (diffDays === 0) return translateText("clan_modal.history_today");
- if (diffDays === 1) return translateText("clan_modal.history_yesterday");
- // "17 May 2026" — weekday dropped (no translation coverage) and the
- // month rendered through our own translation keys instead of
- // toLocaleDateString so other locales can swap it cleanly.
- const month = translateText(MONTH_KEYS[d.getMonth()]);
- return `${d.getDate()} ${month} ${d.getFullYear()}`;
}
diff --git a/src/core/ApiSchemas.ts b/src/core/ApiSchemas.ts
index 828306b2c..bb8dad117 100644
--- a/src/core/ApiSchemas.ts
+++ b/src/core/ApiSchemas.ts
@@ -2,7 +2,7 @@ import { z } from "zod";
import { base64urlToUuid } from "./Base64";
import { ClanTagSchema } from "./Schemas";
import { BigIntStringSchema, PlayerStatsSchema } from "./StatsSchemas";
-import { Difficulty, GameMode, GameType, RankedType } from "./game/Game";
+import { Difficulty, GameMode, RankedType } from "./game/Game";
function stripClanTagFromUsername(username: string): string {
return username.replace(/^\s*\[[a-zA-Z0-9]{2,5}\]\s*/u, "").trim();
@@ -154,25 +154,64 @@ export const PlayerStatsTreeSchema = z.object({
});
export type PlayerStatsTree = z.infer;
-export const PlayerGameSchema = z.object({
- gameId: z.string(),
- start: z.iso.datetime(),
- mode: z.enum(GameMode),
- type: z.enum(GameType),
- map: z.string(),
- difficulty: z.enum(Difficulty),
- clientId: z.string().optional(),
-});
-export type PlayerGame = z.infer;
-
export const PlayerProfileSchema = z.object({
createdAt: z.iso.datetime(),
user: DiscordUserSchema.optional(),
- games: PlayerGameSchema.array(),
stats: PlayerStatsTreeSchema,
});
export type PlayerProfile = z.infer;
+// Mode buckets for GET /public/player/:publicId/games — mirrors the clan
+// game-history filter (see ClanGameFilter). Resolved server-side off the
+// games join (mode / ranked_type / player_teams).
+export const PlayerGameModeFilters = ["ffa", "team", "hvn", "ranked"] as const;
+export const PlayerGameModeFilterSchema = z.enum(PlayerGameModeFilters);
+export type PlayerGameModeFilter = z.infer;
+
+// Game-type split — orthogonal to the mode filter. Matches games.type.
+export const PlayerGameTypeFilters = [
+ "public",
+ "private",
+ "singleplayer",
+] as const;
+export const PlayerGameTypeFilterSchema = z.enum(PlayerGameTypeFilters);
+export type PlayerGameTypeFilter = z.infer;
+
+// "incomplete" covers games with no recorded winner (winnerType IS NULL).
+export const PlayerGameResultSchema = z.enum([
+ "victory",
+ "defeat",
+ "incomplete",
+]);
+export type PlayerGameResult = z.infer;
+
+export const PublicPlayerGameSchema = z.object({
+ gameId: z.string(),
+ start: z.iso.datetime(),
+ durationSeconds: z.number().int().nonnegative(),
+ map: z.string(),
+ mode: z.string(),
+ type: z.string(),
+ playerTeams: z.string().nullable(),
+ rankedType: z.string(),
+ result: PlayerGameResultSchema,
+ totalPlayers: z.number().int().nonnegative().nullable(),
+ username: z.string(),
+ clanTag: z.string().nullable(),
+});
+export type PublicPlayerGame = z.infer;
+
+export const PublicPlayerGamesResponseSchema = z.object({
+ results: PublicPlayerGameSchema.array(),
+ // Opaque continuation token. Round-trip verbatim as the `cursor` query
+ // parameter to fetch the next page; never construct or parse it. `null`
+ // means the server has no more rows to serve.
+ nextCursor: z.string().nullable(),
+});
+export type PublicPlayerGamesResponse = z.infer<
+ typeof PublicPlayerGamesResponseSchema
+>;
+
export const PlayerLeaderboardEntrySchema = z.object({
rank: z.number(),
playerId: z.string(),
diff --git a/tests/ApiSchemas.test.ts b/tests/ApiSchemas.test.ts
new file mode 100644
index 000000000..19c04ce51
--- /dev/null
+++ b/tests/ApiSchemas.test.ts
@@ -0,0 +1,176 @@
+import {
+ PlayerGameModeFilterSchema,
+ PlayerGameResultSchema,
+ PlayerGameTypeFilterSchema,
+ PlayerProfileSchema,
+ PublicPlayerGameSchema,
+ PublicPlayerGamesResponseSchema,
+} from "../src/core/ApiSchemas";
+
+describe("PlayerProfileSchema", () => {
+ const base = {
+ createdAt: "2024-01-15T12:00:00.000Z",
+ stats: {},
+ };
+
+ it("accepts a profile without a games array (moved to its own endpoint)", () => {
+ const result = PlayerProfileSchema.safeParse(base);
+ expect(result.success).toBe(true);
+ });
+
+ it("ignores a legacy games field rather than failing the parse", () => {
+ const result = PlayerProfileSchema.safeParse({
+ ...base,
+ games: [{ gameId: "g1" }],
+ });
+ // Zod strips unknown keys by default, so an old server response that still
+ // carries games[] parses cleanly without the field surfacing.
+ expect(result.success).toBe(true);
+ if (result.success) {
+ expect("games" in result.data).toBe(false);
+ }
+ });
+
+ it("rejects a non-ISO createdAt", () => {
+ expect(
+ PlayerProfileSchema.safeParse({ ...base, createdAt: "yesterday" })
+ .success,
+ ).toBe(false);
+ });
+});
+
+describe("PlayerGameModeFilterSchema", () => {
+ it.each(["ffa", "team", "hvn", "ranked"])("accepts %s", (value) => {
+ expect(PlayerGameModeFilterSchema.safeParse(value).success).toBe(true);
+ });
+
+ it("rejects 'all' (filter omission is encoded by absence, not a value)", () => {
+ expect(PlayerGameModeFilterSchema.safeParse("all").success).toBe(false);
+ });
+});
+
+describe("PlayerGameTypeFilterSchema", () => {
+ it.each(["public", "private", "singleplayer"])("accepts %s", (value) => {
+ expect(PlayerGameTypeFilterSchema.safeParse(value).success).toBe(true);
+ });
+
+ it("rejects an unknown type value", () => {
+ expect(PlayerGameTypeFilterSchema.safeParse("ranked").success).toBe(false);
+ });
+});
+
+describe("PlayerGameResultSchema", () => {
+ it.each(["victory", "defeat", "incomplete"])("accepts %s", (value) => {
+ expect(PlayerGameResultSchema.safeParse(value).success).toBe(true);
+ });
+
+ it("rejects an unknown result value", () => {
+ expect(PlayerGameResultSchema.safeParse("win").success).toBe(false);
+ });
+});
+
+describe("PublicPlayerGameSchema", () => {
+ const validGame = {
+ gameId: "g1",
+ start: "2024-06-01T00:00:00.000Z",
+ durationSeconds: 1234,
+ map: "World",
+ mode: "Team",
+ type: "Public",
+ playerTeams: "Duos",
+ rankedType: "unranked",
+ result: "victory" as const,
+ totalPlayers: 8,
+ username: "alice",
+ clanTag: "ABC",
+ };
+
+ it("accepts a fully-populated game", () => {
+ expect(PublicPlayerGameSchema.safeParse(validGame).success).toBe(true);
+ });
+
+ it("accepts clanTag: null (not repping a clan)", () => {
+ expect(
+ PublicPlayerGameSchema.safeParse({ ...validGame, clanTag: null }).success,
+ ).toBe(true);
+ });
+
+ it("rejects a missing username", () => {
+ const withoutUsername: Record = { ...validGame };
+ delete withoutUsername.username;
+ expect(PublicPlayerGameSchema.safeParse(withoutUsername).success).toBe(
+ false,
+ );
+ });
+
+ it("accepts playerTeams: null (FFA / non-team games)", () => {
+ expect(
+ PublicPlayerGameSchema.safeParse({ ...validGame, playerTeams: null })
+ .success,
+ ).toBe(true);
+ });
+
+ it("accepts totalPlayers: null (historical rows)", () => {
+ expect(
+ PublicPlayerGameSchema.safeParse({ ...validGame, totalPlayers: null })
+ .success,
+ ).toBe(true);
+ });
+
+ it("rejects a negative durationSeconds", () => {
+ expect(
+ PublicPlayerGameSchema.safeParse({ ...validGame, durationSeconds: -1 })
+ .success,
+ ).toBe(false);
+ });
+
+ it("rejects a non-ISO start", () => {
+ expect(
+ PublicPlayerGameSchema.safeParse({ ...validGame, start: "June 1 2024" })
+ .success,
+ ).toBe(false);
+ });
+});
+
+describe("PublicPlayerGamesResponseSchema", () => {
+ const validGame = {
+ gameId: "g1",
+ start: "2024-06-01T00:00:00.000Z",
+ durationSeconds: 1234,
+ map: "World",
+ mode: "Free For All",
+ type: "Public",
+ playerTeams: null,
+ rankedType: "unranked",
+ result: "defeat" as const,
+ totalPlayers: 20,
+ username: "bob",
+ clanTag: null,
+ };
+
+ it("accepts a non-empty page with an opaque cursor", () => {
+ const result = PublicPlayerGamesResponseSchema.safeParse({
+ results: [validGame],
+ nextCursor: "opaque-cursor-abc123",
+ });
+ expect(result.success).toBe(true);
+ if (result.success) {
+ expect(result.data.nextCursor).toBe("opaque-cursor-abc123");
+ }
+ });
+
+ it("accepts an empty page with a null cursor", () => {
+ expect(
+ PublicPlayerGamesResponseSchema.safeParse({
+ results: [],
+ nextCursor: null,
+ }).success,
+ ).toBe(true);
+ });
+
+ it("rejects when nextCursor is missing (must be string or null)", () => {
+ expect(
+ PublicPlayerGamesResponseSchema.safeParse({ results: [] }).success,
+ ).toBe(false);
+ });
+});