Skip to content

test: add unit tests for rate-limit.ts (#2760)#2779

Closed
ANU5565 wants to merge 2 commits into
Priyanshu-byte-coder:mainfrom
ANU5565:test/rate-limit-tests
Closed

test: add unit tests for rate-limit.ts (#2760)#2779
ANU5565 wants to merge 2 commits into
Priyanshu-byte-coder:mainfrom
ANU5565:test/rate-limit-tests

Conversation

@ANU5565

@ANU5565 ANU5565 commented Jun 24, 2026

Copy link
Copy Markdown

Summary

This PR adds essential unit tests for src/lib/rate-limit.ts to ensure robust IP detection and rate-limiting functionality.

Closes #

This closes #2760.

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/rate-limit.test.ts.

  • Added test cases for getClientIp including headers (cf-connecting-ip, x-real-ip, x-forwarded-for) and priority handling.


How to Test

  1. Run npm install to ensure dependencies are up to date.

  2. Run npx vitest test/rate-limit.test.ts to execute the new tests.

  3. Verify that all tests pass.

Expected result:
All tests in rate-limit.test.ts should pass with green status

Screenshots / Recordings

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)

  • Keyboard navigation works correctly
  • Color contrast meets WCAG AA standard
  • ARIA labels / roles added where needed
  • Tested on mobile / responsive layout

Additional Context

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

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Umbrella-io — 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

@Legit-Ox Legit-Ox left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge.

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

Closing. #2733 was selected as the best rate-limit test suite — it covers all fallback headers and the full logic including pruning. This PR only has a single test for one header. Thanks for contributing!

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 rate-limit.ts

3 participants