Remove development previews and complete hall of fame, match history, official results, and multi-kill API integration. Fix active match pagination and team-ready controls, preserve basic scoreboards, and recover statistics when Riot archives arrive. Use bounded in-process cache invalidation retries and add the Riot match lookup index migration with regression coverage.
97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
formatOfficialMatchResult,
|
|
getMainLane,
|
|
parseLeaderboardSort,
|
|
rankLeaderboardByLane,
|
|
sortLeaderboardRows,
|
|
} from '../src/lib/internal-stats-presentation.ts';
|
|
|
|
const rows = [
|
|
{ id: 'many', games: 90, winRate: 46, kda: 2.1 },
|
|
{ id: 'steady', games: 40, winRate: 55, kda: 3.4 },
|
|
{ id: 'lucky', games: 2, winRate: 100, kda: 9 },
|
|
{ id: 'sharp', games: 12, winRate: 55, kda: 4.2 },
|
|
];
|
|
const ids = (list: typeof rows) => list.map(({ id }) => id);
|
|
|
|
test('keeps the server order for the default sort and ignores unknown values', () => {
|
|
assert.equal(parseLeaderboardSort(null), 'games');
|
|
assert.equal(parseLeaderboardSort('nope'), 'games');
|
|
assert.equal(parseLeaderboardSort('kda'), 'kda');
|
|
assert.deepEqual(ids(sortLeaderboardRows(rows, 'games')), ids(rows));
|
|
});
|
|
|
|
test('ranks small samples after players with enough games', () => {
|
|
assert.deepEqual(ids(sortLeaderboardRows(rows, 'winRate')), [
|
|
'steady',
|
|
'sharp',
|
|
'many',
|
|
'lucky',
|
|
]);
|
|
assert.deepEqual(ids(sortLeaderboardRows(rows, 'kda')), [
|
|
'sharp',
|
|
'steady',
|
|
'many',
|
|
'lucky',
|
|
]);
|
|
});
|
|
|
|
test('ranks one lane by its own win rate and sample size', () => {
|
|
const player = (
|
|
id: string,
|
|
byLane: Parameters<typeof rankLeaderboardByLane>[0][number]['byLane'],
|
|
) => ({ id, games: 50, wins: 25, losses: 25, winRate: 50, kda: 3, byLane });
|
|
const ranked = rankLeaderboardByLane(
|
|
[
|
|
player('offlane', { MIDDLE: { games: 20, wins: 18, kda: 5 } }),
|
|
player('lucky', { TOP: { games: 2, wins: 2, kda: 9 } }),
|
|
player('steady', { TOP: { games: 10, wins: 6, kda: 3 } }),
|
|
player('sharp', { TOP: { games: 6, wins: 4, kda: 4 } }),
|
|
],
|
|
'TOP',
|
|
);
|
|
|
|
assert.deepEqual(
|
|
ranked.map(({ id }) => id),
|
|
['sharp', 'steady', 'lucky'],
|
|
);
|
|
assert.deepEqual(
|
|
{ games: ranked[0].games, wins: ranked[0].wins, losses: ranked[0].losses, winRate: ranked[0].winRate },
|
|
{ games: 6, wins: 4, losses: 2, winRate: 67 },
|
|
);
|
|
});
|
|
|
|
test('picks the most played lane', () => {
|
|
assert.equal(
|
|
getMainLane({
|
|
TOP: { games: 3, wins: 1, kda: 2 },
|
|
BOTTOM: { games: 8, wins: 4, kda: 3 },
|
|
}),
|
|
'BOTTOM',
|
|
);
|
|
assert.equal(getMainLane({}), undefined);
|
|
});
|
|
|
|
test('displays official tournament winners by ID and keeps older records neutral', () => {
|
|
const champion = 'winner' as import('@lolympus/contracts').TeamId;
|
|
assert.equal(formatOfficialMatchResult({
|
|
type: 'official',
|
|
competitionId: 'tournament' as import('@lolympus/contracts').CompetitionId,
|
|
sourceRevision: 10,
|
|
phase: 'completed',
|
|
formatType: 'double-elimination',
|
|
completedSeriesCount: 2,
|
|
teams: [{ teamId: champion, name: '별무리' }],
|
|
outcome: {
|
|
type: 'double-elimination',
|
|
championTeamId: champion,
|
|
placements: [{ rank: 1, teamId: champion }],
|
|
completedAt: '2026-11-10T00:00:00Z',
|
|
},
|
|
}), '우승 · 별무리');
|
|
assert.equal(formatOfficialMatchResult({ type: 'legacy' }), '과거 기록');
|
|
assert.equal(formatOfficialMatchResult(undefined), '공식 결과 확인 불가');
|
|
});
|