Add global match history and ending timestamps

This commit is contained in:
2026-09-20 21:44:36 -04:00
parent fc681c56c9
commit 3c8b5b2e40
8 changed files with 68 additions and 14 deletions
+20 -3
View File
@@ -45,7 +45,7 @@ it('records server match counts, unique rejoins, duration, and final round durab
const { serverMatchHistory } = await import('../../src/lib/server/fleet/match-history.js');
expect(serverMatchHistory(server)).toEqual({ total: 1, matches: [expect.objectContaining({
status: 'completed', startPlayers: 2, uniquePlayers: 3, endPlayers: 1,
durationMs: 3000, finalRound: 7
durationMs: 3000, finalRound: 7, endedAt: '2026-09-18T20:00:03.000Z'
})] });
expect(serverMatchHistory('other')).toEqual({ total: 0, matches: [] });
});
@@ -58,8 +58,8 @@ it('preserves unknown boundaries and distinguishes empty rosters from missing ob
await report('game_start');
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 }),
expect.objectContaining({ status: 'interrupted', startPlayers: 0, endPlayers: null, durationMs: null, finalRound: null }),
expect.objectContaining({ status: 'active', startPlayers: 1, endPlayers: null, durationMs: null, finalRound: null, endedAt: null }),
expect.objectContaining({ status: 'interrupted', startPlayers: 0, endPlayers: null, durationMs: null, finalRound: null, endedAt: null }),
expect.objectContaining({ status: 'completed', startPlayers: null, uniquePlayers: 1, endPlayers: 0, durationMs: null, finalRound: 6 })
]);
const { GET } = await import('../../src/routes/api/servers/[name]/matches/+server.js');
@@ -70,6 +70,23 @@ it('preserves unknown boundaries and distinguishes empty rosters from missing ob
expect(GET({ params: { name: server }, url: new URL('http://localhost/?limit=-1') }).status).toBe(400);
});
it('lists global matches newest first across servers with totals and ending timestamps', async () => {
await report('game_start');
await report('game_end', 8);
await report('game_start', 0, [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);
expect(all.matches).toEqual([
expect.objectContaining({ server: 't6_zombie_town_1', endedAt: null }),
expect.objectContaining({ server, endedAt: '2026-09-18T20:00:01.000Z' })
]);
const limited = await GET({ url: new URL('http://localhost/api/matches?limit=1') }).json();
expect(limited.total).toBe(2);
expect(limited.matches).toEqual([all.matches[0]]);
expect(GET({ url: new URL('http://localhost/api/matches?limit=0') }).status).toBe(400);
});
async function records(guid = '2741626') {
const { db } = await import('../../src/lib/server/db/index.js');
return db().prepare('SELECT * FROM leaderboard_match_players WHERE guid = ? ORDER BY match_id').all(guid) as Array<{