Skip to content

Conversation

@supermoz5536
Copy link

@supermoz5536 supermoz5536 commented Jun 13, 2025

Overview

Fixes #225

What I’ve done

  1. Applied strings.TrimSpace to "nameOrEmail" in "SearchUser" resolver.
  2. Added " e2e" input case to TestSearchUser.
  3. Refactored TestSearchUser to table-driven style.

What I haven’t done

  • Apply Trimming to other GraphQL resolvers (besides SearchUser).

How I tested

  1. make run-db → start test MongoDB.
  2. go test ./server/e2e -v -run TestSearchUser→ all cases pass.

Which point I want you to review particularly

  • Whether the fix correctly addresses the issue.

Memo

Summary by CodeRabbit

  • Bug Fixes

    • Improved user search to handle and ignore leading or trailing spaces in search terms, ensuring more accurate results.
  • Tests

    • Enhanced user search tests for better coverage and reliability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

Walkthrough

The SearchUser method was updated to trim whitespace from the search input, ensuring user searches are not affected by leading or trailing spaces. Correspondingly, the user search test was refactored to a table-driven format, improving structure and clarity by consolidating multiple search scenarios into subtests.

Changes

File(s) Change Summary
server/internal/adapter/gql/loader_user.go Modified SearchUser to trim whitespace from nameOrEmail before searching.
server/e2e/gql_user_test.go Refactored TestSearchUser to use a table-driven approach with subtests for different search cases.

Sequence Diagram(s)

sequenceDiagram
    participant Test as TestSearchUser
    participant Loader as UserLoader
    participant Usecase as UserUsecase

    Test->>Loader: SearchUser(nameOrEmail)
    Loader->>Loader: Trim whitespace from nameOrEmail
    Loader->>Usecase: SearchUser(trimmedNameOrEmail)
    Usecase-->>Loader: User or nil
    Loader-->>Test: User or nil
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Add a string format check for user name (#225)

Poem

A hop and a skip, a whitespace snip—
Now searching for users is never a trip!
With names trimmed neat, results come fast,
Table-driven tests ensure they last.
The code is clean, the bugs are few,
This bunny’s proud of what you do!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch fix/trim-user-name-or-email
  • Post Copyable Unit Tests in Comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
server/internal/adapter/gql/loader_user.go (1)

42-45: Inline trim & guard against empty input

The extra temporary trimmed variable is unnecessary, and the method will still hit the DB even if the caller passes only whitespace.
A tiny refactor improves readability and avoids an unhelpful round-trip.

-	trimmed := strings.TrimSpace(nameOrEmail)
-	nameOrEmail = trimmed
+	nameOrEmail = strings.TrimSpace(nameOrEmail)
+	if nameOrEmail == "" { // nothing to search
+		return nil, nil
+	}
server/e2e/gql_user_test.go (2)

145-165: Broaden whitespace test coverage

Nice conversion to table-driven tests 👏.
Consider adding a trailing-space and a both-sides-space case so the new logic is exercised symmetrically:

         {
             name: "trimming space",
             input:     " e2e",
             wantFound:   true,
         },
+        {
+            name: "trailing space",
+            input:     "e2e ",
+            wantFound:   true,
+        },
+        {
+            name: "both sides space",
+            input:     "  e2e  ",
+            wantFound:   true,
+        },

173-181: Check GraphQL errors at the root level

errors is a root-level field, not inside data.
Asserting on resp.NotContainsKey("errors") after you’ve already drilled into data will always pass.
Capture the raw response first (before .Value("data")) or perform a second assertion on the top-level object.

raw := Request(e, uId1.String(), request).Object()
data := raw.Value("data").Object()

// ...
if !tt.wantFound {
    data.Value("searchUser").IsNull()
    raw.NotContainsKey("errors")
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a15747 and c588efc.

📒 Files selected for processing (2)
  • server/e2e/gql_user_test.go (1 hunks)
  • server/internal/adapter/gql/loader_user.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
server/e2e/gql_user_test.go (1)
server/e2e/common.go (2)
  • GraphQLRequest (222-226)
  • Request (228-239)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a string format check for user name

1 participant