Skip to content

Commit 7430ebc

Browse files
authored
test(github): add bounds check for extreme values in generateAchievements (JhaSourav07#796)
## Description Fixes : JhaSourav07#692 Adds a test to assert that the `generateAchievements` function correctly clamps extreme progress values between 0 and 100, and verifies that the progress value is finite. ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs, tests) ## Visual Preview N/A - This PR only adds automated tests and does not affect the SVG output visually. ## 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. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord server for faster collaboration, mentorship, and PR support.
2 parents 067d028 + ddb1c07 commit 7430ebc

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/github.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,16 @@ describe('generateAchievements', () => {
538538

539539
expect(unlocked.some((a) => a.title === '100 Day Streak')).toBe(false);
540540
});
541+
542+
it('caps progress between 0 and 100 for extreme values', () => {
543+
const achievements = generateAchievements(999999, 999999);
544+
545+
for (const item of achievements) {
546+
expect(Number.isFinite(item.progress)).toBe(true);
547+
expect(item.progress).toBeGreaterThanOrEqual(0);
548+
expect(item.progress).toBeLessThanOrEqual(100);
549+
}
550+
});
541551
});
542552

543553
describe('validateGitHubUsername', () => {

0 commit comments

Comments
 (0)