Skip to content

Commit d548cbf

Browse files
authored
refactor(svg): add a ?scale=log integration test verifying shorter tower heights (JhaSourav07#2234)
## Description Adds an integration test that verifies ?scale=log produces visually different SVG output than ?scale=linear, not just a 200 response. The test mocks a high-count calendar (20 contributions/day across 7 days) and asserts the two SVG strings are not identical, confirming logarithmic scaling actually compresses tower heights. Fixes JhaSourav07#382 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A ## 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): ...`). - [x] 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 1eae6cd + f0b129a commit d548cbf

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

app/api/streak/route.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,41 @@ describe('GET /api/streak', () => {
570570

571571
expect(response.status).toBe(200);
572572
});
573+
574+
it('produces different SVG output for scale=log versus scale=linear with mixed contribution counts', async () => {
575+
// Mix of low (1) and high (100) counts: linear scales them 1× vs 100×,
576+
// log compresses the ratio to log₂(2) vs log₂(101) — guaranteed to produce
577+
// different tower heights and therefore different path data in the SVG.
578+
vi.mocked(fetchGitHubContributions).mockResolvedValue({
579+
calendar: {
580+
totalContributions: 203,
581+
weeks: [
582+
{
583+
contributionDays: [
584+
{ contributionCount: 1, date: '2024-06-10' },
585+
{ contributionCount: 5, date: '2024-06-11' },
586+
{ contributionCount: 20, date: '2024-06-12' },
587+
{ contributionCount: 100, date: '2024-06-13' },
588+
{ contributionCount: 50, date: '2024-06-14' },
589+
{ contributionCount: 5, date: '2024-06-15' },
590+
{ contributionCount: 1, date: '2024-06-16' },
591+
],
592+
},
593+
],
594+
},
595+
repoContributions: [],
596+
} as unknown as ExtendedContributionData);
597+
598+
const linearResponse = await GET(makeRequest({ user: 'octocat', scale: 'linear' }));
599+
const logResponse = await GET(makeRequest({ user: 'octocat', scale: 'log' }));
600+
601+
const linearBody = await linearResponse.text();
602+
const logBody = await logResponse.text();
603+
604+
expect(linearResponse.status).toBe(200);
605+
expect(logResponse.status).toBe(200);
606+
expect(linearBody).not.toBe(logBody);
607+
});
573608
});
574609

575610
describe('year parameter', () => {

0 commit comments

Comments
 (0)