Skip to content

🧪 testing improvement: add unit tests for validateName in collections route#883

Open
is0692vs wants to merge 2 commits into
stagingfrom
test/validate-name-9579289262309400852
Open

🧪 testing improvement: add unit tests for validateName in collections route#883
is0692vs wants to merge 2 commits into
stagingfrom
test/validate-name-9579289262309400852

Conversation

@is0692vs
Copy link
Copy Markdown
Contributor

@is0692vs is0692vs commented May 24, 2026

🎯 What: The validateName function in apps/api/src/routes/collections.ts was an untested pure function. It has been exported and a dedicated test suite has been added to apps/api/src/routes/__tests__/collections.test.ts.

📊 Coverage: The new test suite covers:

  • Happy paths (valid names, names exactly 100 characters long)
  • Invalid types (null, undefined, numbers, objects)
  • Empty or whitespace-only names
  • Names exceeding the 100-character limit

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 キーワードの追加のみで、既存のロジックへの影響はありません。
  • テストは有効な名前・無効な型・空白のみ・101文字超の各ケースをカバーしており、基本的な網羅性は確保されています。トリム後の長さがちょうど 100 文字になる境界値(生文字列は 100 文字超)のケースが未検証です。

Confidence Score: 4/5

既存のプロダクションロジックへの変更は export の追加のみで、ランタイムへの影響はありません。テストの追加は安全です。

ソースコードの変更は export キーワードの追加のみであり、関数の動作は一切変わりません。テストスイートは主要なケースを網羅していますが、「生文字列が 100 文字超でもトリム後は 100 文字以内」という境界値ケースが欠けており、validateName の空白トリム動作を完全には検証できていません。

apps/api/src/routes/__tests__/collections.test.ts のトリム境界値テストを補足すると、より堅牢なテストスイートになります。

Important Files Changed

Filename Overview
apps/api/src/routes/collections.ts validateName 関数に export キーワードを追加した最小限の変更。ロジックに変更なし。
apps/api/src/routes/tests/collections.test.ts validateName のテストスイートを追加。基本的なハッピーパス・型チェック・空文字・上限超過は網羅されているが、「トリム後ちょうど100文字」の境界値ケースが欠けている。
.jules/sentinel.md ピュア関数のテスト方法に関する学習ログを追記。内容に問題なし。

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文字超)"]
    end
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/api/src/routes/__tests__/collections.test.ts:46-53
`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",
    );
  });
```

Reviews (1): Last reviewed commit: "test: add unit tests for validateName in..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

is0692vs and others added 2 commits May 21, 2026 16:48
Release: staging -> main (2026-05-21 07:43)
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@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.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
open-shelf Ignored Ignored May 24, 2026 2:41am

@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@dosubot dosubot Bot added the javascript Pull requests that update javascript code label May 24, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 24, 2026

Warning

Review limit reached

@is0692vs, we couldn't start this review because you've used your available PR reviews for now.

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 @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 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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 49b75d42-73a0-42a2-86e7-9c4f147ad29e

📥 Commits

Reviewing files that changed from the base of the PR and between d429569 and b9026fa.

📒 Files selected for processing (3)
  • .jules/sentinel.md
  • apps/api/src/routes/__tests__/collections.test.ts
  • apps/api/src/routes/collections.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/validate-name-9579289262309400852

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.

@github-actions
Copy link
Copy Markdown

このリポジトリでは staging 先行フローを採用しています。PR のターゲットを staging に変更しました。staging で動作確認後、stagingmain の PR を作成してください。

@github-actions github-actions Bot changed the base branch from main to staging May 24, 2026 02:41
@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Comment on lines +46 to +53
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",
);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 validateName はトリム後の長さで上限チェックをしているため、「生の文字列は 100 文字超だがトリム後はちょうど 100 文字」のケースも有効(null 返却)であることが期待されますが、現在のテストではそのパスを検証していません。また " a".repeat(101) は 201 文字(トリム後)と上限から大きく外れており、境界値の検証としての意図が不明瞭です。

Suggested change
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.

Copy link
Copy Markdown
Contributor

@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 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.

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

Labels

javascript Pull requests that update javascript code size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant