Skip to content

test : added unit tests for github-rate-limit helpers#2466

Open
tmdeveloper007 wants to merge 1 commit into
Umbrella-io:mainfrom
tmdeveloper007:#2461
Open

test : added unit tests for github-rate-limit helpers#2466
tmdeveloper007 wants to merge 1 commit into
Umbrella-io:mainfrom
tmdeveloper007:#2461

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Closes #2461.

Summary of What Has Been Done:
Added a dedicated vitest test file test/github-rate-limit.test.ts that pins the behaviour of every export in src/lib/github-rate-limit.ts: getGitHubRateLimitDetails, throwIfGitHubRateLimited, githubRateLimitResponse, and the GitHubRateLimitError class. Tests use a real Response constructed via new Response(null, { status, headers }) so the public surface area (including header parsing) is exercised end-to-end.

Changes Made:

  • New file: test/github-rate-limit.test.ts (15 tests, all passing under npm test).
  • Coverage for getGitHubRateLimitDetails:
    • 200 with x-ratelimit-remaining: 0 → null (status is the gate).
    • 404 → null.
    • 403 with x-ratelimit-remaining: 1 → null (still has budget).
    • 403 with x-ratelimit-remaining: 0 and a valid reset epoch → full GitHubRateLimitDetails with matching resetAt ISO string and resetAtEpoch.
    • 429 with the same conditions → same shape.
    • 403 with x-ratelimit-remaining: 0 but missing reset header → resetAt: null, generic message.
    • 403 with non-numeric reset header → resetAt: null, resetAtEpoch: null.
  • Coverage for throwIfGitHubRateLimited:
    • 200 → no throw.
    • 403 with remaining=0 → throws GitHubRateLimitError whose details and message match getGitHubRateLimitDetails.
    • 403 with remaining=1 → no throw.
  • Coverage for githubRateLimitResponse:
    • Returns null for plain Error, strings, null, undefined.
    • Returns a 429 Response with the right JSON body for a GitHubRateLimitError (both with and without a reset timestamp).

Impact it Made:
Locks the contract between GitHub's rate-limit signal and DevTrack's user-facing 429 response. Future refactors of the helper will surface a test failure rather than a silent security or UX regression. No production code is modified; the change is limited to one new test file.

@github-actions github-actions Bot added type:testing GSSoC type bonus: tests (+10 pts) gssoc26 GSSoC 2026 contribution labels Jun 15, 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

@Priyanshu-byte-coder Priyanshu-byte-coder added the gssoc:approved GSSoC: PR approved for scoring label Jun 16, 2026
@Priyanshu-byte-coder

Copy link
Copy Markdown
Member

This PR has merge conflicts with the current main branch. Please rebase or merge main into your branch to resolve the conflicts, then push the updated branch. Once conflicts are resolved, this PR will be merged.

git fetch origin main
git merge origin/main
# resolve conflicts
git push

@Priyanshu-byte-coder

Copy link
Copy Markdown
Member

This PR has merge conflicts with main. Please rebase or resolve conflicts and push again.

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

Labels

gssoc:approved GSSoC: PR approved for scoring 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.

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

2 participants