Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: src/graphql/types/Community/updater.ts #3110

Conversation

NishantSinghhhhh
Copy link

@NishantSinghhhhh NishantSinghhhhh commented Jan 31, 2025

What kind of change does this PR introduce?
Adding tests for updater.ts

Issue Number:
Fixes: #3085

Snapshots/Videos:
Screencast from 2025-02-01 04-25-01.webm

If relevant, did you update the documentation?
N/A

Summary
This PR improves the updater.ts file by:

Replacing any types with more specific TypeScript types to improve type safety.
Added tests to verify the updater.ts logic, including database error handling, user retrieval, and authentication/authorization checks.

Does this PR introduce a breaking change?
No

Checklist
CodeRabbit AI Review
I have reviewed and addressed all critical issues flagged by CodeRabbit AI
I have implemented or provided justification for each non-critical suggestion
I have documented my reasoning in the PR comments where CodeRabbit AI suggestions were not implemented
Test Coverage
I have written tests for all new changes/features
I have verified that test coverage meets or exceeds 95%
I have run the test suite locally and all tests pass
Other Information

Have you read the contributing guide?
Yes ✅

Summary by CodeRabbit

  • New Features

    • Enhanced community update functionality that validates user authentication and returns relevant user details when available, improving error handling for unauthorized access.
    • Introduced a mock logger for testing purposes, enhancing logging capabilities in the testing environment.
    • Added UUID generation capabilities to the project.
  • Tests

    • Added a comprehensive test suite for the community resolver's updater method, covering various scenarios and ensuring correct functionality and error handling.
    • Implemented a mock logger to streamline testing processes.

Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

coderabbitai bot commented Jan 31, 2025

Warning

Rate limit exceeded

@NishantSinghhhhh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 3 seconds before requesting another review.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba4be66 and 9dd2393.

📒 Files selected for processing (2)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
  • test/utilities/mockLogger.ts (1 hunks)

Walkthrough

This pull request introduces a new GraphQL resolver for the Community type. A new type, CommunityResolvers, and a corresponding constant, CommunityResolver, have been added with an updater method. The resolver performs authentication checks, verifies the existence of an updater ID on the community, and queries the database for the associated user, implementing error handling. Additionally, a comprehensive test suite for the updater functionality has been added, along with supporting utilities such as a mock logger.

Changes

File(s) Change Summary
src/graphql/types/Community/Community.ts Added new type CommunityResolvers, new method updater, and the CommunityResolver constant implementing the updater function with error handling.
test/graphql/types/Community/updater.test.ts Introduced a detailed test suite for the updater method including scenarios for unauthenticated users, missing updater IDs, and proper DB queries.
test/utilities/mockLogger.ts Added a new utility function createMockLogger that returns a mock logger adhering to the FastifyBaseLogger interface with mock implementations.
package.json Added dependencies: "uuid": "^11.0.5" and "@types/uuid": "^10.0.0" for UUID generation and type definitions.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant R as CommunityResolver.updater
    participant DB as Database (usersTable)
    participant CTX as GraphQLContext

    C->>R: Request updater for Community
    R->>CTX: Check if user is authenticated
    alt Unauthenticated
        R-->>C: Throw TalawaGraphQLError
    else Authenticated
        R->>R: Check if parent has updaterId
        alt No updaterId
            R-->>C: Return null
        else updaterId exists
            R->>DB: Query for user with updaterId
            alt User not found
                R->>R: Log missing user message
                R-->>C: Return null
            else User found
                R->>DB: Query again for updater details
                R-->>C: Return fetched user
            end
        end
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Achieve 100% test coverage for src/graphql/types/Community/updater.ts (#3085)
Validate error handling and correct DB queries in Community.updater (#3085)

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 80.39216% with 10 lines in your changes missing coverage. Please review.

Project coverage is 39.70%. Comparing base (e2151ff) to head (9dd2393).
Report is 16 commits behind head on develop-postgres.

Files with missing lines Patch % Lines
src/graphql/types/Community/Community.ts 80.39% 10 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           develop-postgres    #3110      +/-   ##
====================================================
+ Coverage             39.63%   39.70%   +0.06%     
====================================================
  Files                   454      454              
  Lines                 33477    33528      +51     
  Branches                397      407      +10     
====================================================
+ Hits                  13270    13311      +41     
- Misses                20207    20217      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6683e62 and 51fc985.

📒 Files selected for processing (3)
  • src/graphql/context.ts (1 hunks)
  • src/graphql/types/Community/Community.ts (1 hunks)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (3)
src/graphql/context.ts (1)

17-17: LGTM! Enhanced type safety with role information.

Adding the 'role' field to the user type in ExplicitAuthenticationTokenPayload improves type safety and makes authorization requirements explicit.

src/graphql/types/Community/Community.ts (1)

22-38: LGTM! Robust authentication and authorization checks.

The implementation properly validates user authentication and authorization with clear error messages.

test/graphql/types/Community/updater.test.ts (1)

150-183: LGTM! Comprehensive test coverage.

The test suite thoroughly covers the core functionality, edge cases, and error handling scenarios.

src/graphql/types/Community/Community.ts Outdated Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 1, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

@NishantSinghhhhh
Copy link
Author

@palisadoes , there are type errors coming from files that i did not even touch

Copy link

@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: 2

🔭 Outside diff range comments (1)
src/graphql/context.ts (1)

Line range hint 5-21: Fix formatting issues flagged by biome check.

The formatter has detected issues with:

  • Empty line at line 5
  • Type declaration formatting (lines 6-8)
  • Closing bracket indentation (line 21)

Apply the following formatting fixes:

-
-export type AuthTokenUserFields = Pick<typeof usersTable.$inferSelect, "id" | "role">;
-
+export type AuthTokenUserFields = Pick<
+	typeof usersTable.$inferSelect,
+	"id" | "role"
+>;

export type ExplicitAuthenticationTokenPayload = {
	user: AuthTokenUserFields;
-  };
+};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 51fc985 and a33c769.

📒 Files selected for processing (2)
  • src/graphql/context.ts (2 hunks)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Pull request workflow
src/graphql/context.ts

[error] 5-21: File formatting issues detected by biome check. The formatter would have printed changes for the 'AuthTokenUserFields' type declaration (lines 5-8) and for the closing bracket in 'ExplicitAuthenticationTokenPayload' (line 21). Please apply the suggested formatting changes.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (7)
src/graphql/context.ts (1)

6-6: LGTM! Type safety improvements.

The changes enhance type safety by:

  1. Creating a reusable AuthTokenUserFields type
  2. Updating ExplicitAuthenticationTokenPayload to include the user's role

Also applies to: 20-20

test/graphql/types/Community/updater.test.ts (6)

24-33: LGTM! Well-structured test context interface.

The TestContext interface properly extends GraphQLContext while overriding the necessary types for testing.


84-148: LGTM! Comprehensive test setup.

The test setup is thorough and includes:

  • Mock user with admin role
  • Mock community with all required fields
  • Complete test context with all necessary dependencies

150-156: LGTM! Core functionality tests.

Good coverage of the main success paths:

  • Fetching updater user
  • Handling null updaterId

Also applies to: 158-170


172-183: LGTM! Authentication and authorization tests.

Thorough testing of security checks:

  • Unauthenticated user handling
  • Unauthorized (non-admin) user handling

Also applies to: 185-202


225-242: LGTM! Error handling test.

Good coverage of database error scenario with proper error logging verification.


244-281: LGTM! Edge case handling.

Comprehensive test for fetching different user with proper verification of:

  • Multiple database calls
  • Correct updaterId usage

test/graphql/types/Community/updater.test.ts Outdated Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
@palisadoes
Copy link
Contributor

Did you merge with the latest upstream?

The sign up file was fixed a few days ago

Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 1, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

@NishantSinghhhhh
Copy link
Author

Did you merge with the latest upstream?

The sign up file was fixed a few days ago

Yes I did , My code was up to date

Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

@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: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a33c769 and 801912c.

📒 Files selected for processing (4)
  • src/graphql/context.ts (1 hunks)
  • src/graphql/types/Community/Community.ts (1 hunks)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
  • test/utilities/mockLogger.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (6)
src/graphql/types/Community/Community.ts (2)

11-17: Type definition looks good.
No issues observed with the CommunityResolvers definition.


35-39: Optimize database queries by removing redundant user lookup.
This is the same suggestion from a previous review. You can reuse the result from the first query instead of querying again.

Also applies to: 45-49

test/utilities/mockLogger.ts (1)

1-29: Mock logger implementation looks solid.
All relevant log methods are mocked for thorough testing, and the flexible child logger approach is a good design.

test/graphql/types/Community/updater.test.ts (3)

18-28: LGTM! Well-structured test context interface.

The TestContext interface is well-designed, properly extending GraphQLContext while adding type-safe mock implementations for the database client and logger.


29-44: LGTM! Type-safe mock PubSub implementation.

The mock PubSub implementation is well-structured with proper typing and handles all necessary operations including publish, subscribe, and asyncIterator.


51-114: LGTM! Comprehensive test setup with proper mocking.

The test setup is thorough with proper type safety and reset of mocks between tests. Good use of the mock logger utility.

src/graphql/types/Community/Community.ts Outdated Show resolved Hide resolved
src/graphql/types/Community/Community.ts Outdated Show resolved Hide resolved
src/graphql/context.ts Outdated Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Feb 1, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 801912c and 2bf7c05.

📒 Files selected for processing (1)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Pull request workflow
test/graphql/types/Community/updater.test.ts

[error] 143-143: Formatter would have printed the following content: unexpected empty line before line 143.


[error] Some errors were emitted while running checks.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (1)
test/graphql/types/Community/updater.test.ts (1)

51-114: LGTM! Well-structured test setup.

The test setup is comprehensive and follows best practices:

  • Proper test isolation through beforeEach
  • Complete mocking of dependencies
  • Realistic test data
🧰 Tools
🪛 GitHub Actions: Pull request workflow

[error] Some errors were emitted while running checks.

test/graphql/types/Community/updater.test.ts Outdated Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Show resolved Hide resolved
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 1, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

@NishantSinghhhhh
Copy link
Author

@palisadoes , I will be adding more tests in this PR , Do not merge it now , there aree lot many test cases that are left to be covered

Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 1, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@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: 5

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2bf7c05 and 2d7a2ad.

📒 Files selected for processing (1)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run tests for talawa api
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (1)
test/graphql/types/Community/updater.test.ts (1)

29-44: 🧹 Nitpick (assertive)

Enhance type safety in PubSub mock implementation.

The current implementation could be improved with stronger type checking for the event topic and payload.

 const createMockPubSub = () => ({
   publish: vi.fn().mockImplementation(
     (
-      event: {
-        topic: keyof PubSubEvents;
-        payload: PubSubEvents[keyof PubSubEvents];
+      event: {
+        topic: K extends keyof PubSubEvents ? K : never;
+        payload: K extends keyof PubSubEvents ? PubSubEvents[K] : never;
       },
       callback?: () => void,
     ) => {
       if (callback) callback();
       return;
     },
   ),
   subscribe: vi.fn(),
   asyncIterator: vi.fn(),
 });

Likely invalid or redundant comment.

test/graphql/types/Community/updater.test.ts Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Show resolved Hide resolved
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 1, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d499b07 and 0c8f326.

📒 Files selected for processing (1)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run tests for talawa api
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (6)
test/graphql/types/Community/updater.test.ts (6)

1-317: LGTM! Comprehensive test coverage.

The test suite provides thorough coverage of the Community updater resolver, including:

  • Authentication checks
  • Database error handling
  • Success cases
  • Edge cases
  • Proper error messages and logging

13-16: Consider expanding PubSubEvents type.

The PubSubEvents type appears incomplete as it only includes COMMUNITY_CREATED and POST_CREATED events. Consider adding other relevant events that might be used in the Community context.

Let's check for other event types in the codebase:


61-79: 🧹 Nitpick (assertive)

Simplify mock community object creation.

The mock community object contains many null fields that could be simplified using object spread.

 mockCommunity = {
   id: "community-123",
   name: "Test Community",
   createdAt: new Date(),
   updatedAt: new Date(),
   updaterId: "456",
-  facebookURL: null,
-  githubURL: null,
-  inactivityTimeoutDuration: null,
-  instagramURL: null,
-  linkedinURL: null,
-  logoMimeType: null,
-  logoName: null,
-  redditURL: null,
-  slackURL: null,
-  websiteURL: null,
-  xURL: null,
-  youtubeURL: null,
+  ...Object.fromEntries(
+    [
+      'facebookURL', 'githubURL', 'inactivityTimeoutDuration',
+      'instagramURL', 'linkedinURL', 'logoMimeType', 'logoName',
+      'redditURL', 'slackURL', 'websiteURL', 'xURL', 'youtubeURL'
+    ].map(key => [key, null])
+  )
 };

Likely invalid or redundant comment.


53-59: 🧹 Nitpick (assertive)

Use type-safe role constant.

Consider using a type-safe constant for the role value to prevent typos and ensure consistency.

+const USER_ROLES = {
+  ADMIN: 'administrator',
+  USER: 'user'
+} as const;

 mockUser = {
   id: "123",
   name: "John Doe",
-  role: "administrator",
+  role: USER_ROLES.ADMIN,
   createdAt: new Date(),
   updatedAt: null,
 };

Likely invalid or redundant comment.


187-205: 🛠️ Refactor suggestion

Remove duplicate test case.

This test case duplicates the functionality already tested in the "should make correct database queries with expected parameters" test at lines 143-164. Consider merging these tests to reduce redundancy.

-  it("should correctly query the database for current user and updater user", async () => {
-    const updaterUser = {
-      id: "456",
-      name: "Jane Updater",
-      role: "user",
-      createdAt: new Date(),
-      updatedAt: null,
-    };
-
-    ctx.drizzleClient.query.usersTable.findFirst
-      .mockResolvedValueOnce(mockUser) // First call for current user
-      .mockResolvedValueOnce(updaterUser); // Second call for updater user
-
-    await CommunityResolver.updater(mockCommunity, {}, ctx);
-
-    expect(ctx.drizzleClient.query.usersTable.findFirst).toHaveBeenCalledTimes(
-      2,
-    );
-  });

Likely invalid or redundant comment.


11-11: 🧹 Nitpick (assertive)

Remove unnecessary type alias.

The DeepPartial type is just an alias for the built-in Partial type. Consider removing this type alias and using Partial directly.

-type DeepPartial<T> = Partial<T>;

Likely invalid or redundant comment.

test/graphql/types/Community/updater.test.ts Show resolved Hide resolved
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 2, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c8f326 and 1ee17e9.

📒 Files selected for processing (1)
  • test/utilities/mockLogger.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run tests for talawa api
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (1)
test/utilities/mockLogger.ts (1)

1-4: LGTM! Well-structured imports and function signature.

The imports and function signature are appropriate for creating a mock logger.

test/utilities/mockLogger.ts Outdated Show resolved Hide resolved
test/utilities/mockLogger.ts Outdated Show resolved Hide resolved
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 2, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

@NishantSinghhhhh
Copy link
Author

@palisadoes , there is 1 type errror that was coming in this PR related to uuid , for that I have installed a new dependency
as the error was persistent

Screenshot from 2025-02-02 13-48-09

@NishantSinghhhhh
Copy link
Author

@coderabbitai full review

Copy link

coderabbitai bot commented Feb 2, 2025

✅ Actions performed

Full review triggered.

Copy link

@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: 6

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ee17e9 and 791a1ac.

📒 Files selected for processing (2)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
  • test/utilities/mockLogger.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run tests for talawa api
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (6)
test/utilities/mockLogger.ts (5)

4-7: LGTM!

The interface is well-defined with optional properties that allow flexible configuration of the mock logger.


9-40: 🧹 Nitpick (assertive)

Consider improving type safety and preventing infinite recursion.

The implementation is solid but could be improved in two areas:

  1. The type assertion could be replaced with a type guard.
  2. The child method could potentially cause infinite recursion.

Consider this improved implementation:

 export const createMockLogger = (
   config?: MockLoggerConfig,
+  depth: number = 0,
 ): FastifyBaseLogger => {
   const level = config?.level ?? "info";
   const enabledLevels =
     config?.enabledLevels ??
     new Set(["error", "warn", "info", "debug", "trace", "fatal", "silent"]);

   const logger = {
     error: vi.fn(),
     warn: vi.fn(),
     info: vi.fn(),
     debug: vi.fn(),
     trace: vi.fn(),
     fatal: vi.fn(),
     silent: vi.fn(),
-    child: () => createMockLogger(config),
+    child: () => depth < 10 ? createMockLogger(config, depth + 1) : logger,
     level,
     isLevelEnabled: (l: string) => enabledLevels.has(l),
     bindings: vi.fn().mockReturnValue({}),
     flush: vi.fn(),
     isFatalEnabled: () => enabledLevels.has("fatal"),
     isErrorEnabled: () => enabledLevels.has("error"),
     isWarnEnabled: () => enabledLevels.has("warn"),
     isInfoEnabled: () => enabledLevels.has("info"),
     isDebugEnabled: () => enabledLevels.has("debug"),
     isTraceEnabled: () => enabledLevels.has("trace"),
     isSilentEnabled: () => enabledLevels.has("silent"),
   };

+  // Type guard to ensure all required properties are implemented
+  const isComplete = (l: typeof logger): l is FastifyBaseLogger => {
+    const required: (keyof FastifyBaseLogger)[] = [
+      'error', 'warn', 'info', 'debug', 'trace', 'fatal',
+      'child', 'level', 'isLevelEnabled'
+    ];
+    return required.every(prop => prop in l);
+  };
+
+  if (!isComplete(logger)) {
+    throw new Error('Mock logger is missing required properties');
+  }

-  return logger as unknown as FastifyBaseLogger;
+  return logger;
 };

Likely invalid or redundant comment.


39-40: Type casting implementation looks good.

The current implementation maintains type compatibility while keeping the code simple, as discussed in previous reviews.


1-40: Overall implementation is well-structured and comprehensive.

The mock logger implementation provides all necessary functionality for testing purposes, with good defaults and configuration options. The code is clean and maintainable.


25-25: 🧹 Nitpick (assertive)

Optimize child logger creation.

The current implementation creates a new logger instance for each child, which could lead to memory issues in tests with deep chains of child loggers. Consider reusing the parent logger instance.

-child: () => createMockLogger(config),
+child: () => logger,

Likely invalid or redundant comment.

test/graphql/types/Community/updater.test.ts (1)

60-78: 🧹 Nitpick (assertive)

Simplify mock object creation.

The mock community object contains many null fields that could be simplified.

 mockCommunity = {
   id: "community-123",
   name: "Test Community",
   createdAt: new Date(),
   updatedAt: new Date(),
   updaterId: "456",
+  ...Object.fromEntries(
+    [
+      'facebookURL', 'githubURL', 'inactivityTimeoutDuration',
+      'instagramURL', 'linkedinURL', 'logoMimeType', 'logoName',
+      'redditURL', 'slackURL', 'websiteURL', 'xURL', 'youtubeURL'
+    ].map(key => [key, null])
+  )
-  facebookURL: null,
-  githubURL: null,
-  inactivityTimeoutDuration: null,
-  instagramURL: null,
-  linkedinURL: null,
-  logoMimeType: null,
-  logoName: null,
-  redditURL: null,
-  slackURL: null,
-  websiteURL: null,
-  xURL: null,
-  youtubeURL: null,
 };

Likely invalid or redundant comment.

test/graphql/types/Community/updater.test.ts Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Outdated Show resolved Hide resolved
test/utilities/mockLogger.ts Show resolved Hide resolved
test/utilities/mockLogger.ts Show resolved Hide resolved
Copy link

@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: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e2151ff and 791a1ac.

📒 Files selected for processing (3)
  • src/graphql/types/Community/Community.ts (1 hunks)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
  • test/utilities/mockLogger.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/graphql/types/Community/Community.ts

[warning] 53-53: src/graphql/types/Community/Community.ts#L53
Added line #L53 was not covered by tests


[warning] 57-64: src/graphql/types/Community/Community.ts#L57-L64
Added lines #L57 - L64 were not covered by tests

🔇 Additional comments (5)
src/graphql/types/Community/Community.ts (4)

3-5: All good with the imports.
The added imports for TalawaGraphQLError, GraphQLContext, and User are appropriate and enhance type safety and error handling.


11-17: Type definitions look solid.
Defining CommunityResolvers with a clear return type of Promise<User | null> helps ensure that the resolver’s contract is properly enforced.


35-40: Duplicate DB queries for the same user.
The code performs two queries for the same updaterId. Reuse the first query result to avoid an unnecessary second lookup.

Also applies to: 51-55


53-53: Add test coverage for the second query’s null or undefined results.
Some lines remain untested (e.g., lines 53, 57–64). Although certain error paths are covered, consider adding a test where the second query specifically returns undefined or triggers the isNull condition in the query.

Also applies to: 57-64

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 53-53: src/graphql/types/Community/Community.ts#L53
Added line #L53 was not covered by tests

test/graphql/types/Community/updater.test.ts (1)

53-53: Confirm coverage of the second query condition.
Ensure there is a test case where parent.updaterId leads to the isNull check in the second query, or confirm that this code path is unreachable.

src/graphql/types/Community/Community.ts Show resolved Hide resolved
test/utilities/mockLogger.ts Outdated Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Show resolved Hide resolved
@NishantSinghhhhh
Copy link
Author

NishantSinghhhhh commented Feb 2, 2025

@palisadoes , CodeRabbit is asking me to change the backend code , as it states that adding role based authorization , which will require changing a lot many backend files

so I am not adding those changes

Copy link

coderabbitai bot commented Feb 2, 2025

✅ Actions performed

Full review triggered.

@NishantSinghhhhh
Copy link
Author

@coderabbitai full review

Copy link

coderabbitai bot commented Feb 2, 2025

✅ Actions performed

Full review triggered.

Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 2, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 2, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

@NishantSinghhhhh
Copy link
Author

NishantSinghhhhh commented Feb 2, 2025

@palisadoes, I have completed this PR and added as many test cases as possible. I also included the uuid dependency, as its absence was causing a type error in one of the files.

Screenshot from 2025-02-02 13-48-09

Additionally, I have incorporated most of the genuine changes requested by coderabbitai. also , I have tried doing full review by coderabbit a lot many times , but it is not responding anything

If there are any other important modifications you'd like me to make, please let me know, and I'll address them right away. Otherwise, I'll proceed with working on the next component.

@NishantSinghhhhh
Copy link
Author

@coderabbitai full review

Copy link

coderabbitai bot commented Feb 2, 2025

✅ Actions performed

Full review triggered.

Copy link

@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: 5

♻️ Duplicate comments (1)
src/graphql/types/Community/Community.ts (1)

36-56: 🛠️ Refactor suggestion

Consolidate redundant user lookups.

This code executes two separate queries (existingUser and updater) against the same table and effectively checks the same condition. You can unify the logic into a single query while retaining or adjusting the error checks, thereby improving performance and clarity.

const updater = await context.drizzleClient.query.usersTable.findFirst({
  where: (users, { eq }) => eq(users.id, updaterId), 
});

if (!updater) {
  context.log.warn(`No user found for updaterId: ${updaterId}`);
  throw new TalawaGraphQLError({
    message: "Updater user not found",
    extensions: {
      code: "arguments_associated_resources_not_found",
      issues: [{ argumentPath: ["updaterId"] }],
    },
  });
}

return updater;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 791a1ac and fb6fa53.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • package.json (2 hunks)
  • src/graphql/types/Community/Community.ts (1 hunks)
  • test/graphql/types/Community/updater.test.ts (1 hunks)
  • test/utilities/mockLogger.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
test/graphql/types/Community/updater.test.ts (1)
Learnt from: NishantSinghhhhh
PR: PalisadoesFoundation/talawa-api#3110
File: test/graphql/types/Community/updater.test.ts:278-301
Timestamp: 2025-02-02T08:24:26.022Z
Learning: In Talawa API, for invalid input validation errors, use TalawaGraphQLError with code "invalid_arguments" and include the required "issues" array containing argumentPath and message. Don't use generic error codes like "bad_user_input".
🪛 GitHub Actions: Pull request workflow
src/graphql/types/Community/Community.ts

[error] 32-32: Formatter would have printed the following content indicating formatting issues.

test/graphql/types/Community/updater.test.ts

[error] 298-298: Formatter would have printed the following content indicating formatting issues.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (3)
src/graphql/types/Community/Community.ts (1)

69-75: Good error handling approach.

Catching and logging database errors here is a solid practice. It ensures troubleshooting information is retained. The usage of TalawaGraphQLError for rethrowing maintains consistency with the rest of the codebase.

test/utilities/mockLogger.ts (1)

16-51: 🧹 Nitpick (assertive)

Prevent potential infinite recursion in child loggers.

child: () => createMockLogger(config) can recursively create nested loggers. While this may not necessarily cause issues in short test runs, adding a depth limit or returning the same logger instance helps avoid corner cases.

child: (() => {
  let depth = 0;
  return () => {
+   if (depth >= 3) {
+     return logger as FastifyBaseLogger;
+   }
    depth++;
    return createMockLogger(config);
  };
})(),

Likely invalid or redundant comment.

package.json (1)

42-42: @types/uuid Type Definitions Enhancement

Introducing "@types/uuid": "^10.0.0" as a dev dependency improves type safety when working with UUIDs. However, note that modern versions of the uuid library (such as v11) may already include built-in TypeScript definitions. Please verify that adding this dependency is necessary and does not introduce any conflicts or redundant type definitions.

src/graphql/types/Community/Community.ts Outdated Show resolved Hide resolved
test/utilities/mockLogger.ts Outdated Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Outdated Show resolved Hide resolved
test/graphql/types/Community/updater.test.ts Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
Copy link

github-actions bot commented Feb 2, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

@NishantSinghhhhh
Copy link
Author

@palisadoes, I have completed this PR and added as many test cases as possible. Can you tell me what more things I can add to make it more mergeable

@palisadoes palisadoes changed the title Updater vitest Test: src/graphql/types/Community/updater.ts Feb 3, 2025
@palisadoes palisadoes merged commit 8e74cfe into PalisadoesFoundation:develop-postgres Feb 3, 2025
17 of 18 checks passed
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.

2 participants