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

Query returns null for the image field of the likedBy object of the post. #2507

Merged
merged 21 commits into from
Sep 28, 2024

Conversation

prayanshchh
Copy link

@prayanshchh prayanshchh commented Sep 3, 2024

What kind of change does this PR introduce?
bugfix

Issue Number:
#2262
Fixes #

Did you add tests for your changes?
Yes

Snapshots/Videos:
image

If relevant, did you update the documentation?
No

Summary
This solves the issue of null image of users that had liked posts.

Does this PR introduce a breaking change?
No, it's a bug fix

Other information

Have you read the contributing guide?
yes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced post retrieval by including additional user data related to the likedBy field, such as user images, first names, and last names, improving the richness of information available to users.
  • Bug Fixes
    • Improved formatting and clarity in installation and documentation files for better user experience.
  • Tests
    • Introduced new unit tests for post-related resolvers to ensure correct functionality of the like feature and data retrieval.
  • Configuration Changes
    • Adjusted configuration settings for improved test execution performance and consistency in formatting.

Copy link

coderabbitai bot commented Sep 3, 2024

Walkthrough

The changes include an update to the posts resolver, where a .populate() method is added to enhance data retrieval related to the likedBy field, specifically fetching image, firstName, and lastName properties of associated users. Additionally, various documentation and configuration files underwent minor formatting adjustments, including newline additions and spacing corrections, without affecting the functionality.

Changes

Files Change Summary
src/resolvers/Organization/posts.ts Added .populate() method to the posts resolver to retrieve user image, firstName, and lastName data related to likedBy.
.coderabbit.yaml, README.md Minor formatting changes, including newline additions and adjustments to spacing and indentation, with no impact on functionality.
INSTALLATION.md, docker-compose.prod.yaml, scripts/cloud-api-demo/README.md, tests/helpers/userAndOrg.ts, tests/resolvers/Post/likedBy.spec.ts, vite.config.mts Minor formatting changes, including newline additions and adjustments to quotation marks, with no impact on functionality.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PostsResolver
    participant Database

    Client->>PostsResolver: Request posts
    PostsResolver->>Database: Query posts
    Database-->>PostsResolver: Return posts data
    PostsResolver->>Database: Populate likedBy images, firstName, lastName
    Database-->>PostsResolver: Return populated data
    PostsResolver-->>Client: Return posts with user details
Loading

Possibly related issues

  • Test: src/resolvers/User/posts.ts #1928: This issue seeks to ensure 100% test coverage for the posts.ts file, which aligns with the changes made to the posts resolver, potentially facilitating the addition of relevant tests.

Poem

🐰 In fields of code, a change so bright,
A hop to gather data right.
With images and names that cheer,
Our posts now shine, oh so clear!
A little tweak, a joyful dance,
In every like, a new romance! 🌼


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

github-actions bot commented Sep 3, 2024

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

@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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 95597d7 and 164fe8a.

Files selected for processing (1)
  • src/resolvers/Organization/posts.ts (1 hunks)
Additional comments not posted (1)
src/resolvers/Organization/posts.ts (1)

82-85: LGTM!

The code changes correctly populate the likedBy field with the image property, fixing the issue of the image field returning null for users who liked the post.

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 3, 2024
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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 164fe8a and d85440b.

Files selected for processing (1)
  • src/resolvers/Organization/posts.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/resolvers/Organization/posts.ts

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 3, 2024
Copy link

codecov bot commented Sep 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.77%. Comparing base (2683bbf) to head (903bde9).
Report is 5 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2507   +/-   ##
========================================
  Coverage    98.77%   98.77%           
========================================
  Files          355      355           
  Lines        17992    17996    +4     
  Branches      2400     2400           
========================================
+ Hits         17772    17776    +4     
  Misses         220      220           

☔ 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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d85440b and 3d9c4df.

Files selected for processing (1)
  • src/resolvers/Organization/posts.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/resolvers/Organization/posts.ts

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 4, 2024
@prayanshchh
Copy link
Author

@pranshugupta54 can you please review it sir?

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

Please add a test to ensure that this error doesn't repeat itself.

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

Commits

Files that changed from the base of the PR and between 3d9c4df and e26e6a4.

Files selected for processing (8)
  • .coderabbit.yaml (1 hunks)
  • INSTALLATION.md (1 hunks)
  • README.md (1 hunks)
  • docker-compose.prod.yaml (1 hunks)
  • scripts/cloud-api-demo/README.md (1 hunks)
  • tests/helpers/userAndOrg.ts (1 hunks)
  • tests/resolvers/Post/likedBy.spec.ts (1 hunks)
  • vite.config.mts (1 hunks)
Files skipped from review due to trivial changes (6)
  • .coderabbit.yaml
  • INSTALLATION.md
  • README.md
  • docker-compose.prod.yaml
  • scripts/cloud-api-demo/README.md
  • vite.config.mts
Additional comments not posted (1)
tests/resolvers/Post/likedBy.spec.ts (1)

17-38: Setup and Teardown Functions: Well Implemented

The beforeAll and afterAll functions are correctly implemented using async/await to handle asynchronous operations, ensuring that the database connection is properly managed before and after tests.

Comment on lines 40 to 74
describe("resolvers -> organization -> posts", () => {
it(`returns the post object for parent post`, async () => {
const parent = await Organization.findById(testOrganization?._id).lean();

if (!parent) {
throw new Error("Parent organization not found.");
}

const postPayload = (await postResolver?.(parent, { first: 1 }, {})) as {
edges: { node: InterfacePost }[];
totalCount: number;
};

expect(postPayload).toBeDefined();
if (!postPayload) {
throw new Error("postPayload is null or undefined");
}
expect(postPayload.edges).toBeDefined();
expect(Array.isArray(postPayload.edges)).toBe(true);

const posts = await Post.find({
organization: testOrganization?._id,
}).lean();

console.log("postPayloadedge:", postPayload.edges[0].node.likedBy[0]);
console.log("posts:", posts[0].likedBy[0]);

expect(postPayload.edges.length).toEqual(posts.length);
expect(postPayload.totalCount).toEqual(posts.length);
const returnedPost = postPayload.edges[0].node;
expect(returnedPost._id).toEqual(testPost?._id.toString());
expect(returnedPost.likedBy).toHaveLength(1);
expect(returnedPost.likedBy[0]._id).toEqual(testUser?._id);
expect(returnedPost.likedBy[0].image).not.toBeNull();
});
Copy link

Choose a reason for hiding this comment

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

Test Case Review: Comprehensive but Consider Removing Debug Logs

The test case is well-structured and checks important aspects of the likedBy functionality. However, consider removing or commenting out the debug logs at lines 64-65 for cleaner test output in production environments.

@@ -24,7 +24,7 @@ export const createTestUser = async (): Promise<TestUserType> => {
password: `pass${nanoid().toLowerCase()}`,
firstName: `firstName${nanoid().toLowerCase()}`,
lastName: `lastName${nanoid().toLowerCase()}`,
image: null,
image: "exampleimageurl.com",
Copy link

Choose a reason for hiding this comment

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

Modification in createTestUser: Appropriate for Testing

The addition of a default image URL in the createTestUser function is a suitable change for testing scenarios involving user images. Consider documenting this default value in the function's JSDoc to inform other developers of its purpose and usage.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e26e6a4 and a8478c4.

Files selected for processing (1)
  • tests/resolvers/Post/likedBy.spec.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/resolvers/Post/likedBy.spec.ts

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a8478c4 and 37de8c9.

Files selected for processing (1)
  • tests/resolvers/Post/likedBy.spec.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/resolvers/Post/likedBy.spec.ts

@prayanshchh
Copy link
Author

prayanshchh commented Sep 8, 2024

@palisadoes I have added a test, this is the first time I have written a test so if you have any practices that I should follow, please share so that i can update this and keep that in mind for my next PR's, thank you sir.

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

Please make the suggested changes

.coderabbit.yaml Outdated
@@ -15,4 +15,4 @@ reviews:
- develop
- main
chat:
auto_reply: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Your PR has too many unnecessary files that don’t relate to your issue. You can from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit

Please apply these changes to this file.

INSTALLATION.md Outdated
@@ -324,8 +324,8 @@ Follow these steps for setting up a software development environment.
```
2. Running asynchronously in a subshell. You will have to use the `docker-compose down` command below to stop it.
`bash
sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build &
`
sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build &
Copy link
Contributor

Choose a reason for hiding this comment

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

Your PR has too many unnecessary files that don’t relate to your issue. You can from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit

Please apply these changes to this file.

README.md Outdated
@@ -44,11 +44,11 @@ Core features include:

1. You can install the software for this repository using the steps in our [INSTALLATION.md](INSTALLATION.md) file.
1. Do you want to contribute to our code base? Look at our [CONTRIBUTING.md](CONTRIBUTING.md) file to get started. There you'll also find links to:
1. Our code of conduct documentation in the [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) file.
1. How we handle the processing of new and existing issues in our [ISSUE_GUIDELINES.md](ISSUE_GUIDELINES.md) file.
1. The methodologies we use to manage our pull requests in our [PR_GUIDELINES.md](PR_GUIDELINES.md) file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Your PR has too many unnecessary files that don’t relate to your issue. You can from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit

Please apply these changes to this file.

@@ -237,4 +237,3 @@ echo "0 * * * * talawa-api python3 reset_database.py --mongo-container develop-m
### 8.3 Logging for cron jobs

This will set up logging for the cron jobs and manage log rotation using logrotate.
Copy link
Contributor

Choose a reason for hiding this comment

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

Your PR has too many unnecessary files that don’t relate to your issue. You can from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit

Please apply these changes to this file.

vite.config.mts Outdated
@@ -52,9 +52,9 @@ export default defineConfig({
testTimeout: 30000,

// Use a thread pool for parallel execution to improve performance
pool: 'threads',
Copy link
Contributor

Choose a reason for hiding this comment

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

Your PR has too many unnecessary files that don’t relate to your issue. You can from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit

Please apply these changes to this file.

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

Commits

Files that changed from the base of the PR and between 37de8c9 and 7018143.

Files selected for processing (2)
  • README.md (2 hunks)
  • vite.config.mts (2 hunks)
Additional context used
Markdownlint
README.md

30-30: Expected: 2; Actual: 0
Inconsistent indentation for list items at the same level

(MD005, list-indent)

Additional comments not posted (2)
vite.config.mts (1)

13-13: LGTM!

The removal of the pool property is approved.

README.md (1)

30-30: LGTM!

The adjustments to the indentation of the numbered list items are approved. The changes improve the formatting and readability of the documentation.

Tools
Markdownlint

30-30: Expected: 2; Actual: 0
Inconsistent indentation for list items at the same level

(MD005, list-indent)

README.md Outdated
@@ -27,7 +27,7 @@ Core features include:

- [Talawa Components](#talawa-components)
- [Documentation](#documentation)
- [Videos](#videos)
- [Videos](#videos)
Copy link

Choose a reason for hiding this comment

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

Fix the indentation of the list items.

Markdownlint indicates inconsistent indentation for list items at the same level. Please ensure that all list items at the same level have consistent indentation.

Apply the following change to fix the indentation:

-1. You can install the software for this repository using the steps in our [INSTALLATION.md](INSTALLATION.md) file.
-1. Do you want to contribute to our code base? Look at our [CONTRIBUTING.md](CONTRIBUTING.md) file to get started. There you'll also find links to:
+   1. You can install the software for this repository using the steps in our [INSTALLATION.md](INSTALLATION.md) file.
+   1. Do you want to contribute to our code base? Look at our [CONTRIBUTING.md](CONTRIBUTING.md) file to get started. There you'll also find links to:
        1. Our code of conduct documentation in the [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) file.
        1. How we handle the processing of new and existing issues in our [ISSUE_GUIDELINES.md](ISSUE_GUIDELINES.md) file.
        1. The methodologies we use to manage our pull requests in our [PR_GUIDELINES.md](PR_GUIDELINES.md) file.
-1. The `talawa` documentation can be found at our [docs.talawa.io](https://docs.talawa.io) site.
+   1. The `talawa` documentation can be found at our [docs.talawa.io](https://docs.talawa.io) site.
        1. It is automatically generated from the markdown files stored in our [Talawa-Docs GitHub repository](https://github.com/PalisadoesFoundation/talawa-docs). This makes it easy for you to update our documenation.

Committable suggestion was skipped due to low confidence.

Tools
Markdownlint

30-30: Expected: 2; Actual: 0
Inconsistent indentation for list items at the same level

(MD005, list-indent)

@palisadoes
Copy link
Contributor

Please make sure that coderabbit.ai approves your PR. Make the suggested changes.

@prayanshchh prayanshchh reopened this Sep 10, 2024
@prayanshchh
Copy link
Author

yeah i am on it

@palisadoes
Copy link
Contributor

We have a policy of unassigning contributors who close PRs without getting validation from our reviewer team. This is because:

  1. We start looking for people to review PRs when you submit them.
  2. We often contact them and link to the PR. If the PR is closed the whole effort is wasted.
  3. The historical thread of reviewer comments is broken when the work is spread across multiple PRs. The quality of our code is affected negatively.

Please be considerate of our volunteers' limited time and our desire to improve our code base.

This policy is stated as a pinned post in all our Talawa repositories. Our YouTube videos explain why this practice is not acceptable to our Community.

Unfortunately, if this continues we will have to close the offending PR and unassign you from the issue.

@prayanshchh
Copy link
Author

am really sorry for this, I will remember this next time, won't happen again
again my apologies

@prayanshchh
Copy link
Author

the reviews suggested by coderabbit.ai are outdated as the files have been unstaged

@palisadoes
Copy link
Contributor

@coderabbitai

Copy link

coderabbitai bot commented Sep 11, 2024

@palisadoes: I will review the changes.

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@prayanshchh
Copy link
Author

prayanshchh commented Sep 21, 2024

Hi @palisadoes I have fixed all errors related to the PR, I just need some help to fix this linting error, as I have a failing test, I tried check with prettier but it showed everything was good, I even ran npx prettier --write but all the files were unchanged

This happening because the setup.ts file as a eslint-disable comment, when i removed the comment i recieved several errors

10:1 error './src/constants' import is restricted from being used by a pattern no-restricted-imports
11:1 error './src/setup/MongoDB' import is restricted from being used by a pattern no-restricted-imports
16:1 error './src/setup/askToKeepValues' import is restricted from being used by a pattern no-restricted-imports
17:1 error './src/setup/getNodeEnvironment' import is restricted from being used by a pattern no-restricted-imports
18:1 error './src/setup/isValidEmail' import is restricted from being used by a pattern no-restricted-imports
19:1 error './src/setup/reCaptcha' import is restricted from being used by a pattern no-restricted-imports
20:1 error './src/setup/redisConfiguration' import is restricted from being used by a pattern no-restricted-imports
25:1 error './src/setup/setImageUploadSize' import is restricted from being used by a pattern no-restricted-imports
29:1 error './src/setup/superAdmin' import is restricted from being used by a pattern no-restricted-imports
30:1 error './src/setup/updateEnvVariable' import is restricted from being used by a pattern no-restricted-imports
31:1 error './src/setup/verifySmtpConnection' import is restricted from being used by a pattern no-restricted-imports
32:1 error './src/utilities/loadDefaultOrg' import is restricted from being used by a pattern no-restricted-imports

can you please tell me what am I missing here

@palisadoes
Copy link
Contributor

Please ask the #talawa-api slack channel for assistance

@prayanshchh
Copy link
Author

I actually did ask this on slack, but nobody replied, that's why I tagged you, I will ask this again on slack.

@palisadoes
Copy link
Contributor

@pranshugupta54 @varshith257 Do you have any suggestions?

@palisadoes palisadoes self-requested a review September 28, 2024 22: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