Skip to content

Commit b95df14

Browse files
committed
Fix tests and finalize streak-based leaderboard logic
1 parent 3b632a0 commit b95df14

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

Frontend/src/components/charts/__tests__/test_getTopContributorsAndRepos.test.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,40 @@ import { describe, it, expect } from "vitest";
1212
describe("getTopContributorsAndRepos", () => {
1313
// mock JSON data so that Lint passes
1414
const mockJSON = {
15-
"repo1": {
16-
issues: { "alice": { total_issues_opened: 2 }, "bob": { total_issues_opened: 1 } },
15+
repo1: {
16+
issues: {
17+
alice: { currentStreak: 2, total_issues_closed: 2 },
18+
bob: { currentStreak: 1, total_issues_closed: 1 }
1719
},
18-
"repo2": {
19-
pull_requests: { "charlie": { total_prs_opened: 4 } }
20+
},
21+
repo2: {
22+
issues: {
23+
charlie: { currentStreak: 3, total_issues_closed: 4 }
2024
}
21-
};
25+
}
26+
};
2227

2328

24-
it("counts contributor activity and sorts correctly", () => {
29+
it("sorts contributors based on streak correctly", () => {
2530
const {topContributors} = getTopContributorsAndRepos(mockJSON, 5);
26-
// charlie: 4, alicce: 2, bob: 1
31+
// charlie: 3, alice: 2, bob: 1 (based on streaks in mock data)
2732
expect(topContributors).toEqual(
2833
expect.arrayContaining([
29-
expect.objectContaining({ name: "charlie", count: 4 }),
30-
expect.objectContaining({ name: "alice", count: 2 }),
31-
expect.objectContaining({ name: "bob", count: 1 }),
34+
expect.objectContaining({ name: "charlie", currentStreak: 3 }),
35+
expect.objectContaining({ name: "alice", currentStreak: 2 }),
36+
expect.objectContaining({ name: "bob", currentStreak: 1 }),
3237
])
3338
);
3439
});
3540

36-
it("counts repository activity and sorts correctly", () => {
41+
it("sorts repositories based on streak and active members correctly", () => {
3742
const { topRepos } =
3843
getTopContributorsAndRepos(mockJSON, 5);
3944

40-
// repo1: 3 (2 from alice + 1 from bob), repo2: 4 (from charlie)
45+
// repo2: streak 3 (1 member), repo1: streak 2 (2 members)
4146
expect(topRepos).toEqual([
42-
{ name: "repo2", count: 4 },
43-
{ name: "repo1", count: 3},
47+
{ name: "repo2", streak: 3, activeMembers: 1 },
48+
{ name: "repo1", streak: 2, activeMembers: 2 },
4449
]);
4550
});
4651

0 commit comments

Comments
 (0)