Reuse leaderboard aggregates and add repeatable benchmarks

This commit is contained in:
2026-10-01 12:33:11 -04:00
parent f10345ae79
commit 221c4c10cf
5 changed files with 403 additions and 38 deletions
+19 -1
View File
@@ -193,6 +193,9 @@ describe('persisted leaderboard queries', () => {
expect(search.entries.map(entry => [entry.name, entry.rank])).toEqual([['Casey', 3]]);
expect(search.total).toBe(1);
expect(search.summary).toEqual(board.summary);
expect(getLeaderboard({ game: 't5', q: 'no matching player' })).toMatchObject({
entries: [], total: 0, summary: board.summary, maps: board.maps
});
expect(getLeaderboard({ game: 't5', metric: 'kills', limit: 1, offset: 1 }).entries[0])
.toMatchObject({ name: 'Blake', rank: 2 });
expect(getLeaderboard({ q: '303' }).entries[0]).toMatchObject({ name: 'Casey', rank: 4 });
@@ -226,7 +229,22 @@ describe('persisted leaderboard queries', () => {
expect(first.total).toBe(4);
expect(second.total).toBe(4);
expect(second.summary).toEqual(first.summary);
expect(getLeaderboard({ metric: 'kills', limit: 2, offset: 4 }).entries).toEqual([]);
expect(getLeaderboard({ metric: 'kills', limit: 2, offset: 4 })).toMatchObject({
entries: [], total: first.total, summary: first.summary, maps: first.maps
});
});
it('keeps recorded participation in summaries when an identity is unavailable for display', async () => {
const handle = await seedRecords();
const { getLeaderboard } = await import('../../src/lib/server/fleet/leaderboard.js');
const original = getLeaderboard();
handle.prepare("DELETE FROM leaderboard_players WHERE guid = '101'").run();
const board = getLeaderboard();
expect(board.total).toBe(original.total - 1);
expect(board.entries.some(entry => entry.guid === '101')).toBe(false);
expect(board.summary).toEqual(original.summary);
expect(board.maps).toEqual(original.maps);
expect(getLeaderboard({ q: '101' })).toMatchObject({ entries: [], total: 0, summary: original.summary });
});
it('ignores unsupported games in identities, totals, rankings and map options', async () => {