Skip to content

test : add unit tests for github-rate-limit helpers #2461

Description

@tmdeveloper007

Summary of What Needs to be Done:
Add a dedicated vitest test file for the pure helpers in src/lib/github-rate-limit.ts: getGitHubRateLimitDetails, throwIfGitHubRateLimited, and githubRateLimitResponse. The module is used across the app to translate GitHub rate-limit responses into typed errors and 429 Responses, but it has no test coverage. Tests must use a fake Response (a plain object with status and headers.get) so they remain fast and deterministic.

Changes that Need to be Made:

  • Create test/github-rate-limit.test.ts that imports from ../src/lib/github-rate-limit.
  • Cover getGitHubRateLimitDetails with cases:
    • 200 with x-ratelimit-remaining: 0 → returns null (only 403/429 trigger).
    • 403 with x-ratelimit-remaining: 0 and a valid x-ratelimit-reset epoch → returns full details with matching resetAt ISO and resetAtEpoch.
    • 429 with x-ratelimit-remaining: 0 but missing x-ratelimit-reset → returns resetAt: null and a generic message.
    • 403 with x-ratelimit-remaining: 1 (still has budget) → returns null.
    • 404 → returns null.
  • Cover throwIfGitHubRateLimited with cases:
    • 200 response → no throw.
    • 403 with rate-limit headers → throws GitHubRateLimitError whose details matches the values returned by getGitHubRateLimitDetails.
  • Cover githubRateLimitResponse with cases:
    • Plain Error instance → returns null.
    • new GitHubRateLimitError(...) → returns a Response with status 429 and JSON body { error, message, rateLimit: { resetAt, resetAtEpoch } }.

Impact that it would Provide:
Locks the contract between GitHub's rate-limit signal and DevTrack's user-facing 429 response. Stops accidental behaviour drift the next time the helper is touched, with no production code changes.

Hello @Priyanshu-byte-coder, please assign this issue to me (@tmdeveloper007) so I can open a focused PR with the new test file.

Metadata

Metadata

Assignees

Labels

gssoc:assignedGSSoC: Issue assigned to a contributor

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions