Skip to content

Test/streak unit tests only v2#3202

Open
sudeekshaballanda-hub wants to merge 2 commits into
Priyanshu-byte-coder:mainfrom
sudeekshaballanda-hub:test/streak-unit-tests-only-v2
Open

Test/streak unit tests only v2#3202
sudeekshaballanda-hub wants to merge 2 commits into
Priyanshu-byte-coder:mainfrom
sudeekshaballanda-hub:test/streak-unit-tests-only-v2

Conversation

@sudeekshaballanda-hub

Copy link
Copy Markdown

Summary

Adds unit tests for the streak utilities (src/lib/streak-utils.ts) by importing the real functions instead of re-implementing them. This ensures the tests exercise the actual shipped code and can catch regressions.


Closes # (no specific issue - this is a test improvement PR addressing feedback from #3131)


Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 📝 Documentation update
  • ♻️ Refactor / code cleanup (no functional change)
  • ⚡ Performance improvement
  • 🔒 Security fix
  • 🧪 Tests only

What Changed

  • Created test/streak/streak.test.ts: Unit tests for streak utilities
    • Imports calculateCurrentStreak and calculateLongestStreak from source (src/lib/streak-utils.ts)
    • Tests dynamic date logic (current streak based on today/yesterday)
    • Tests longest streak calculation with various patterns
    • Edge cases: empty arrays, duplicate dates, unsorted data, invalid dates
    • No local re-implementations - uses real functions

How to Test

  1. Run the unit tests:
    pnpm test test/streak/streak.test.ts
    

Expected result:
✓ test/streak/streak.test.ts (15 tests) 20ms
✓ Streak Utilities (15)
✓ calculateCurrentStreak (7)
✓ returns 0 for empty contributions
✓ returns correct streak for consecutive days ending today
✓ returns 0 when last activity was more than 1 day ago
✓ handles Date objects
✓ handles unsorted dates
✓ handles duplicate dates
✓ returns 0 for invalid dates
✓ calculateLongestStreak (8)
✓ returns 0 for empty contributions
✓ returns correct longest streak
✓ handles single-day streaks
✓ handles all days with contributions
✓ handles Date objects
✓ handles unsorted dates
✓ handles duplicate dates
✓ ignores invalid dates

Screenshots / Recordings

This PR only adds tests, no UI changes.

Checklist

  • Linked the related issue above
  • Self-reviewed my own diff
  • No unnecessary console.log, debug code, or commented-out blocks
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Added or updated tests where applicable
  • Updated documentation / comments if behavior changed

Accessibility (UI changes only)

This PR has no UI changes.

Additional Context

This PR addresses the feedback from the previous PR (#3131) by:
-Importing real functions from src/lib/streak-utils.ts
-Using the correct function signatures (Date[]/string[] array)
-Removing local re-implementations

The tests now properly exercise the shipped code and can catch regressions. This is a follow-up to the feedback provided in #3131.

- Remove local calculateStreak/getLongestStreak definitions
- Import calculateCurrentStreak and calculateLongestStreak from src/lib/streak-utils.ts
- Update test data format to match real function signatures (Date[]/string[] array)
- Add tests for Date objects, duplicates, invalid dates, and unsorted data
- Add dynamic date tests for current streak logic

This ensures the tests actually exercise the shipped code and can catch regressions.
@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:testing GSSoC type bonus: tests (+10 pts) labels Jul 13, 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

@sudeekshaballanda-hub

Copy link
Copy Markdown
Author

@Priyanshu-byte-coder This PR is ready for review. I'm a GSSoC contributor. Thanks!

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant