Skip to content

Commit ef844b7

Browse files
committed
test(github): verify contribution LoC injection
1 parent bcd0718 commit ef844b7

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)