Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions packages/backend/src/persistence/gameHistoryRepository.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import assert from 'node:assert/strict';
import test from 'node:test';

import { zDatabaseGame, zFinishedGameRecord } from '@ih3t/shared';

test(`parses legacy tournament replay records with defaulted timeout, pending extension, and profile fields`, () => {
const legacyTournamentGame = {
id: `game-1`,
version: 3,
sessionId: `session-1`,
startedAt: 1_700_000_000_000,
finishedAt: 1_700_000_120_000,
players: [
{
playerId: `player-left`,
displayName: `Left`,
profileId: `profile-left`,
elo: null,
eloChange: null,
},
{
playerId: `player-right`,
displayName: `Right`,
profileId: `profile-right`,
elo: null,
eloChange: null,
},
],
playerTiles: {
'player-left': { color: `#fbbf24` },
'player-right': { color: `#38bdf8` },
},
gameOptions: {
visibility: `public`,
rated: false,
firstPlayer: `random`,
timeControl: {
mode: `unlimited`,
},
},
moves: [],
moveCount: 0,
gameResult: {
winningPlayerId: `player-left`,
durationMs: 120_000,
reason: `six-in-a-row`,
},
tournament: {
tournamentId: `tournament-1`,
tournamentName: `Spring Major`,
matchId: `match-1`,
bracket: `winners`,
round: 1,
order: 1,
bestOf: 1,
currentGameNumber: 1,
leftWins: 1,
rightWins: 0,
matchJoinTimeoutMs: 300_000,
matchExtensionMs: 300_000,
leftDisplayName: `Left`,
rightDisplayName: `Right`,
resultType: `played`,
},
};

const parsedDatabaseGame = zDatabaseGame.parse(legacyTournamentGame);
assert.equal(parsedDatabaseGame.tournament?.pendingExtension, false);
assert.equal(parsedDatabaseGame.tournament?.matchJoinTimeoutInMs, null);
assert.equal(parsedDatabaseGame.tournament?.leftProfileId, null);
assert.equal(parsedDatabaseGame.tournament?.rightProfileId, null);

const parsedReplay = zFinishedGameRecord.parse(parsedDatabaseGame);
assert.equal(parsedReplay.tournament?.pendingExtension, false);
assert.equal(parsedReplay.tournament?.matchJoinTimeoutInMs, null);
assert.equal(parsedReplay.tournament?.leftProfileId, null);
assert.equal(parsedReplay.tournament?.rightProfileId, null);
});
13 changes: 9 additions & 4 deletions packages/shared/src/tournaments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,17 @@ export const zSessionTournamentInfo = z.object({
.nonnegative(),
matchExtensionMs: z.number().int()
.nonnegative(),
pendingExtension: z.boolean(),
matchJoinTimeoutInMs: z.number().int().nullable(),
pendingExtension: z.boolean().default(false),
matchJoinTimeoutInMs: z.number().int()
Comment thread
alfaoz marked this conversation as resolved.
.nonnegative()
.nullable()
.default(null),
leftDisplayName: z.string().nullable(),
rightDisplayName: z.string().nullable(),
leftProfileId: zIdentifier.nullable(),
rightProfileId: zIdentifier.nullable(),
leftProfileId: zIdentifier.nullable()
.default(null),
rightProfileId: zIdentifier.nullable()
.default(null),
});
export type SessionTournamentInfo = z.infer<typeof zSessionTournamentInfo>;

Expand Down
Loading