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

migrated test/rotes/graphql/Mutation/updateChatMessage to integration test #3344

Open
wants to merge 3 commits into
base: develop-postgres
Choose a base branch
from

Conversation

Piyushk8
Copy link

@Piyushk8 Piyushk8 commented Mar 8, 2025

What kind of change does this PR introduce?

  • Migrated updateChatMessage test from unit (mock) to integration (real schema) with 100% coverage.

  • Fixed parentMessageId in MutattonCreateChatMessageInput in file src/graphql/input/MutattonCreateChatMessageInput from required (true) to required (false) for replies/threads.

  • Made changes the schema for the same by pnpm generate_graphql_sdl_file and pnpm generate_gql_tada

Issue Number:

Fixes #3274

Snapshots/Videos:
Screenshot 2025-03-07 014246

Summary

  • Migrated test to integration for real schema testing of mutations/queries.

  • Fixed parentMessageId in MutattonCreateChatMessageInput in file src/graphql/input/MutattonCreateChatMessageInput from required (true) to required (false) for replies/threads.

  • due to unexpected behavior on creating a new message as a standalone message required parentMessageID which needs to undefined but was required true.

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

Summary by CodeRabbit

  • New Features
    • Introduced new chat operations including creating chats, sending messages, updating messages, and managing memberships through the GraphQL API.
    • Now you can create a chat message without mandatorily linking it to a parent, supporting both replies and standalone messages.
    • Enhanced response structures for chat-related mutations, providing additional context and relationships in the data returned.
  • Improvements
    • Enhanced chat message updates with streamlined processing and robust error handling for a more reliable experience.
    • Comprehensive test coverage added for the updateChatMessage mutation, ensuring various scenarios are properly handled.

Copy link

coderabbitai bot commented Mar 8, 2025

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
duplicated mapping key in ".coderabbit.yaml" (15:3)

 12 |   high_level_summary: true
 13 |   review_status: true
 14 |   collapse_walkthrough: false
 15 |   request_changes_workflow: true
--------^
 16 |   auto_review:
 17 |     enabled: true
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

This pull request updates several GraphQL chat-related components. The primary change is modifying the parentMessageId field in the MutationCreateChatMessageInput type to be nullable instead of required. Additionally, the update chat message logic has been refactored to use an inline mutation field definition, while corresponding tests have been overhauled to cover authentication, authorization, validation, and error scenarios. New GraphQL mutation definitions for chat creation, messaging, updates, and memberships have also been added.

Changes

File(s) Change Summary
schema.graphql, src/graphql/inputs/MutationCreateChatMessageInput.ts, test/routes/graphql/gql.tada.d.ts Changed the parentMessageId field from non-nullable to nullable and updated the required attribute accordingly in the MutationCreateChatMessageInput type.
src/graphql/types/Mutation/updateChatMessage.ts Refactored the update chat message logic by removing the standalone resolver and integrating it directly into a mutation field using builder.mutationField, while preserving authentication, validation, and error handling.
test/routes/graphql/Mutation/updateChatMessage.test.ts Rewrote the test suite for the updateChatMessage mutation to include comprehensive tests for authentication, authorization, invalid arguments, non-existing messages, unexpected errors, and successful updates.
test/routes/graphql/documentNodes.ts, test/routes/graphql/gql.tada-cache.d.ts Added new GraphQL mutation definitions related to chat operations, including creating chats, chat messages, updating messages, and creating chat memberships.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant G as GraphQL Server
    participant V as Validator
    participant DB as Database
    C->>G: Execute updateChatMessage mutation with input
    G->>G: Verify authentication (isAuthenticated)
    G->>V: Validate input arguments
    V-->>G: Return validated input / error
    G->>DB: Fetch current user and chat message
    DB-->>G: Provide user and message data
    G->>G: Check authorization for update
    G->>DB: Update chat message details
    DB-->>G: Return updated message
    G-->>C: Return updated message or error
Loading

Possibly related PRs

Suggested reviewers

  • palisadoes
  • disha1202

🐰 In the chat where messages flow,
The parent ID can now let go.
With updates made and tests anew,
Our chats will thrive, and friendships too!
Hooray for changes, let’s all cheer,
For clearer paths, we hold so dear! 🌟

✨ Finishing Touches
  • 📝 Generate Docstrings

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

github-actions bot commented Mar 8, 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

@GlenDsza GlenDsza added the ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files label Mar 8, 2025
Copy link

codecov bot commented Mar 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.10%. Comparing base (ca4d8ae) to head (28cb9a2).

Additional details and impacted files
@@                 Coverage Diff                  @@
##           develop-postgres    #3344      +/-   ##
====================================================
+ Coverage             50.58%   51.10%   +0.52%     
====================================================
  Files                   466      466              
  Lines                 35030    35025       -5     
  Branches               1101     1136      +35     
====================================================
+ Hits                  17720    17900     +180     
+ Misses                17308    17123     -185     
  Partials                  2        2              

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 8, 2025
@Piyushk8 Piyushk8 closed this Mar 8, 2025
@Piyushk8 Piyushk8 reopened this Mar 8, 2025
@palisadoes
Copy link
Contributor

Please make a minor commit. The sensitive file check should then pass

@Piyushk8
Copy link
Author

Piyushk8 commented Mar 8, 2025

Please make a minor commit. The sensitive file check should then pass

I think it's passing now all checks succeeded after re run

@palisadoes
Copy link
Contributor

@disha1202 @meetulr @GlenDsza PTAL

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

🧹 Nitpick comments (4)
test/routes/graphql/documentNodes.ts (1)

725-737: Include role in Mutation_createChatMembership return data.

Since roles are often important for verifying membership level, returning the role alongside id and timestamps may streamline client usage.

Example diff adding role:

 createChatMembership(input: $input) {
   id
   createdAt
   creator {
     id
     name
   }
   updatedAt
+  role
 }
test/routes/graphql/Mutation/updateChatMessage.test.ts (3)

21-136: Consolidate repeated test setup logic for unauthenticated scenarios.

This block thoroughly checks unauthenticated states. However, the steps for signing in as an administrator, creating users, and executing mutations appear multiple times. Consider extracting them into shared test utilities to reduce duplication and improve maintainability.


304-346: Extend validation to additional missing resources, if needed.

This test ensures an error is raised for a non-existing message. If the code also handles other missing resources (e.g., missing chat), consider adding parallel checks to maximize coverage.


517-646: Break down overly large success-path test for clarity.

The final success test is comprehensive but somewhat lengthy, making it harder to maintain. Consider factoring out repeated steps into helper functions or test fixtures.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc9580d and 28cb9a2.

📒 Files selected for processing (9)
  • schema.graphql (1 hunks)
  • src/graphql/inputs/MutationCreateChatMessageInput.ts (1 hunks)
  • src/graphql/types/Mutation/updateChatMessage.ts (1 hunks)
  • test/routes/graphql/Mutation/updateChatMessage.test.ts (1 hunks)
  • test/routes/graphql/documentNodes.ts (1 hunks)
  • test/routes/graphql/gql.tada-cache.d.ts (1 hunks)
  • test/routes/graphql/gql.tada.d.ts (1 hunks)
  • test/routes/graphql/documentNodes.ts (1 hunks)
  • test/routes/graphql/gql.tada-cache.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/graphql/inputs/MutationCreateChatMessageInput.ts
  • schema.graphql
  • test/routes/graphql/gql.tada.d.ts
  • src/graphql/types/Mutation/updateChatMessage.ts
🧰 Additional context used
🧠 Learnings (2)
test/routes/graphql/Mutation/updateChatMessage.test.ts (2)
Learnt from: iamanishx
PR: PalisadoesFoundation/talawa-api#3174
File: test/routes/graphql/Mutation/updateChatMessage.test.ts:6-16
Timestamp: 2025-02-10T13:05:53.364Z
Learning: For test files in development environment, it's acceptable to define simplified interfaces locally instead of importing production types, as it's more pragmatic and includes only the fields needed for testing.
Learnt from: iamanishx
PR: PalisadoesFoundation/talawa-api#3174
File: src/graphql/types/Mutation/updateChatMessage.ts:124-141
Timestamp: 2025-02-10T10:03:45.272Z
Learning: When reviewing test-focused PRs in talawa-api, suggestions should be limited to test implementation aspects unless the changes directly impact test coverage. Modifications to existing business logic should be handled in separate PRs to maintain clear scope boundaries.
test/routes/graphql/gql.tada-cache.d.ts (1)
Learnt from: yugal07
PR: PalisadoesFoundation/talawa-api#3218
File: test/routes/graphql/gql.tada-cache.d.ts:61-62
Timestamp: 2025-02-18T06:09:11.711Z
Learning: The file `test/routes/graphql/gql.tada-cache.d.ts` is auto-generated from GraphQL schema/queries and should not be modified directly.
⏰ 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/routes/graphql/Mutation/updateChatMessage.test.ts (4)

1-20: No issues identified with imports and initial setup.

These import statements and helper references are consistent and clear.


140-301: Authorization check is well-covered.

The tests accurately validate the unauthorized_action_on_arguments_associated_resources code path when the user lacks necessary membership. The approach is solid, and the expectations are correct.


348-386: Robust invalid argument handling.

Using an empty message body to trigger an invalid_arguments error is a good approach. The expectations align well with typical GraphQL validation errors.


388-515: Good use of mocking to simulate an unexpected DB state.

This test cleverly mocks the database update to return no rows, capturing the unexpected error scenario. The approach is effective for verifying fallback error handling.

test/routes/graphql/gql.tada-cache.d.ts (2)

81-82: Confirm addition of fileUrl in Mutation_createPresignedUrl.

Adding fileUrl to the presigned URL response can be helpful, but confirm it exists in the actual schema. This file is auto-generated, so any discrepancies should be corrected at the schema level.


83-94: Validate newly added chat-related definitions.

The new Chat queries and mutations (CreateChat, CreateChatMessage, UpdateChatMessage, CreateChatMembership, etc.) appear consistent with the rest of the schema. However, remember that these definitions will be overwritten if gql.tada is regenerated, so ensure the backing schema reflects these changes permanently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants