Skip to content

🧪 [Testing Improvement] Add error path tests for fetchYearInReviewData#167

Open
is0692vs wants to merge 2 commits intomainfrom
jules-4138953963284005681-0d13bc0a
Open

🧪 [Testing Improvement] Add error path tests for fetchYearInReviewData#167
is0692vs wants to merge 2 commits intomainfrom
jules-4138953963284005681-0d13bc0a

Conversation

@is0692vs
Copy link
Copy Markdown
Contributor

@is0692vs is0692vs commented Apr 17, 2026

🎯 What: This PR addresses a testing gap in src/lib/githubYearInReview.ts by adding comprehensive tests for error paths in fetchYearInReviewData.

📊 Coverage: The new tests cover the following scenarios:

  • UserNotFoundError: Triggered when either statsResponse.user or reposResponse.user returns null.
  • RateLimitError: Triggered when the API responds with a 403 status code.
  • GitHubApiError: Triggered for generic API failures (e.g., 500 status code).

Result: Test coverage for src/lib/githubYearInReview.ts has significantly improved, properly simulating GraphQL API error responses and ensuring that fetchYearInReviewData correctly propagates exceptions. The modifications also setup isolated fetching mock environment within the test file, ensuring there is no pollution to other tests. Tests and builds pass without regression.


PR created automatically by Jules for task 4138953963284005681 started by @is0692vs

Greptile Summary

fetchYearInReviewData のエラー経路(UserNotFoundErrorRateLimitErrorGitHubApiError)をカバーするテストを追加し、vi.stubGlobalfetch をモック化するセットアップを導入した PR です。ロジックは正しく、既存テストへのリグレッションもありません。指摘事項はすべて P2(スタイル・堅牢性)です。

Confidence Score: 5/5

テスト追加のみの変更でありマージ可能です。残存指摘は全て P2(スタイル改善)です。

P0/P1 の問題はなく、追加されたテストのロジックは実装コードの実行フローと正確に一致しています。callCount の順序依存・export の不要エクスポート・beforeEach のスコープはいずれも実害のない P2 指摘です。

特に注意が必要なファイルはありません。

Important Files Changed

Filename Overview
src/lib/tests/githubYearInReview.test.ts fetchYearInReviewData のエラーパス(UserNotFoundError・RateLimitError・GitHubApiError)を網羅するテストを追加。fetch のグローバルモックと beforeEach/afterEach のスコープ定義に P2 の改善余地あり。
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/lib/__tests__/githubYearInReview.test.ts
Line: 12-19

Comment:
**`beforeEach`/`afterEach` のスコープが広すぎる**

`beforeEach`/`afterEach` がモジュールレベルに定義されているため、`fetch` を一切使用しない `"githubYearInReview helpers"` describe ブロックの各テストにもモックが適用されます。意図的なものでなければ、`describe("fetchYearInReviewData error paths")` ブロック内に移動することで、スコープを明確化できます。

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/lib/__tests__/githubYearInReview.test.ts
Line: 10-21

Comment:
**テストファイルからの `export` が不適切**

`mockFetch``jsonResponse``export` が付いていますが、テストファイルから外部へエクスポートするのは通常の慣習に反します。他のテストファイルで再利用する意図があるなら、`src/lib/__tests__/testUtils.ts` のような共有ユーティリティファイルに切り出すべきです。再利用の意図がなければ `export` を削除してください。

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/lib/__tests__/githubYearInReview.test.ts
Line: 67-88

Comment:
**`callCount` ベースのルーティングが脆弱**

`callCount === 1` を stats クエリ、`callCount === 2` を repos クエリと仮定しているのは、実装コードの `fetch` 呼び出し順序への暗黙の依存です。実装の順序が変更された場合、テストはエラーなく通るが意図しない経路を検証する可能性があります。この問題は他の `callCount` を使うテスト(lines 94–110、113–131、134–149)にも同様に存在します。

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "🧪 Add error path tests for fetchYearInR..." | Re-trigger Greptile

Greptile also left 3 inline comments on this PR.

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
github-user-summary Ready Ready Preview, Comment Apr 17, 2026 8:41am

@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

Warning

Rate limit exceeded

@is0692vs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 57 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 20 minutes and 57 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a3f3bf69-338b-4b65-bf6e-cd3596c70f89

📥 Commits

Reviewing files that changed from the base of the PR and between 3be157d and 0b5a67b.

📒 Files selected for processing (1)
  • src/lib/__tests__/githubYearInReview.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jules-4138953963284005681-0d13bc0a

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the test suite for the GitHub Year in Review feature by adding comprehensive error path testing for the fetchYearInReviewData function. It introduces a global fetch mocking setup and specific test cases for handling UserNotFoundError, RateLimitError, and general GitHubApiError. The feedback suggests improving the jsonResponse helper by using the native Response constructor instead of manual object casting to ensure better interface compliance and robustness.

Comment thread src/lib/__tests__/githubYearInReview.test.ts
Comment thread src/lib/__tests__/githubYearInReview.test.ts
Comment thread src/lib/__tests__/githubYearInReview.test.ts
Comment thread src/lib/__tests__/githubYearInReview.test.ts
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant