Skip to content

Commit 7dd8c04

Browse files
authored
test(calculate): verify streak across Dec 31 to Jan 1 year boundary (JhaSourav07#1594)
## Description Fixes JhaSourav07#1482 Adds a unit test in `lib/calculate.test.ts` simulating a contribution streak that spans the **Dec 31 → Jan 1** year boundary. It verifies that `calculateStreak` treats the calendar year rollover (`2024-12-31` → `2025-01-01`) as one continuous run rather than splitting the streak — guarding against off-by-one bugs at the year boundary. Assertions: - `currentStreak === 7` (Dec 27 → Jan 2) - `longestStreak === 7` - `totalContributions === 7` - `todayDate === '2025-01-02'` No production code changed — this is purely additional test coverage. ## 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 — test-only change, no SVG/UI output affected. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [ ] 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 community for contributor discussions, mentorship, and faster PR support.
2 parents 5cfb855 + a6a6666 commit 7dd8c04

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

lib/calculate.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,46 @@ describe('calculateStreak — todayDate format', () => {
550550
});
551551
});
552552

553+
describe('calculateStreak — year boundary transition (Dec 31 → Jan 1)', () => {
554+
// Streak math relies on the flattened day array being chronologically ordered,
555+
// so a run that crosses from December into January must be counted as a single
556+
// continuous streak. This guards against off-by-one bugs where the calendar
557+
// year rollover (e.g. 2024-12-31 → 2025-01-01) is mistakenly treated as a gap.
558+
it('counts a streak that spans the Dec 31 → Jan 1 boundary as one continuous run', () => {
559+
const calendar: ContributionCalendar = {
560+
totalContributions: 7,
561+
weeks: [
562+
{
563+
contributionDays: [
564+
{ contributionCount: 0, date: '2024-12-26' }, // gap before the streak begins
565+
{ contributionCount: 1, date: '2024-12-27' },
566+
{ contributionCount: 1, date: '2024-12-28' },
567+
{ contributionCount: 1, date: '2024-12-29' },
568+
{ contributionCount: 1, date: '2024-12-30' },
569+
{ contributionCount: 1, date: '2024-12-31' }, // last day of the year
570+
{ contributionCount: 1, date: '2025-01-01' }, // first day of the new year
571+
],
572+
},
573+
{
574+
contributionDays: [
575+
{ contributionCount: 1, date: '2025-01-02' }, // "today"
576+
],
577+
},
578+
],
579+
};
580+
581+
// Pin "now" to Jan 2 so the final day is treated as today and the streak is live.
582+
const now = new Date('2025-01-02T12:00:00Z');
583+
const result = calculateStreak(calendar, 'UTC', now);
584+
585+
// The 7-day run (Dec 27 → Jan 2) must not be split by the year rollover.
586+
expect(result.currentStreak).toBe(7);
587+
expect(result.longestStreak).toBe(7);
588+
expect(result.totalContributions).toBe(7);
589+
expect(result.todayDate).toBe('2025-01-02');
590+
});
591+
});
592+
553593
// ---------- EPIC ENHANCEMENT TESTS ----------
554594

555595
describe('aggregateCalendars', () => {

0 commit comments

Comments
 (0)