37 lines
1.6 KiB
TypeScript
37 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
buildVoiceLeaderboard,
|
|
buildXpLeaderboard,
|
|
} from "@/lib/leaderboard/ranking";
|
|
|
|
describe("member leaderboard standing", () => {
|
|
test("keeps shared XP rank when filtering to one Discord ID", () => {
|
|
const leaderboard = buildXpLeaderboard([
|
|
{ userId: "one", username: "one", displayName: null, level: 2, totalXp: "1000" },
|
|
{ userId: "two", username: "two", displayName: null, level: 2, totalXp: "1000" },
|
|
{ userId: "three", username: "three", displayName: null, level: 1, totalXp: "500" },
|
|
{ userId: "zero", username: "zero", displayName: null, level: 0, totalXp: "499" },
|
|
], 1, "two");
|
|
|
|
expect(leaderboard.rows).toHaveLength(1);
|
|
expect(leaderboard.rows[0]?.rank).toBe(1);
|
|
expect(leaderboard.rows.some((row) => row.userId === "zero")).toBeFalse();
|
|
});
|
|
|
|
test("sums only current voice channels before assigning rank", () => {
|
|
const leaderboard = buildVoiceLeaderboard([
|
|
{ userId: "one", username: "one", displayName: null, channelId: "current-a", totalSeconds: "30" },
|
|
{ userId: "one", username: "one", displayName: null, channelId: "current-b", totalSeconds: "45" },
|
|
{ userId: "one", username: "one", displayName: null, channelId: "deleted", totalSeconds: "999" },
|
|
{ userId: "two", username: "two", displayName: null, channelId: "current-a", totalSeconds: "60" },
|
|
], ["current-a", "current-b"], 1, undefined, "one");
|
|
|
|
expect(leaderboard.rows).toHaveLength(1);
|
|
expect(leaderboard.rows[0]).toMatchObject({
|
|
userId: "one",
|
|
totalSeconds: "75",
|
|
rank: 1,
|
|
});
|
|
});
|
|
});
|