Skip to content

Commit a9d067d

Browse files
committed
test(api): verify delta_format=absolute shows commit count in monthly SVG (JhaSourav07#1035)
1 parent 5790627 commit a9d067d

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

app/api/streak/route.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,37 @@ describe('GET /api/streak', () => {
737737
expect(response.status).toBe(200);
738738
expect(body).toContain('CURRENT_STREAK');
739739
});
740+
// =========================================================================
741+
// ISSUE OBJECTIVE: Route test for ?view=monthly&delta_format=absolute
742+
// =========================================================================
743+
it('applies delta_format=absolute to show raw commit counts in the monthly SVG', async () => {
744+
// 1. Mock the GitHub fetch with actual weekly data using vi.mocked
745+
vi.mocked(fetchGitHubContributions).mockResolvedValueOnce({
746+
totalContributions: 150,
747+
weeks: [
748+
{ contributionDays: [{ date: '2026-04-15', contributionCount: 10 }] },
749+
{ contributionDays: [{ date: '2026-05-15', contributionCount: 15 }] },
750+
],
751+
} as unknown as ContributionCalendar);
752+
753+
// 2. Lock the system time to May 2026 so the calendar calculation aligns
754+
vi.useFakeTimers();
755+
vi.setSystemTime(new Date('2026-05-20T12:00:00Z'));
756+
757+
// 3. Make request using the file's built-in makeRequest helper
758+
const req = makeRequest({ user: 'octocat', view: 'monthly', delta_format: 'absolute' });
759+
const res = await GET(req);
760+
761+
expect(res.status).toBe(200);
762+
763+
const body = await res.text();
764+
765+
// 4. Assert body contains 'commits' (the absolute delta unit)
766+
expect(body).toContain('commits');
767+
768+
// Cleanup
769+
vi.useRealTimers();
770+
});
740771
});
741772

742773
describe('theme=random cache header', () => {

0 commit comments

Comments
 (0)