|
7 | 7 | and easy to maintain. |
8 | 8 | */ |
9 | 9 | import { getTopContributorsAndRepos } from "../../../utils/getTopContributorsAndRepos"; |
| 10 | +import { describe, it, expect } from "vitest"; |
10 | 11 |
|
11 | 12 | describe("getTopContributorsAndRepos", () => { |
| 13 | + // mock JSON data so that Lint passes |
| 14 | +const mockJSON = { |
| 15 | + "repo1": { |
| 16 | + issues: { "alice": { total_issues_opened: 2 }, "bob": { total_issues_opened: 1 } }, |
| 17 | + }, |
| 18 | + "repo2": { |
| 19 | + pull_requests: { "charlie": { total_prs_opened: 4 } } |
| 20 | + } |
| 21 | + }; |
| 22 | + |
| 23 | + |
12 | 24 | it("counts contributor activity and sorts correctly", () => { |
13 | | - const events = [ |
14 | | - { author: "alice", repo: "repo1" }, |
15 | | - { author: "bob", repo: "repo1" }, |
16 | | - { author: "alice", repo: "repo2" }, |
17 | | - ]; |
18 | | - |
19 | | - const { topContributors } = |
20 | | - getTopContributorsAndRepos(events, 5); |
21 | | - |
22 | | - // alice should rank first since she appears twice |
| 25 | + const {topContributors} = getTopContributorsAndRepos(mockJSON, 5); |
| 26 | + // charlie: 4, alicce: 2, bob: 1 |
23 | 27 | expect(topContributors).toEqual([ |
| 28 | + { name: "charlie", count: 4 }, |
24 | 29 | { name: "alice", count: 2 }, |
25 | 30 | { name: "bob", count: 1 }, |
26 | 31 | ]); |
27 | 32 | }); |
28 | 33 |
|
29 | 34 | it("counts repository activity and sorts correctly", () => { |
30 | | - const events = [ |
31 | | - { author: "alice", repo: "repo1" }, |
32 | | - { author: "bob", repo: "repo1" }, |
33 | | - { author: "charlie", repo: "repo2" }, |
34 | | - ]; |
35 | | - |
36 | 35 | const { topRepos } = |
37 | | - getTopContributorsAndRepos(events, 5); |
| 36 | + getTopContributorsAndRepos(mockJSON, 5); |
38 | 37 |
|
39 | | - // repo1 should rank higher since it appears more frequently |
| 38 | + // repo1: 3 (2 from alice + 1 from bob), repo2: 4 (from charlie) |
40 | 39 | expect(topRepos).toEqual([ |
41 | | - { name: "repo1", count: 2 }, |
42 | | - { name: "repo2", count: 1 }, |
| 40 | + { name: "repo2", count: 4 }, |
| 41 | + { name: "repo1", count: 3}, |
43 | 42 | ]); |
44 | 43 | }); |
45 | 44 |
|
|
0 commit comments