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

Add: add product tests (product addon, rma) #2396

Merged
merged 7 commits into from
Oct 8, 2024

Conversation

shashwatahalder01
Copy link
Contributor

@shashwatahalder01 shashwatahalder01 commented Oct 7, 2024

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

  • Full PR Link

Closes

  • Closes #

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • New Features

    • Vendors can now manage product addons, including adding, importing, exporting, and removing addons.
    • Enhanced RMA settings for vendors, allowing configuration of warranty options.
    • Vendors can add and update EU compliance data for products.
    • Admin capabilities related to the Dokan plugin have been removed.
    • Admin can now cancel vendor subscriptions immediately or at the end of the current period.
  • Bug Fixes

    • Addressed various permission issues across pages to ensure correct feature access.
  • Tests

    • Added comprehensive tests for product addons, EU compliance options, and RMA settings to ensure functionality.
    • Expanded end-to-end tests for product details functionality, including compliance and warranty scenarios.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Walkthrough

The pull request introduces significant updates to the feature-map.yml file and related test files, enhancing vendor capabilities while restricting certain admin functionalities. Key modifications include the removal of admin permissions for the Dokan plugin, the addition of new vendor features for managing product addons and EU compliance data, and the introduction of methods in the ProductsPage class for handling these functionalities. The test suite is expanded to cover these new features, ensuring comprehensive validation of the updated functionalities.

Changes

File Path Change Summary
tests/pw/feature-map/feature-map.yml Removed admin permissions related to the Dokan plugin; added vendor features for product addons and EU compliance.
tests/pw/pages/productsPage.ts Added methods for managing product addons and RMA options, enhancing the ProductsPage class functionality.
tests/pw/pages/requestForQuotationsPage.ts Modified logic in updateQuoteRuleFields method to check rule.keepBothCartQuoteButton instead of rule.hideAddToCartButton.
tests/pw/tests/e2e/productAddons.spec.ts Updated to include tests for adding, importing, exporting, and removing product addons for vendors.
tests/pw/tests/e2e/productsDetails.spec.ts Introduced tests for EU compliance options, product addons, and RMA options, enhancing test coverage for vendors.

Possibly related PRs

Suggested labels

QA approved

Suggested reviewers

  • mrabbani

Poem

🐰 In the garden where vendors play,
New features bloom, brightening the day.
Addons and compliance, all in their hands,
While admins watch from distant lands.
With RMA settings and exports galore,
The marketplace thrives, who could ask for more? 🌼


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.

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.

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

🧹 Outside diff range and nitpick comments (4)
tests/pw/tests/e2e/productAddons.spec.ts (1)

100-103: LGTM with a minor suggestion: Well-structured test for removing a product addon.

This test case effectively tests the functionality of removing a product-specific addon. The use of apiUtils for setup is consistent with other parts of the codebase.

However, there's a minor suggestion for improvement:

On line 102, consider adding a type guard instead of using a type assertion:

if (typeof addonName[0] === 'string') {
    await vendor1.removeAddon(productName, addonName[0]);
} else {
    throw new Error('Unexpected addon name type');
}

This approach provides better type safety and runtime checks.

tests/pw/feature-map/feature-map.yml (1)

190-201: Overall enhancement of vendor capabilities

The changes introduced in this feature map significantly enhance vendor capabilities in three key areas:

  1. EU compliance: Allowing vendors to manage EU compliance data for their products.
  2. Product addons: Enabling vendors to create, import, export, and manage product addons.
  3. RMA settings: Providing vendors with options to set various warranty and return policies.

These additions will likely improve the flexibility and control vendors have over their products and stores. However, it's crucial to ensure that these features are properly implemented, tested, and documented to maintain the overall quality and reliability of the Dokan plugin.

Consider the following recommendations:

  1. Ensure comprehensive unit and integration tests are in place for these new features.
  2. Update user documentation to explain these new capabilities to vendors.
  3. Consider adding admin-level controls to enable/disable these features globally if not already present.
  4. Implement proper validation and error handling for EU compliance data and RMA settings to prevent misuse or incorrect data entry.

Also applies to: 439-442

tests/pw/tests/e2e/productsDetails.spec.ts (1)

473-473: Implement tests for updating RMA options

The TODO comment indicates that tests for updating RMA options are pending.

Would you like assistance in creating these tests to improve coverage of RMA functionalities?

tests/pw/pages/productsPage.ts (1)

1465-1465: Clarify the method comment for 'exportAddon'

To maintain consistency and clarity, consider updating the comment to // export addon above the exportAddon method if it's not already correct.

Ensure the comment accurately describes the method:

-    // export addon
+    // export addon
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d41c6ee and d0ee88c.

📒 Files selected for processing (4)
  • tests/pw/feature-map/feature-map.yml (3 hunks)
  • tests/pw/pages/productsPage.ts (1 hunks)
  • tests/pw/tests/e2e/productAddons.spec.ts (4 hunks)
  • tests/pw/tests/e2e/productsDetails.spec.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (12)
tests/pw/tests/e2e/productAddons.spec.ts (6)

3-3: LGTM: New imports and variable declarations are appropriate.

The additions of the ProductsPage import and the new variables (vendor1 and productName) are well-placed and necessary for the new product addon tests. The naming convention is consistent with the existing code.

Also applies to: 15-15, 20-20


35-35: LGTM: Proper setup for new product addon tests.

The initialization of vendor1 and the creation of a product in the beforeAll hook are appropriate additions. These changes set up the necessary context for the new product-specific addon tests.

Also applies to: 39-39


86-88: LGTM: Well-structured test for adding a product addon.

This test case is well-implemented, following the existing test structure. It appropriately tests the new functionality of adding a product-specific addon using the vendor1 instance.


90-93: LGTM: Comprehensive test for importing a product addon.

This test case is well-implemented, testing the functionality of importing a product-specific addon. The use of serialization for the addon data is consistent with other parts of the codebase.


95-98: LGTM: Well-structured test for exporting a product addon.

This test case effectively tests the functionality of exporting a product-specific addon. The use of apiUtils for setup and serialization for the export process is consistent with other parts of the codebase.


Line range hint 1-103: LGTM: Comprehensive and well-structured test suite for product addons.

The additions to this test suite provide excellent coverage for product-specific addons, complementing the existing tests for global addons. The new test cases cover all essential operations (add, import, export, and remove) for product-specific addons, maintaining consistency in structure and naming conventions with the existing code.

This comprehensive approach ensures thorough testing of both global and product-specific addon functionalities, which is crucial for maintaining the quality and reliability of the product addon feature.

tests/pw/feature-map/feature-map.yml (4)

197-201: New RMA options for vendors

These features allow vendors to add various RMA (Return Merchandise Authorization) options for their products, including no warranty, limited warranty, lifetime warranty, and warranty as an addon.

Let's verify the implementation of these RMA features:

#!/bin/bash
# Description: Check for the implementation of RMA features for vendors

# Test: Search for RMA related functions in the codebase
rg --type php "function.*rma" -g "!tests/*"

193-196: New product addon features for vendors

These features enable vendors to add, import, export, and remove product addons. This enhancement provides vendors with more flexibility in customizing their products.

Let's verify the implementation of these product addon features:

#!/bin/bash
# Description: Check for the implementation of product addon features for vendors

# Test: Search for product addon related functions in the codebase
rg --type php "function.*product.*addon" -g "!tests/*"

439-442: New RMA settings for vendors

These features allow vendors to set various RMA settings, including no warranty, limited warranty, lifetime warranty, and warranty as an addon. This is consistent with the product-level RMA options added earlier.

Let's verify the implementation of these RMA settings:

#!/bin/bash
# Description: Check for the implementation of RMA settings for vendors

# Test: Search for RMA settings related functions in the codebase
rg --type php "function.*rma.*settings" -g "!tests/*"

190-192: New EU compliance features for vendors

These new features allow vendors to add, update, and remove EU compliance data for products. This is a valuable addition that helps ensure products meet EU regulations.

To ensure these features are properly implemented, let's verify the corresponding code:

tests/pw/tests/e2e/productsDetails.spec.ts (2)

441-443: ⚠️ Potential issue

Ensure correct serialization and error handling when importing product addons

In the import product addon test, you serialize the addon data using serialize([addon]).

Ensure that the serialize function correctly processes the addon data and that any serialization errors are properly handled. Consider adding validation for the addon object before serialization.


446-448: ⚠️ Potential issue

Verify retrieval of _product_addons metadata

In the export product addon test, you're accessing the _product_addons metadata from responseBody.meta_data.

Ensure that responseBody.meta_data contains the _product_addons key. Add error handling for cases where the metadata might be missing or malformed to avoid runtime exceptions.

tests/pw/tests/e2e/productsDetails.spec.ts Show resolved Hide resolved
tests/pw/tests/e2e/productsDetails.spec.ts Show resolved Hide resolved
tests/pw/tests/e2e/productsDetails.spec.ts Show resolved Hide resolved
tests/pw/tests/e2e/productsDetails.spec.ts Outdated Show resolved Hide resolved
tests/pw/tests/e2e/productsDetails.spec.ts Show resolved Hide resolved
tests/pw/pages/productsPage.ts Show resolved Hide resolved
tests/pw/pages/productsPage.ts Outdated Show resolved Hide resolved
tests/pw/pages/productsPage.ts Outdated Show resolved Hide resolved
tests/pw/pages/productsPage.ts Show resolved Hide resolved
tests/pw/pages/productsPage.ts Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (1)
tests/pw/pages/requestForQuotationsPage.ts (1)

Line range hint 1-638: Consider refactoring for improved maintainability

While not directly related to the current changes, I noticed that the RequestForQuotationsPage class is quite large and handles multiple responsibilities (admin, vendor, and customer actions). Consider refactoring this class in the future to improve maintainability:

  1. Split the class into smaller, more focused classes (e.g., AdminQuotePage, VendorQuotePage, CustomerQuotePage).
  2. Extract some of the longer methods into smaller, more manageable functions.
  3. Use composition to share common functionality between these classes if needed.

This refactoring would improve code organization, make it easier to test, and potentially reduce the likelihood of bugs when modifying quote-related functionality.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d0ee88c and 8dae527.

📒 Files selected for processing (3)
  • tests/pw/pages/productsPage.ts (1 hunks)
  • tests/pw/pages/requestForQuotationsPage.ts (1 hunks)
  • tests/pw/tests/e2e/productsDetails.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/pw/tests/e2e/productsDetails.spec.ts
🧰 Additional context used
🔇 Additional comments (7)
tests/pw/pages/productsPage.ts (7)

1419-1422: Simplify code by removing unnecessary toPass wrapper

As previously noted, the use of await this.toPass(async () => { ... }); is unnecessary here since the actions inside can be awaited directly. Removing this.toPass will simplify the code and enhance readability.


1457-1463: importAddon method implementation is correct

The importAddon method correctly imports an addon by filling the import input, saving the product, and verifying the presence of the addon. The implementation is concise and functions as intended.


1465-1471: exportAddon method implementation is correct

The exportAddon method properly exports an addon and verifies that the export input contains the correct addon identifier. The code is clear and operates correctly.


1473-1480: removeAddon method implementation is correct

The removeAddon method effectively removes an addon from a product, confirms its deletion, and ensures it is no longer visible after saving. The method is well-implemented.


1483-1527: Consider refactoring to reduce code duplication in addProductRmaOptions

As previously suggested, the addProductRmaOptions method contains repeated code blocks for handling different rma.type values and their corresponding verifications. Refactoring these blocks into helper functions can improve maintainability by reducing duplication.


1523-1525: Re-evaluate refundReasonIsVisible after saving

As previously noted, after saving the product with await this.saveProduct();, the visibility of productsVendor.rma.refundReasonsFirst may change. Re-checking refundReasonIsVisible after saving ensures accurate verification of the refund reasons.


1530-1535: removeProductRmaOptions method implementation is correct

The removeProductRmaOptions method correctly disables RMA settings for a product and confirms that the settings are no longer enabled after saving. The implementation is appropriate and works as expected.

tests/pw/pages/requestForQuotationsPage.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA approved This PR is approved by the QA team Test Automation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant