Show map rankings for player personal records

This commit is contained in:
2026-10-08 00:32:32 -04:00
parent 3b270f79a7
commit 8de9247ff2
7 changed files with 108 additions and 6 deletions
+32
View File
@@ -75,6 +75,38 @@ it('resolves tied bests by earliest completion, receipt time for unknown endings
}
});
it('ranks each map best against distinct players using leaderboard ties, qualification, and game boundaries', async () => {
const { db } = await import('../../src/lib/server/db/index.js');
const handle = db();
seed(handle, 1, { round: 20, kills: 200, score: 2000 });
seed(handle, 2, { guid: '202', round: 30, kills: 100, score: 3000 });
seed(handle, 3, { guid: '202', round: 30, kills: 150, score: 2000 });
seed(handle, 4, { guid: '303', round: 30, kills: 300, score: 2000 });
seed(handle, 5, { guid: '404', round: 10, kills: 200, score: 1000 });
seed(handle, 6, { map: 'moon', round: 5, kills: 10, score: 10 });
seed(handle, 7, { game: 't6', round: 6, kills: 6, score: 6 });
seed(handle, 8, { game: 't6', guid: '202', round: 7, kills: 7, score: 7 });
seed(handle, 9, { guid: 'active', status: 'active', round: 99, kills: 9999, score: 9999 });
seed(handle, 10, { guid: 'interrupted', status: 'interrupted', round: 99, kills: 9999, score: 9999 });
seed(handle, 11, { guid: 'unrecorded', hasStats: 0, round: 99, kills: 9999, score: 9999 });
seed(handle, 12, { guid: 'unqualified', round: 1, kills: 9999, score: 9999 });
handle.prepare('UPDATE leaderboard_matches SET start_players=2 WHERE id IN (1,6,7)').run();
handle.prepare('UPDATE leaderboard_matches SET start_players=4 WHERE id IN (2,3,4,5,8)').run();
const { getPlayerProfile } = await import('../../src/lib/server/fleet/player-profile.js');
const { getPlayerLeaderboardEntry } = await import('../../src/lib/server/fleet/leaderboard.js');
const profile = getPlayerProfile('101')!;
expect(profile.maps.find(map => map.key === 't5:theater')?.ranks).toEqual({ highestRound: 3, bestKills: 2, bestScore: 2 });
expect(profile.maps.find(map => map.key === 't5:moon')?.ranks).toEqual({ highestRound: 1, bestKills: 1, bestScore: 1 });
expect(profile.maps.find(map => map.key === 't6:theater')?.ranks).toEqual({ highestRound: 2, bestKills: 2, bestScore: 2 });
for (const map of profile.maps) for (const metric of ['highestRound', 'bestKills', 'bestScore'] as const) {
expect(map.ranks[metric]).toBe(getPlayerLeaderboardEntry('101', { game: map.game, map: map.key, metric })?.rank);
}
expect(getPlayerProfile('101', 0, { game: 't6', map: 't6:theater', players: 2 })?.maps).toEqual(profile.maps);
seed(handle, 13, { guid: 'new-leader', round: 40, kills: 400, score: 4000 });
expect(getPlayerProfile('101')?.maps.find(map => map.key === 't5:theater')?.ranks)
.toEqual({ highestRound: 4, bestKills: 3, bestScore: 3 });
});
it('never uses unfinished, unsupported, nonqualifying or unrecorded stats as evidence', async () => {
const { db } = await import('../../src/lib/server/db/index.js');
const handle = db();