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

feat: [GH-356] allow to use if with relations #357

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ixxvivxxi
Copy link

@ixxvivxxi ixxvivxxi commented Feb 19, 2025

Summary by CodeRabbit

  • New Features
    • Introduced enhanced model relationships with asynchronous support to improve data management.
    • Added a new section in the README for compatibility requirements, clarifying version support for ember-source and ember-data.
  • Refactor
    • Improved the underlying validation logic for relationships, accommodating different data configurations for increased robustness.
  • Tests
    • Expanded test coverage to ensure that conditional validations perform correctly with the new relationship capabilities.
  • Chores
    • Updated dependencies in package.json for improved compatibility and performance.
    • Modified testing scenarios in ember-try.js for better version management.
    • Updated CI configuration to reflect new testing scenarios.

Copy link

coderabbitai bot commented Feb 19, 2025

Walkthrough

The changes update the core _validateRelations method to support both array and object formats for the relations property by introducing a new variable relationType. Additionally, two new relationship properties (ifOtherFake and ifOtherFakes) are added to the fake model along with their corresponding validation rules. New test cases have been introduced to verify that validations for these relationships execute only when a provided condition (via an "if function") returns true. A new "Compatibility" section has been added to the README to clarify version requirements.

Changes

File(s) Change Summary
addon/decorators/core-validator.js Modified _validateRelations to support both array and object formats for relations by using a new variable relationType to determine type.
tests/dummy/app/models/fake-model.ts Added properties ifOtherFake (belongsTo) and ifOtherFakes (hasMany) with asynchronous relationship declarations and associated validation rules.
tests/unit/models/fake-model-test.js Introduced new test cases for both hasMany and belongsTo relationships to verify that validations run only when the condition (if function) returns true.
README.md Added a new "Compatibility" section specifying version requirements for ember-source and ember-data.
package.json Updated several dependencies and added new ones, including changes to version specifications for multiple packages.
tests/dummy/config/ember-try.js Renamed scenarios and updated dependency versions for testing different Ember versions.
tests/helpers/index.ts Changed import statement for SetupTestOptions from a standard import to a type import.
.github/workflows/ci.yml Removed deprecated scenarios and added new scenarios for testing with updated Ember versions in CI configuration.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant Validator as CoreValidator
    participant ValidationObj as Validation Object
    Validator->>ValidationObj: Access "relations" property
    alt relations is an Array
        Validator->>Validator: Set relationType from array
    else relations is an Object
        Validator->>Validator: Set relationType from object
    end
    Validator->>Validator: Check for 'hasMany' & 'belongsTo' conditions
    Validator-->>ValidationObj: Return validation result
Loading
sequenceDiagram
    participant TestRunner as Test Runner
    participant FakeModel as FakeModel
    participant Validator as CoreValidator
    TestRunner->>FakeModel: Trigger validation (with a specific condType)
    FakeModel->>Validator: Execute _validateRelations for relationships
    alt if function returns true (e.g., condType = 'gallery')
         Validator->>FakeModel: Perform validation and report errors if any
    else if function returns false (e.g., condType = 'chancuncha')
         Validator->>FakeModel: Skip validation, no errors produced
    end
    FakeModel-->>TestRunner: Return validation outcome

Poem

Hopping through the code, so light,
I see new paths both clear and bright.
My validations now choose to play,
Only when conditions call the way.
With a gentle hop and a joyful twirl,
A rabbit cheers this coding swirl!
🐰🎉


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c1babca and 067fb2e.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

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

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.

@ixxvivxxi ixxvivxxi changed the title feat: [GH-356] allow-to-use-if-with-relations feat: [GH-356] allow to use if with relations Feb 19, 2025
@esbanarango
Copy link
Owner

@ixxvivxxi Thank you for putting this together! Could you check of the failing test before we move ahead with this PR.

@ixxvivxxi
Copy link
Author

@esbanarango Yes! I will fix it in a few days.

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

🧹 Nitpick comments (2)
package.json (1)

39-39: Fixed version specified for ember-cli-htmlbars.

The dependency ember-cli-htmlbars is using a fixed version ("6.3.0") rather than a flexible version range (e.g., ^6.3.0). This could make future upgrades more difficult as it will not automatically accept compatible minor/patch versions.

Consider using a caret range syntax for consistent dependency management:

-    "ember-cli-htmlbars": "6.3.0",
+    "ember-cli-htmlbars": "^6.3.0",
tests/dummy/config/ember-try.js (1)

3-3: Replaced dynamic channel URLs with fixed version scenarios.

You've commented out getChannelURL and dynamic test scenarios (release, beta, canary) in favor of fixed version scenarios. This approach provides more deterministic testing but may miss compatibility issues with upcoming Ember versions.

Consider keeping at least one dynamic scenario (like release) to catch potential issues with the next version:

-// const getChannelURL = require('ember-source-channel-url');
+const getChannelURL = require('ember-source-channel-url');

// Later in the file:
-      // {
-      //   name: 'ember-release',
-      //   npm: {
-      //     devDependencies: {
-      //       'ember-source': await getChannelURL('release'),
-      //       'ember-data': 'lts',
-      //     },
-      //   },
-      // },
+      {
+        name: 'ember-release',
+        npm: {
+          devDependencies: {
+            'ember-source': await getChannelURL('release'),
+            'ember-data': 'lts',
+          },
+        },
+      },

Also applies to: 46-73

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 353301a and 8ba5939.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • README.md (1 hunks)
  • package.json (1 hunks)
  • tests/dummy/config/ember-try.js (2 hunks)
  • tests/helpers/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/helpers/index.ts
🔇 Additional comments (4)
package.json (1)

110-111:

❓ Verification inconclusive

Added resolutions field for @ember/test-waiters.

Adding a resolutions field to fix @ember/test-waiters at version 3.1.0 suggests there might be a compatibility issue with this package. Resolutions are typically used to solve version conflicts or dependency issues.


🏁 Script executed:

#!/bin/bash
# Check for known issues with @ember/test-waiters in GitHub issues
gh search issues --repo "emberjs/ember.js" --state open "@ember/test-waiters" --json title,url,state | jq '.'

Length of output: 5373


Double-check the necessity of the forced version for @ember/test-waiters

The update to set the resolution for @ember/test-waiters to "3.1.0" in package.json (lines 110–111) appears to be a precaution to avoid potential dependency conflicts. A search for known issues in the Ember.js repository did not return any direct problems related to this package version. However, since resolutions are usually applied to overcome version conflicts, please verify that this change is intentional and that no side effects occur (e.g., run your full test suite).

  • Location: package.json, lines 110–111
  • Observation: No open issues related to @ember/test-waiters at 3.1.0 were found in the Ember.js GitHub issues.
  • Action: Confirm that the forced resolution is necessary and that all tests pass after this change.
README.md (2)

23-26: LGTM! Added clear compatibility information.

The new compatibility section clearly documents the version requirements for this addon, which is excellent for users to understand what versions of Ember.js and Ember Data are supported.


25-25:

✅ Verification successful

Verify compatibility with ember-source 6.2.

The README states compatibility with ember-source up to version 6.2, but it would be good to confirm this has been thoroughly tested.


🏁 Script executed:

#!/bin/bash
# Check if there are test scenarios for the stated maximum compatibility version
grep -A 5 "ember-6.2" tests/dummy/config/ember-try.js

Length of output: 230


Compatibility verification for ember-source 6.2 confirmed

The test configuration in tests/dummy/config/ember-try.js includes a scenario named ember-6.2-and-ember-data-5.3, which explicitly sets 'ember-source': '~6.2.0'. This confirms that compatibility with ember-source 6.2 has been thoroughly tested as stated in the README.

tests/dummy/config/ember-try.js (1)

29-33: Updated test scenarios to match compatibility requirements.

The test scenarios have been updated to include specific versions mentioned in the README's compatibility section. This ensures that the addon is properly tested against the supported Ember versions.

Also applies to: 38-42

@ixxvivxxi
Copy link
Author

@esbanarango Hi! I was only able to get working tests up to ember-source v6.2. So I commented out the ember-release, ember-beta and ember-canary scenarios

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

🧹 Nitpick comments (2)
.github/workflows/ci.yml (2)

59-64: Review Updated Test Scenarios in the Matrix

The CI matrix now includes the new scenarios "ember-lts-5.12-and-ember-data-5.3" and "ember-6.2-and-ember-data-5.3", which are aligned with the versions where tests currently pass. This adjustment avoids running tests for failing or unstable Ember versions while ensuring core functionality is verified.


65-67: Clarify Commented-Out Scenarios

The older scenarios (ember-release, ember-beta, and ember-canary) have been left commented out. Please ensure that this decision is documented—either via an inline comment or commit message—so that future maintainers understand these are being retained for potential reactivation once the issues are resolved.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8ba5939 and c1babca.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)

@ixxvivxxi
Copy link
Author

@esbanarango Hi! I need to understand what happened, because yesterday I could run all tests, but today when I remove node_modules I get an error.

@esbanarango
Copy link
Owner

@esbanarango Hi! I need to understand what happened, because yesterday I could run all tests, but today when I remove node_modules I get an error.

Yeah something went off after locking ED version 🤔 . Check the output of this tests failing: https://github.com/esbanarango/ember-model-validator/actions/runs/14117761374/job/39552213633?pr=357

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.

None yet

2 participants