Skip to content

Commit 3599231

Browse files
authored
test(calculate): verify streak formulas for only weekday contributions timeline (JhaSourav07#1475) (JhaSourav07#2026)
## Description This PR adds a specific Vitest test case to `lib/calculate.test.ts` to simulate a contribution timeline containing exclusively Monday through Friday commits. This test explicitly proves the off-by-one error where the current streak is prematurely broken across weekend boundaries. Fixes JhaSourav07#1475 ## 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 — This PR only adds a unit test for backend calculation logic. No visual SVG changes were made. ## 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. - [ ] 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 eabc1b3 + 5b6b97b commit 3599231

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

components/DiscordButton.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use client';
2-
32
import { useRef, useState, useEffect } from 'react';
43
import { motion } from 'framer-motion';
54
import gsap from 'gsap';

lib/calculate.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,33 @@ describe('calculateStreak', () => {
322322
expect(result.totalContributions).toBe(1);
323323
expect(result.longestStreak).toBe(1);
324324
});
325+
it.fails('simulates a streak containing ONLY Monday through Friday commits (Issue #1475)', () => {
326+
// buildCalendar assumes index 0 is a Monday.
327+
// Days in a week: Mon(1), Tue(1), Wed(1), Thu(1), Fri(1), Sat(0), Sun(0)
328+
// We will simulate 3 full weeks of this pattern.
329+
const calendar = buildCalendar([
330+
// Week 1
331+
1, 1, 1, 1, 1, 0, 0,
332+
// Week 2
333+
1, 1, 1, 1, 1, 0, 0,
334+
// Week 3
335+
1, 1, 1, 1, 1, 0, 0,
336+
]);
337+
338+
// Evaluate the streak on the final Sunday of the calendar (index 20).
339+
// Because the logic currently has an off-by-one bug when handling weekends,
340+
// the test asserts what the math *should* output if weekend bridging is working correctly.
341+
const result = calculateStreak(
342+
calendar,
343+
'UTC',
344+
new Date('2024-01-21T12:00:00Z') // The date of the 3rd Sunday
345+
);
346+
347+
// If weekend gaps are bridged properly, all 15 weekdays form a continuous streak.
348+
expect(result.currentStreak).toBe(15);
349+
expect(result.longestStreak).toBe(15);
350+
expect(result.totalContributions).toBe(15);
351+
});
325352

326353
it('does not walk past the start of a 1-day calendar when grace is larger than the available days', () => {
327354
const calendar = buildCalendar([1]);

0 commit comments

Comments
 (0)