Skip to content

Commit 9ba96d6

Browse files
authored
test(calculate): verify weekend ratio for weekday-only calendar (JhaSourav07#1170)
## Description Fixes JhaSourav07#1054 Added a unit test for `calculateWrappedStats` to verify that `weekendRatio` is calculated correctly when all contributions occur on weekdays (Monday–Friday). ### Test Coverage Added * Creates a calendar containing contributions only on weekdays. * Verifies that no weekend contributions are counted. * Asserts that `weekendRatio` is `0`. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable — test-only change. ## 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 (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 4fda518 + 51834de commit 9ba96d6

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

lib/calculate.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,27 @@ describe('aggregateCalendars', () => {
520520
});
521521

522522
describe('calculateWrappedStats', () => {
523+
it('returns weekendRatio as 0 when all contributions occur on weekdays', () => {
524+
const calendar = {
525+
totalContributions: 25,
526+
weeks: [
527+
{
528+
contributionDays: [
529+
{ date: '2024-01-01', contributionCount: 5 }, // Mon
530+
{ date: '2024-01-02', contributionCount: 5 }, // Tue
531+
{ date: '2024-01-03', contributionCount: 5 }, // Wed
532+
{ date: '2024-01-04', contributionCount: 5 }, // Thu
533+
{ date: '2024-01-05', contributionCount: 5 }, // Fri
534+
],
535+
},
536+
],
537+
};
538+
539+
const result = calculateWrappedStats(calendar);
540+
541+
expect(result.weekendRatio).toBe(0);
542+
});
543+
523544
it('calculates GitHub Wrapped stats accurately', () => {
524545
// 2024-01-01 was a Monday. Indices 5 (Sat) and 6 (Sun) are the weekend.
525546
const cal = buildCalendar([0, 0, 0, 0, 0, 5, 15]);

0 commit comments

Comments
 (0)