Skip to content

Feature: add project Powers#2129

Merged
CarlosQ96 merged 4 commits intostagingfrom
feature_add_project_power_in_missing_views
Aug 17, 2025
Merged

Feature: add project Powers#2129
CarlosQ96 merged 4 commits intostagingfrom
feature_add_project_power_in_missing_views

Conversation

@CarlosQ96
Copy link
Collaborator

@CarlosQ96 CarlosQ96 commented Aug 17, 2025

#2073

Summary by CodeRabbit

  • New Features
    • Cause listings now include associated project power details for richer context.
    • Project details can optionally include power information when explicitly requested.
  • Tests
    • Email validation unit tests have been temporarily disabled.
  • Notes
    • Existing filtering, sorting, and pagination behaviors remain unchanged.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 17, 2025

Walkthrough

Added eager loading of project power data: a left join for project.projectPower in findAllCauses, and a conditional left join in ProjectResolver.projectById when projectPower is requested. Disabled isValidEmail tests in src/repositories/userRepository.test.ts and src/resolvers/userResolver.test.ts. No exported signatures changed.

Changes

Cohort / File(s) Summary
Cause repository joins
src/repositories/causeRepository.ts
Added a leftJoinAndSelect to eagerly load project.projectPower (alias projectPower) in findAllCauses. Existing joins, filters, sorting, and pagination unchanged.
Project resolver conditional join
src/resolvers/projectResolver.ts
Added a conditional leftJoinAndSelect to include projectPower in projectById only when projectPower is requested by the selection set. No other control flow or signature changes.
Tests disabled
src/repositories/userRepository.test.ts, src/resolvers/userResolver.test.ts
Commented out / disabled the isValidEmail test imports and test suites; previous test cases left commented. All other tests remain unchanged.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ProjectResolver
  participant DB

  Client->>ProjectResolver: projectById(id, selectionSet)
  ProjectResolver->>ProjectResolver: inspect selectionSet for projectPower
  alt projectPower requested
    ProjectResolver->>DB: SELECT Project LEFT JOIN project.projectPower WHERE id=...
  else
    ProjectResolver->>DB: SELECT Project WHERE id=...
  end
  DB-->>ProjectResolver: Project (with/without projectPower)
  ProjectResolver-->>Client: Result
Loading
sequenceDiagram
  participant Caller as CauseRepository.findAllCauses
  participant DB

  Caller->>DB: SELECT Cause ... LEFT JOIN project.projectPower AS projectPower
  DB-->>Caller: Causes with project power data + pagination/filters applied
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ae2079
  • kkatusic

Poem

I hop through joins and fields unseen,
I fetch the watts where projects lean.
A gentle left join, soft and spry,
Tests nap quietly while queries fly.
Carrots for code — a bright, small sigh. 🥕⚡

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature_add_project_power_in_missing_views

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • 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

Status, Documentation and Community

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c2b927d and 2c231aa.

📒 Files selected for processing (2)
  • src/repositories/causeRepository.ts (1 hunks)
  • src/resolvers/projectResolver.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
src/resolvers/projectResolver.ts (1)

901-903: LGTM: Conditional join for projectPower is correct and scoped

The join is added only when the client requests projectPower, and the alias name aligns with usage elsewhere. No issues spotted.

Comment on lines 317 to 320
.leftJoinAndSelect('cause.projectPower', 'projectPower')
.leftJoinAndSelect('cause.categories', 'categories')
.leftJoinAndSelect('project.projectPower', 'projectPower')
.leftJoinAndSelect('categories.mainCategory', 'mainCategory')
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Fix alias collision: both joins use 'projectPower' alias, which will crash the query

TypeORM requires unique aliases per query. Reusing 'projectPower' for both cause.projectPower and project.projectPower will throw a duplicate alias error or produce incorrect mappings.

Refactor to distinct aliases, e.g., reserve 'projectPower' for the project's relation and use a different alias for the cause's relation.

Apply this diff:

-    .leftJoinAndSelect('cause.projectPower', 'projectPower')
+    .leftJoinAndSelect('cause.projectPower', 'causeProjectPower')
...
-    .leftJoinAndSelect('project.projectPower', 'projectPower')
+    .leftJoinAndSelect('project.projectPower', 'projectPower')

Note: If any downstream filters/orderings reference the 'projectPower' alias in this query, confirm they target the project's power, not the cause's.


🏁 Script executed:

#!/bin/bash
set -e

# Locate the repository file
file=$(fd -e ts --hidden causeRepository.ts | head -n 1)
echo "Inspecting file: $file"

# Show lines around the snippet
echo -e "\nLines 310-330:"
sed -n '310,330p' "$file"

# List all leftJoinAndSelect calls involving projectPower
echo -e "\n.leftJoinAndSelect calls with 'projectPower':"
rg -n ".leftJoinAndSelect.*projectPower" "$file"

# Show any other references to the alias 'projectPower'
echo -e "\nAll occurrences of 'projectPower' in the file:"
rg -n "projectPower" "$file"

Length of output: 2072


Fix duplicate ‘projectPower’ alias to prevent query failure

The query currently joins two relations with the same alias, which will cause TypeORM to throw a “duplicate alias” error or map data incorrectly. Rename the alias on the cause’s relation to be unique.

• File: src/repositories/causeRepository.ts
– Line 317: change alias for cause.projectPower
– Line 319: preserve alias for project.projectPower

Apply:

-    .leftJoinAndSelect('cause.projectPower', 'projectPower')
+    .leftJoinAndSelect('cause.projectPower', 'causeProjectPower')

After renaming, verify any filters or orderings that reference the old alias to ensure they still target the intended relation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.leftJoinAndSelect('cause.projectPower', 'projectPower')
.leftJoinAndSelect('cause.categories', 'categories')
.leftJoinAndSelect('project.projectPower', 'projectPower')
.leftJoinAndSelect('categories.mainCategory', 'mainCategory')
.leftJoinAndSelect('cause.projectPower', 'causeProjectPower')
.leftJoinAndSelect('cause.categories', 'categories')
.leftJoinAndSelect('project.projectPower', 'projectPower')
.leftJoinAndSelect('categories.mainCategory', 'mainCategory')
🤖 Prompt for AI Agents
In src/repositories/causeRepository.ts around lines 317 to 320, the query uses
the same alias 'projectPower' for both cause.projectPower and
project.projectPower which causes a duplicate-alias error; change the alias for
the cause relation to a unique name (e.g., 'causeProjectPower') while leaving
project.projectPower's alias as 'projectPower', then update any
where/orderBy/select references that used the old alias to point to the new
alias so filters and ordering still target the intended relation.

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

🧹 Nitpick comments (2)
src/repositories/userRepository.test.ts (2)

55-55: Use describe.skip instead of commenting out a test suite

Commenting out hides the test; skipping keeps it discoverable and reported as skipped.

Apply this diff:

-// describe('isValidEmail test cases', isValidEmailTestCases);
+describe.skip('isValidEmail test cases', isValidEmailTestCases);

597-611: Reinstate the test body; remove the no-op assertion; keep it skipped via describe.skip

Leaving the whole suite commented-out reduces visibility and erodes coverage. Restoring the suite (while skipped) keeps intent clear and allows easy re-enablement. Also remove the redundant assert.isTrue(true) in the invalid case.

Apply this diff:

-// function isValidEmailTestCases() {
-//   it('should return true for valid email', async () => {
-//     const email = `${new Date().getTime()}@giveth.io`;
-//     const isValid = await isValidEmail(email);
-//     assert.isOk(isValid);
-//   });
-//
-//   it('should return false for invalid email', async () => {
-//     assert.isTrue(true);
-//     const email = `${new Date().getTime()}@giveeeeth.io`;
-//     const isValid = await isValidEmail(email);
-//     assert.isNotOk(isValid);
-//   });
-// }
+function isValidEmailTestCases() {
+  it('should return true for valid email', async () => {
+    const email = `${new Date().getTime()}@giveth.io`;
+    const isValid = await isValidEmail(email);
+    assert.isOk(isValid);
+  });
+
+  it('should return false for invalid email', async () => {
+    const email = `${new Date().getTime()}@giveeeeth.io`;
+    const isValid = await isValidEmail(email);
+    assert.isNotOk(isValid);
+  });
+}

If the tests are flaky due to network/DNS/external API checks, I can help replace them with deterministic unit tests using mocks (e.g., nock/sinon) or move them to a separate integration suite. Want me to draft that?

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2bed101 and 1801c68.

📒 Files selected for processing (1)
  • src/repositories/userRepository.test.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: Analyze (javascript-typescript)

Comment on lines +20 to 21
// isValidEmail,
} from './userRepository';
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Avoid commenting out imports; prefer keeping the suite and marking it skipped

This change is unrelated to the PR objective (project power eager loading). If the isValidEmail tests are flaky/blocked, keep them in place and mark them skipped so they remain visible in test reports and aren’t silently dropped.
[suggest_optional_refactor]

Apply this diff to restore the import:

   findUsersWhoSupportProject,
-  // isValidEmail,
+  isValidEmail,
 } from './userRepository';

Optionally verify that isValidEmail is still exported and locate its call sites:


🏁 Script executed:

#!/bin/bash
# Verify export(s) of isValidEmail and surface call sites for context.
fd -a userRepository.ts | xargs rg -nP -C2 '\bexport\s+(?:async\s+)?function\s+isValidEmail\b|export\s*\{[^}]*\bisValidEmail\b'
rg -nP -C2 '\bisValidEmail\s*\(' --type ts --type tsx

Length of output: 213


I’ll re-check the export, definition, and call-sites of isValidEmail more broadly:

This will confirm whether isValidEmail even exists or is referenced.


🏁 Script executed:

#!/bin/bash
# 1. Locate the userRepository.ts file
file=$(fd --extension ts userRepository.ts | head -n1)
echo "Checking in: $file"

# 2. Inspect for any definition or export of isValidEmail in that file
rg -nP 'function\s+isValidEmail\b|isValidEmail\s*[:=]' -C2 "$file"
rg -nP 'export\s*{[^}]*\bisValidEmail\b|export\s+(?:async\s+)?function\s+isValidEmail\b' -C2 "$file"

# 3. Search across all TS/TSX for usage
rg -nP '\bisValidEmail\s*\(' -C2 -g '*.ts*'

Length of output: 4588


Restore and Skip isValidEmail Tests
The isValidEmail function remains exported in src/repositories/userRepository.ts and is used elsewhere. Rather than commenting out its import and tests (which silently drops coverage), restore them and mark the suite as skipped so they stay visible in reports.

• In src/repositories/userRepository.test.ts (around lines 20–21):

   findUsersWhoSupportProject,
-  // isValidEmail,
+  isValidEmail,
 } from './userRepository';

• Uncomment the existing isValidEmail test cases (around lines 598–609) and wrap them in a skipped suite:

+describe.skip('isValidEmail (flaky)', () => {
   it('should return true for valid email', async () => {
     const email = `${Date.now()}@giveth.io`;
     const isValid = await isValidEmail(email);
     assert.isOk(isValid);
   });

   it('should return false for invalid email', async () => {
     const email = `${Date.now()}@giveeeeth.io`;
     const isValid = await isValidEmail(email);
     assert.isNotOk(isValid);
   });
+});

This preserves the tests in CI output while acknowledging their instability.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/repositories/userRepository.test.ts around lines 20–21 and 598–609, the
isValidEmail import was commented out and its test cases removed; restore the
isValidEmail import at the top (uncomment it) and re-enable the existing test
cases at lines ~598–609 but wrap them in a skipped suite (e.g., describe.skip or
xdescribe) so the tests remain in the file and CI/test reports while not
running; ensure imports and any references inside those tests are intact so they
compile.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/resolvers/userResolver.test.ts (3)

38-38: Prefer describe.skip (or env-gated describe) to commented-out tests.

This keeps the suite discoverable while preventing execution by default.

Apply this diff:

-// describe('isValidEmail() test cases', isValidEmailTestCases);
+(RUN_EMAIL_VALIDATION_TESTS ? describe : describe.skip)(
+  'isValidEmail() test cases',
+  isValidEmailTestCases,
+);

1181-1196: Revive the test cases behind a gate; avoid nested describe duplication.

Uncomment the suite and remove the inner describe. This matches the pattern used elsewhere in this file and keeps the suite grouped by the outer describe you already have.

Apply this diff:

-// function isValidEmailTestCases() {
-//   describe('isValidEmail() test cases', () => {
-//     it('should return true for valid email', async () => {
-//       const email = `${new Date().getTime()}@giveth.io`;
-//       const isValid = await isValidEmail(email);
-//       assert.isTrue(isValid);
-//     });
-//
-//     it('should return false for invalid email', async () => {
-//       const email = `${new Date().getTime()}@giveeeeth.io`;
-//       const isValid = await isValidEmail(email);
-//       assert.isNotOk(isValid);
-//     });
-//   });
-// }
+function isValidEmailTestCases() {
+  it('should return true for valid email', async () => {
+    const email = `${new Date().getTime()}@giveth.io`;
+    const isValid = await isValidEmail(email);
+    assert.isTrue(isValid);
+  });
+
+  it('should return false for invalid email', async () => {
+    const email = `${new Date().getTime()}@giveeeeth.io`;
+    const isValid = await isValidEmail(email);
+    assert.isNotOk(isValid);
+  });
+}

Note: If these tests call external services, consider mocking HTTP (e.g., via nock) to prevent network flakiness and make them safe to run locally and in CI. You can keep them disabled by default with RUN_EMAIL_VALIDATION_TESTS.


32-32: Re-enable isValidEmail import and gate email-validation tests with an ENV flag

We’ve confirmed isValidEmail is still exported (src/repositories/userRepository.ts:211) and used in production code. Commenting out the import can lead to bit-rot and hidden failures. Instead, re-enable the import and wrap or skip the test suite based on an explicit environment variable—so the tests remain visible in CI but only run when opted in.

• In src/resolvers/userResolver.test.ts, restore the import and add a flag:

-// import { isValidEmail } from '../repositories/userRepository';
+import { isValidEmail } from '../repositories/userRepository';
+const RUN_EMAIL_VALIDATION_TESTS = process.env.RUN_EMAIL_VALIDATION_TESTS === 'true';

• Gate the suite with describe.skip (or a runtime check):

- describe('userResolver email validation', () => {
+;(RUN_EMAIL_VALIDATION_TESTS ? describe : describe.skip)('userResolver email validation', () => {
    // …email‐validation tests…
  });

Setting RUN_EMAIL_VALIDATION_TESTS=true in your CI or local env will enable these tests; otherwise they’ll be skipped but still reported.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1801c68 and 67fe610.

📒 Files selected for processing (1)
  • src/resolvers/userResolver.test.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: Analyze (javascript-typescript)

@CarlosQ96 CarlosQ96 merged commit df1cac8 into staging Aug 17, 2025
9 checks passed
@CarlosQ96 CarlosQ96 deleted the feature_add_project_power_in_missing_views branch August 17, 2025 13:21
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.

1 participant