Exclude round one records from match history and statistics

This commit is contained in:
2026-09-21 18:07:30 -04:00
parent 50c81456c4
commit 424d6cefb6
12 changed files with 120 additions and 24 deletions
+38
View File
@@ -34,6 +34,42 @@ async function matches() {
}>;
}
it('starts counting at round 2, preserves early stats, and excludes players who only stayed for round 1', async () => {
const { getLeaderboard } = await import('../../src/lib/server/fleet/leaderboard.js');
const { getPlayerProfile } = await import('../../src/lib/server/fleet/player-profile.js');
const { serverMatchHistory } = await import('../../src/lib/server/fleet/match-history.js');
const departed = player('round-one-only', { kills: 5 });
await report('game_start', 0, [player(), departed]);
await report('round_change', 1, [player(undefined, { kills: 6, score: 1000 }), departed]);
expect(getLeaderboard()).toMatchObject({ entries: [], maps: [], total: 0, summary: { players: 0, matches: 0, kills: 0 } });
expect(getPlayerProfile('t5', player().guid)).toBeNull();
expect(serverMatchHistory()).toEqual({ total: 0, matches: [] });
await report('round_change', 2, [player(undefined, { kills: 6, score: 500 })]);
expect(getLeaderboard()).toMatchObject({ total: 1, entries: [expect.objectContaining({
highestRound: 2, kills: 6, bestScore: 1000, roundsSurvived: 1, gamesPlayed: 1, gamesCompleted: 0
})], summary: { players: 1, matches: 1, kills: 6 } });
expect(getPlayerProfile('t5', departed.guid)).toBeNull();
await report('game_end', 2, [player(undefined, { kills: 10 })]);
const board = getLeaderboard();
const profile = getPlayerProfile('t5', player().guid);
const history = serverMatchHistory();
expect(history).toMatchObject({ total: 1, matches: [{ startPlayers: 2, uniquePlayers: 2, durationMs: 3000, finalRound: 2 }] });
await report('game_start');
await report('game_end', 1, [player(undefined, { kills: 5000 })]);
await report('game_start', 0, []);
await report('game_end', 1, []);
const { closeDb } = await import('../../src/lib/server/db/index.js');
closeDb();
expect(getLeaderboard()).toEqual(board);
// Identity timestamps still reflect live presence, but gameplay records do not change.
expect(getPlayerProfile('t5', player().guid)).toMatchObject({ stats: profile!.stats, maps: profile!.maps, matches: profile!.matches });
expect(serverMatchHistory()).toEqual(history);
const { GET } = await import('../../src/routes/api/matches/+server.js');
expect(await GET({ url: new URL('http://localhost/api/matches?limit=1') }).json()).toEqual(history);
const { GET: serverGET } = await import('../../src/routes/api/servers/[name]/matches/+server.js');
expect(await serverGET({ params: { name: server }, url: new URL('http://localhost/?limit=1') }).json()).toEqual(history);
});
it('records server match counts, unique rejoins, duration, and final round durably', async () => {
await report('game_start', 0, [player('a'), player('b')]);
await report('round_change', 2, [player('b'), player('c')]);
@@ -56,6 +92,7 @@ it('preserves unknown boundaries and distinguishes empty rosters from missing ob
await report('game_start', 0, []);
await report('round_change', 2);
await report('game_start');
await report('round_change', 2);
const { serverMatchHistory } = await import('../../src/lib/server/fleet/match-history.js');
expect(serverMatchHistory(server).matches).toEqual([
expect.objectContaining({ status: 'active', startPlayers: 1, endPlayers: null, durationMs: null, finalRound: null, endedAt: null }),
@@ -74,6 +111,7 @@ it('lists global matches newest first across servers with totals and ending time
await report('game_start');
await report('game_end', 8);
await report('game_start', 0, [player()], 't6_zombie_town_1', 'zm_transit');
await report('round_change', 2, [player()], 't6_zombie_town_1', 'zm_transit');
const { GET } = await import('../../src/routes/api/matches/+server.js');
const all = await GET({ url: new URL('http://localhost/api/matches') }).json();
expect(all.total).toBe(2);