Skip to content

Commit ae97337

Browse files
authored
test(github): verify contribution LoC injection (JhaSourav07#1115)
## Description Fixes JhaSourav07#1059 Added test coverage verifying that `fetchGitHubContributions` correctly injects `locAdditions` and `locDeletions` values for contribution days in LoC mode. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable — test-only change. ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). * [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). * [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). * [ ] I have updated `README.md` if I added a new theme or URL parameter. * [x] I have started the repo. * [x] I have made sure that i have only one commit to merge in this PR. * [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). * [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 504bd24 + ef844b7 commit ae97337

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

lib/github.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,64 @@ describe('fetchGitHubContributions', () => {
8585
expect(result.weeks[0].contributionDays[0]).toHaveProperty('locAdditions');
8686
});
8787

88+
it('injects positive locAdditions and non-negative locDeletions for contribution days', async () => {
89+
const calendarWithContributions: ContributionCalendar = {
90+
totalContributions: 5,
91+
weeks: [
92+
{
93+
contributionDays: [{ contributionCount: 5, date: '2024-06-10' }],
94+
},
95+
],
96+
};
97+
98+
vi.mocked(fetch).mockResolvedValue(
99+
mockResponse({
100+
data: {
101+
user: {
102+
contributionsCollection: {
103+
contributionCalendar: calendarWithContributions,
104+
},
105+
},
106+
},
107+
})
108+
);
109+
110+
const result = await fetchGitHubContributions('octocat');
111+
const day = result.weeks[0].contributionDays[0];
112+
113+
expect(day.locAdditions).toBeGreaterThan(0);
114+
expect(day.locDeletions).toBeGreaterThanOrEqual(0);
115+
});
116+
117+
it('sets locAdditions and locDeletions to zero for zero-contribution days', async () => {
118+
const calendarWithZeroContribution: ContributionCalendar = {
119+
totalContributions: 0,
120+
weeks: [
121+
{
122+
contributionDays: [{ contributionCount: 0, date: '2024-06-11' }],
123+
},
124+
],
125+
};
126+
127+
vi.mocked(fetch).mockResolvedValue(
128+
mockResponse({
129+
data: {
130+
user: {
131+
contributionsCollection: {
132+
contributionCalendar: calendarWithZeroContribution,
133+
},
134+
},
135+
},
136+
})
137+
);
138+
139+
const result = await fetchGitHubContributions('octocat');
140+
const day = result.weeks[0].contributionDays[0];
141+
142+
expect(day.locAdditions).toBe(0);
143+
expect(day.locDeletions).toBe(0);
144+
});
145+
88146
it('sends a POST request to the GitHub GraphQL endpoint with the correct body', async () => {
89147
vi.mocked(fetch).mockResolvedValue(
90148
mockResponse({

0 commit comments

Comments
 (0)