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

fixed super admin profile #2340

Closed

Conversation

ARYANSHAH1567
Copy link
Contributor

@ARYANSHAH1567 ARYANSHAH1567 commented Oct 18, 2024

What kind of change does this PR introduce?

Bugfix

Issue Number:

Fixes #1924

It does not give error as CreatorId is being passed to the talawa-api so i havefixed it in the api also so that it handles it correctly and then it will not throw error
Screenshot 2024-09-21 004048

Summary by CodeRabbit

  • New Features

    • Introduced a new GraphQL query to retrieve organizations by creator ID, enhancing data retrieval based on specific user associations.
  • Bug Fixes

    • Improved testing for the LeftDrawerOrg component to ensure more reliable assertions in asynchronous scenarios.
  • Refactor

    • Updated the LeftDrawerOrg component to utilize the new query, aligning data retrieval with the creator's ID instead of a general organization ID.
    • Adjusted mock data in tests to reflect the new organization details and structure.

Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The pull request introduces a new GraphQL query, ORGANIZATIONS_LIST_BY_CREATOR_ID, designed to fetch organizations based on a specific creator's ID, incorporating various fields for detailed organization information. Additionally, it modifies the existing ORGANIZATIONS_LIST query to align with the new data structure. Changes in the LeftDrawerOrg component reflect this new query, updating the data retrieval logic.

Changes

File Path Change Summary
src/GraphQl/Queries/Queries.ts Added new query ORGANIZATIONS_LIST_BY_CREATOR_ID and updated ORGANIZATIONS_LIST structure.
src/components/LeftDrawerOrg/LeftDrawerOrg.tsx Updated query import from ORGANIZATIONS_LIST to ORGANIZATIONS_LIST_BY_CREATOR_ID.
src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx Updated mocked responses in tests to use ORGANIZATIONS_LIST_BY_CREATOR_ID.

Assessment against linked issues

Objective Addressed Explanation
Tests must be created for this fix (1924) No tests related to the Super Admin profile error were added.
All tests must be valid and pass (1924) No validation of existing tests was mentioned in the changes.

Possibly related PRs

  • pagination and placeholder 2117 #2297: This PR modifies the Organizations.tsx file to change the placeholder text for searching organizations, which is related to the new GraphQL query ORGANIZATIONS_LIST_BY_CREATOR_ID introduced in the main PR, as both involve organization data handling.

Suggested reviewers

  • palisadoes

🐰 In the meadow where bunnies play,
A new query hops in, brightening the day.
With creator IDs, we fetch with delight,
Organizations gather, all in plain sight.
Testing is stronger, no more waiting in vain,
Hooray for the changes, let’s dance in the rain! 🌧️✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7c2f363 and d78a465.

📒 Files selected for processing (1)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx

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

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

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

🧹 Outside diff range and nitpick comments (2)
src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx (2)

Line range hint 1-458: Suggestions for further test improvements

While the test suite is comprehensive, here are some suggestions to further enhance its robustness and consistency:

  1. Consider replacing all instances of the custom wait function with waitFor from @testing-library/react for consistency and improved reliability.

  2. Some test descriptions could be more specific. For example, "Testing Menu Buttons" could be "Clicking Dashboard button navigates to the correct route".

  3. Add an explicit test for error handling when fetching organizations fails. This could involve mocking a network error response.

  4. For consistency, consider using either userEvent or fireEvent throughout the file, not both. userEvent is generally preferred as it more closely simulates real user interactions.

  5. The resizeWindow function could be moved to a separate test utilities file if it's used in other test files as well.

These changes would further improve the test suite's reliability and maintainability.


Line range hint 1-458: Additional test coverage needed for the reported bug fix

While this test file provides good coverage for the LeftDrawerOrg component, it doesn't directly address the bug fix mentioned in the PR objectives (error when editing the Super Admin profile). To ensure the reported issue is resolved and prevent regression, consider adding the following tests:

  1. A test case that simulates editing the Super Admin profile and verifies that no error occurs.
  2. A test that checks the correct handling of CreatorId when passed to the talawa-api.
  3. Tests for the new GraphQL query ORGANIZATIONS_LIST_BY_CREATOR_ID mentioned in the AI summary.
  4. Tests for any modifications made to the LeftDrawerOrg component related to the bug fix.

Adding these tests will increase confidence in the bug fix and improve overall test coverage.

Would you like assistance in drafting these additional test cases?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7496bb3 and dc9617c.

📒 Files selected for processing (3)
  • src/GraphQl/Queries/Queries.ts (2 hunks)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx (2 hunks)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.tsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (6)
src/components/LeftDrawerOrg/LeftDrawerOrg.tsx (4)

186-186: LGTM! Minor style improvement.

Moving the export statement to its own line is a good stylistic choice. It improves code readability by clearly separating the component definition from its export.


Line range hint 1-186: Summary: Changes address the Super Admin profile editing issue effectively.

The modifications to the GraphQL query and its usage in this component are well-aligned with the PR objectives. These changes should resolve the issue #1924 by correctly fetching organizations based on the creator's ID for the Super Admin profile. The component's core logic remains intact, focusing the changes on the data retrieval mechanism.

To ensure the effectiveness of these changes:

  1. Verify that the new query ORGANIZATIONS_LIST_BY_CREATOR_ID is correctly defined and used consistently across the codebase.
  2. Test the Super Admin profile editing functionality to confirm that the error has been resolved.
  3. Update any relevant documentation or comments to reflect the new query usage.

Overall, these changes appear to be a solid fix for the reported issue.


3-3: LGTM! Verify query usage across the codebase.

The import change from ORGANIZATIONS_LIST to ORGANIZATIONS_LIST_BY_CREATOR_ID aligns with the PR objective to fix the Super Admin profile editing issue. This more specific query should resolve the error mentioned in issue #1924.

To ensure consistency, let's verify the usage of this new query across the codebase:


52-53: LGTM! Verify query structure and variable usage.

The update to use ORGANIZATIONS_LIST_BY_CREATOR_ID with creatorId: orgId is consistent with the import change and should resolve the Super Admin profile editing issue.

Let's verify the structure of the new query and its variable usage:

src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx (1)

307-307: Excellent improvement in test reliability!

This change from await wait() to await waitFor(() => expect(screen.getByTestId(/OrgBtn/i)).toBeInTheDocument()) is a significant improvement in the test's reliability and specificity. Here's why this change is beneficial:

  1. It uses the waitFor function from @testing-library/react, which is designed specifically for handling asynchronous operations in React tests.
  2. The new code includes an explicit expectation, making the test more precise about what it's waiting for.
  3. This approach reduces the likelihood of false positives that could occur with a simple timeout.
  4. It aligns with current best practices for testing asynchronous React components.

This change will make the test more robust and less prone to flakiness, especially in CI/CD environments where timing can be unpredictable.

src/GraphQl/Queries/Queries.ts (1)

338-341: Verify the correctness of the creatorId filter

In the ORGANIZATIONS_LIST_BY_CREATOR_ID query (lines 339-341), ensure that filtering by creatorId functions as intended. Confirm that the creatorId field exists on the Organization model and is the appropriate field for identifying the creator of an organization.

Run the following script to confirm that creatorId is a valid field in the Organization schema:

src/GraphQl/Queries/Queries.ts Show resolved Hide resolved
src/GraphQl/Queries/Queries.ts Show resolved Hide resolved
src/GraphQl/Queries/Queries.ts Show resolved Hide resolved
Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.53%. Comparing base (7496bb3) to head (b97ec03).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2340      +/-   ##
===========================================
- Coverage    97.62%   97.53%   -0.09%     
===========================================
  Files          250      250              
  Lines         7188     7189       +1     
  Branches      2069     2071       +2     
===========================================
- Hits          7017     7012       -5     
- Misses         159      165       +6     
  Partials        12       12              

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

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 18, 2024
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

🧹 Outside diff range and nitpick comments (1)
src/GraphQl/Queries/Queries.ts (1)

338-392: Consider Adding Unit Tests for the New Query

To ensure the reliability of the ORGANIZATIONS_LIST_BY_CREATOR_ID query and to prevent future regressions, it's recommended to add unit tests covering various scenarios such as valid creator IDs, invalid IDs, and cases where no organizations are returned. This will enhance the robustness of the application and align with best practices.

Would you like assistance in creating these unit tests or opening a GitHub issue to track this task?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dc9617c and ebc8ac0.

📒 Files selected for processing (3)
  • src/GraphQl/Queries/Queries.ts (1 hunks)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx (3 hunks)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx
  • src/components/LeftDrawerOrg/LeftDrawerOrg.tsx
🧰 Additional context used
🔇 Additional comments (1)
src/GraphQl/Queries/Queries.ts (1)

338-392: Addition of ORGANIZATIONS_LIST_BY_CREATOR_ID Query is Well-Implemented

The new GraphQL query ORGANIZATIONS_LIST_BY_CREATOR_ID correctly retrieves organizations based on the creator's ID and includes all the necessary fields. It aligns with the existing codebase conventions and should effectively address the bug related to editing the Super Admin profile as outlined in the PR objectives.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 18, 2024
@pranshugupta54
Copy link
Member

Please fix failing tests

@ARYANSHAH1567
Copy link
Contributor Author

Please fix failing tests

I am working on it i dont know why is the test coverage failing

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 22, 2024
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

🧹 Outside diff range and nitpick comments (2)
src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx (2)

80-80: LGTM: Mock updated correctly with a minor suggestion.

The GraphQL query in the MOCKS array has been correctly updated to ORGANIZATIONS_LIST_BY_CREATOR_ID. This change is consistent with the import statement update and aligns with the PR objective.

Consider updating the mock data to include a creatorId field in the returned organization object, as it might be relevant for the new query:

 organizations: [
   {
     _id: '123',
+    creatorId: '123', // Add this line
     image: null,
     creator: {
       firstName: 'John',
       lastName: 'Doe',
       email: '[email protected]',
     },
     // ... rest of the mock data
   },
 ],

This addition would make the mock data more representative of the expected API response for the new query.


143-143: LGTM: Mock updated correctly with a minor suggestion.

The GraphQL query in the MOCKS_WITH_IMAGE array has been correctly updated to ORGANIZATIONS_LIST_BY_CREATOR_ID. This change is consistent with the previous updates in the file and aligns with the PR objective.

Similar to the previous suggestion, consider updating the mock data to include a creatorId field in the returned organization object:

 organizations: [
   {
     _id: '123',
+    creatorId: '123', // Add this line
     image: 'https://api.dicebear.com/5.x/initials/svg?seed=Test%20Organization',
     creator: {
       firstName: 'John',
       lastName: 'Doe',
       email: '[email protected]',
     },
     // ... rest of the mock data
   },
 ],

This addition would make the mock data more representative of the expected API response for the new query.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6ca5501 and 7559143.

📒 Files selected for processing (3)
  • src/GraphQl/Queries/Queries.ts (1 hunks)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx (4 hunks)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/LeftDrawerOrg/LeftDrawerOrg.tsx
🧰 Additional context used
🔇 Additional comments (3)
src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx (2)

Line range hint 1-443: Summary: Test file updated correctly to use new GraphQL query.

The changes in this file consistently update the GraphQL query from ORGANIZATIONS_LIST to ORGANIZATIONS_LIST_BY_CREATOR_ID across all mock data. These modifications align with the PR objective of fixing the Super Admin profile editing issue.

Key points:

  1. Import statement updated (line 14)
  2. MOCKS array updated (line 80)
  3. MOCKS_WITH_IMAGE array updated (line 143)
  4. MOCKS_EMPTY array updated (line 207, not highlighted but verified)

The structure of the tests remains unchanged, which is correct as the functionality being tested should remain the same. The only difference is the query being used to fetch the data.

To ensure all tests are passing with the new changes:

#!/bin/bash
# Description: Run tests for the LeftDrawerOrg component

# Test: Run Jest tests for LeftDrawerOrg
npm test -- src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx

If any tests fail, please review and update them accordingly.


14-14: LGTM: Import statement updated correctly.

The import statement has been updated to use ORGANIZATIONS_LIST_BY_CREATOR_ID instead of ORGANIZATIONS_LIST. This change aligns with the PR objective and is consistent with the modifications mentioned in the summary.

To ensure consistency, let's verify that this change is applied throughout the file:

✅ Verification successful

Verified: Import statement updated consistently.

All instances of ORGANIZATIONS_LIST have been successfully replaced with ORGANIZATIONS_LIST_BY_CREATOR_ID throughout the file. No inconsistent usages detected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that ORGANIZATIONS_LIST_BY_CREATOR_ID is used consistently throughout the file.

# Test: Search for any remaining instances of ORGANIZATIONS_LIST
rg -i 'ORGANIZATIONS_LIST(?!_BY_CREATOR_ID)' src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx

# Test: Confirm the usage of ORGANIZATIONS_LIST_BY_CREATOR_ID
rg 'ORGANIZATIONS_LIST_BY_CREATOR_ID' src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx

Length of output: 879


Script:

#!/bin/bash
# Description: Verify that there are no remaining instances of ORGANIZATIONS_LIST not replaced with ORGANIZATIONS_LIST_BY_CREATOR_ID.

# Test: Search for any remaining instances of ORGANIZATIONS_LIST not followed by _BY_CREATOR_ID using PCRE2.
rg -i --pcre2 'ORGANIZATIONS_LIST(?!_BY_CREATOR_ID)' src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx

# Confirm the usage of ORGANIZATIONS_LIST_BY_CREATOR_ID
rg 'ORGANIZATIONS_LIST_BY_CREATOR_ID' src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx

Length of output: 413

src/GraphQl/Queries/Queries.ts (1)

338-392: LGTM!

The ORGANIZATIONS_LIST_BY_CREATOR_ID query is implemented correctly and follows the existing code patterns. The fields included are appropriate for fetching detailed organization information based on the creator's ID.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 22, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 22, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 22, 2024
@ARYANSHAH1567 ARYANSHAH1567 deleted the admin_profile branch November 1, 2024 10:32
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