🧪 testing improvement: add unit tests for validateName in collections route#883
🧪 testing improvement: add unit tests for validateName in collections route#883is0692vs wants to merge 2 commits into
Conversation
Release: staging -> main (2026-05-21 07:43)
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Warning Review limit reached
Your plan currently allows 1 review/hour. Refill in 59 minutes and 24 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the 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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
このリポジトリでは staging 先行フローを採用しています。PR のターゲットを |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| it("should return error for names longer than 100 characters", () => { | ||
| expect(validateName("a".repeat(101))).toBe( | ||
| "name must be 100 characters or less", | ||
| ); | ||
| expect(validateName(" a".repeat(101))).toBe( | ||
| "name must be 100 characters or less", | ||
| ); | ||
| }); |
There was a problem hiding this comment.
validateName はトリム後の長さで上限チェックをしているため、「生の文字列は 100 文字超だがトリム後はちょうど 100 文字」のケースも有効(null 返却)であることが期待されますが、現在のテストではそのパスを検証していません。また " a".repeat(101) は 201 文字(トリム後)と上限から大きく外れており、境界値の検証としての意図が不明瞭です。
| it("should return error for names longer than 100 characters", () => { | |
| expect(validateName("a".repeat(101))).toBe( | |
| "name must be 100 characters or less", | |
| ); | |
| expect(validateName(" a".repeat(101))).toBe( | |
| "name must be 100 characters or less", | |
| ); | |
| }); | |
| it("should return error for names longer than 100 characters", () => { | |
| expect(validateName("a".repeat(101))).toBe( | |
| "name must be 100 characters or less", | |
| ); | |
| // 生文字列は 100 文字超だがトリム後はちょうど 100 文字 → 有効 | |
| expect(validateName(" " + "a".repeat(100) + " ")).toBeNull(); | |
| // トリム後も 101 文字 → 無効 | |
| expect(validateName(" " + "a".repeat(101) + " ")).toBe( | |
| "name must be 100 characters or less", | |
| ); | |
| }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/api/src/routes/__tests__/collections.test.ts
Line: 46-53
Comment:
`validateName` はトリム後の長さで上限チェックをしているため、「生の文字列は 100 文字超だがトリム後はちょうど 100 文字」のケースも有効(`null` 返却)であることが期待されますが、現在のテストではそのパスを検証していません。また `" a".repeat(101)` は 201 文字(トリム後)と上限から大きく外れており、境界値の検証としての意図が不明瞭です。
```suggestion
it("should return error for names longer than 100 characters", () => {
expect(validateName("a".repeat(101))).toBe(
"name must be 100 characters or less",
);
// 生文字列は 100 文字超だがトリム後はちょうど 100 文字 → 有効
expect(validateName(" " + "a".repeat(100) + " ")).toBeNull();
// トリム後も 101 文字 → 無効
expect(validateName(" " + "a".repeat(101) + " ")).toBe(
"name must be 100 characters or less",
);
});
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Code Review
This pull request exports the validateName function in apps/api/src/routes/collections.ts to facilitate unit testing. Comprehensive tests for this function have been added to apps/api/src/routes/tests/collections.test.ts, covering valid inputs, invalid types, whitespace-only strings, and character length limits. The documentation in .jules/sentinel.md was also updated to reflect this change. I have no feedback to provide as there were no review comments to evaluate.
🎯 What: The
validateNamefunction inapps/api/src/routes/collections.tswas an untested pure function. It has been exported and a dedicated test suite has been added toapps/api/src/routes/__tests__/collections.test.ts.📊 Coverage: The new test suite covers:
✨ Result: Increased test coverage and confidence in the input validation logic for collections.
PR created automatically by Jules for task 9579289262309400852 started by @is0692vs
Greptile Summary
validateName関数にexportを付けてテスト可能にし、ハッピーパス・型チェック・空文字・上限超過を網羅した専用テストスイートを追加しています。collections.tsの変更はexportキーワードの追加のみで、既存のロジックへの影響はありません。Confidence Score: 4/5
既存のプロダクションロジックへの変更は
exportの追加のみで、ランタイムへの影響はありません。テストの追加は安全です。ソースコードの変更は
exportキーワードの追加のみであり、関数の動作は一切変わりません。テストスイートは主要なケースを網羅していますが、「生文字列が 100 文字超でもトリム後は 100 文字以内」という境界値ケースが欠けており、validateNameの空白トリム動作を完全には検証できていません。apps/api/src/routes/__tests__/collections.test.tsのトリム境界値テストを補足すると、より堅牢なテストスイートになります。Important Files Changed
validateName関数にexportキーワードを追加した最小限の変更。ロジックに変更なし。validateNameのテストスイートを追加。基本的なハッピーパス・型チェック・空文字・上限超過は網羅されているが、「トリム後ちょうど100文字」の境界値ケースが欠けている。Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["validateName(name: unknown)"] --> B{typeof name === 'string'\nかつ trim後に長さ > 0?} B -- No --> C["return 'name is required'"] B -- Yes --> D{trim後の長さ > 100?} D -- Yes --> E["return 'name must be 100 characters or less'"] D -- No --> F["return null(有効)"] subgraph テストカバレッジ T1["✅ 有効な名前 (例: 'My Collection')"] T2["✅ 無効な型 (null, undefined, number, object)"] T3["✅ 空文字 / 空白のみ"] T4["✅ 101文字超"] T5["⚠️ 未検証: trim後ちょうど100文字\n(生文字列は100文字超)"] endPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "test: add unit tests for validateName in..." | Re-trigger Greptile