Skip to content

Commit 3f05fee

Browse files
authored
test(api): verify delta_format=absolute shows commit count in monthly SVG (JhaSourav07#1035) (JhaSourav07#1195)
## Description Added a new route-level test case in app/api/streak/route.test.ts to verify the ?delta_format=absolute query parameter in the monthly view. The test mocks the GitHub API response with realistic weekly contribution data, requests the streak endpoint with ?view=monthly&delta_format=absolute, asserts a 200 OK status, and explicitly checks the resulting SVG body for the presence of the word commits to confirm the raw absolute delta string is rendering properly. Fixes JhaSourav07#1035 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="943" height="344" alt="Screenshot 2026-05-29 120057" src="https://github.com/user-attachments/assets/08295c0f-a553-4aea-a504-a714a7e12f13" /> ## 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 starred 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. [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions.
2 parents bd32bd5 + a9d067d commit 3f05fee

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
@@ -790,6 +790,37 @@ describe('GET /api/streak', () => {
790790
expect(response.status).toBe(200);
791791
expect(body).toContain('CURRENT_STREAK');
792792
});
793+
// =========================================================================
794+
// ISSUE OBJECTIVE: Route test for ?view=monthly&delta_format=absolute
795+
// =========================================================================
796+
it('applies delta_format=absolute to show raw commit counts in the monthly SVG', async () => {
797+
// 1. Mock the GitHub fetch with actual weekly data using vi.mocked
798+
vi.mocked(fetchGitHubContributions).mockResolvedValueOnce({
799+
totalContributions: 150,
800+
weeks: [
801+
{ contributionDays: [{ date: '2026-04-15', contributionCount: 10 }] },
802+
{ contributionDays: [{ date: '2026-05-15', contributionCount: 15 }] },
803+
],
804+
} as unknown as ContributionCalendar);
805+
806+
// 2. Lock the system time to May 2026 so the calendar calculation aligns
807+
vi.useFakeTimers();
808+
vi.setSystemTime(new Date('2026-05-20T12:00:00Z'));
809+
810+
// 3. Make request using the file's built-in makeRequest helper
811+
const req = makeRequest({ user: 'octocat', view: 'monthly', delta_format: 'absolute' });
812+
const res = await GET(req);
813+
814+
expect(res.status).toBe(200);
815+
816+
const body = await res.text();
817+
818+
// 4. Assert body contains 'commits' (the absolute delta unit)
819+
expect(body).toContain('commits');
820+
821+
// Cleanup
822+
vi.useRealTimers();
823+
});
793824
});
794825

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

0 commit comments

Comments
 (0)