Skip to content

test: add unit tests for streak calculation functions#2821

Open
yachikadev wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
yachikadev:test/streak-calculation-functions
Open

test: add unit tests for streak calculation functions#2821
yachikadev wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
yachikadev:test/streak-calculation-functions

Conversation

@yachikadev

@yachikadev yachikadev commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds unit tests for the pure calculation functions in src/lib/streak.ts as outlined in issue #2795.

Functions Covered

calculateStreakFromDates

Empty input → returns all zeros
Single active date → current and longest both 1
Consecutive days → streak counted correctly
Gap in dates → streak breaks, longest preserved
Freeze dates → contribute to longest streak and totalActiveDays
Last active day older than yesterday → current = 0

calculateCurrentStreak

Accepts Set input
Accepts string[] of ISO timestamps and deduplicates via slice(0,10)
Empty input → returns 0

calculateStreak

Accepts Date[] and returns currentStreak and longestStreak

Timezone Edge Case

Asia/Kolkata timezone tested to verify streak stays alive when last date matches today in non-UTC timezone

Test Setup

Date.now frozen to 2026-06-24T12:00:00Z via vi.useFakeTimers for deterministic results
@/lib/date-utils mocked to isolate streak logic

Result

All tests passing ✅
Closes #2795

@github-actions github-actions Bot added type:testing GSSoC type bonus: tests (+10 pts) gssoc26 GSSoC 2026 contribution type:feature GSSoC type bonus: new feature labels Jun 26, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@yachikadev

Copy link
Copy Markdown
Contributor Author

The Playwright smoke test failure is not related to this PR.
It is caused by a pnpm-lock.yaml lockfile mismatch with the current overrides config in package.json — a pre-existing repo issue. All checks relevant to this PR pass successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:feature GSSoC type bonus: new feature type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test : add unit tests for streak calculation functions

1 participant