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 vendor payment tests #53

Merged
merged 5 commits into from
Oct 3, 2024
Merged

Add: add vendor payment tests #53

merged 5 commits into from
Oct 3, 2024

Conversation

shashwatahalder01
Copy link
Owner

@shashwatahalder01 shashwatahalder01 commented Oct 3, 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

Release Notes

  • New Features

    • Enhanced payment settings navigation for WooCommerce, including new methods for managing payment options.
    • Comprehensive updates to vendor payment methods, allowing users to add, update, and remove various payment options including PayPal, Skrill, and custom methods.
    • New test cases for managing payment methods, including adding, updating, and removing options.
  • Bug Fixes

    • Improved validation logic for payment settings.
  • Documentation

    • Added detailed configurations for payment methods in test data, enhancing clarity and usability.
  • Chores

    • Updated test data structure to support new payment methods and vendor/customer information.

@shashwatahalder01 shashwatahalder01 added enhancement New feature or request approved labels Oct 3, 2024
@shashwatahalder01 shashwatahalder01 self-assigned this Oct 3, 2024
Copy link

coderabbitai bot commented Oct 3, 2024

Walkthrough

The pull request introduces significant modifications to the PaymentsPage class and related test files, focusing on enhancing payment settings navigation and vendor payment method management. Key changes include renaming methods for clarity, consolidating navigation logic, and adding new methods for managing payment methods. The test suite has been updated to reflect these changes, with new tests for managing various payment methods and enhanced database interactions. Additionally, the dbData object has been expanded to include detailed configurations for payment methods, improving the overall structure and functionality of the testing framework.

Changes

File Path Change Summary
tests/pw/pages/paymentsPage.ts - Renamed method goToPaymentSettings to goToWcPaymentSettings.
- Added method goToPaymentSettings(methodName: string).
- Added methods addBasicPayment(paymentMethod: vendor['payment']) and removeBasicPayment(paymentMethod: vendor['payment']).
- Updated setBankTransfer method to addBankTransfer.
- Removed setBasicPaymentSettings and setBasicPayment methods.
tests/pw/tests/e2e/payments.spec.ts - Added new imports for dbUtils, dbData, and helpers.
- Introduced VENDOR_ID for database operations.
- Updated tests for adding, updating, and removing payment methods (PayPal, Skrill, bank, custom).
- Updated test.afterAll to include database updates for payment settings.
tests/pw/utils/dbData.ts - Added paymentSettings object under dokan with configurations for paypal, bank, dokan_custom, and skrill.
tests/pw/utils/helpers.ts - Added methods emptyObjectValues and isPlainObject.
- Updated deepMergeObjects to use isPlainObject.
tests/pw/utils/testData.ts - Expanded paymentDetails, vendor, customer, product, store, and order objects with new properties and methods.
tests/pw/feature-map/feature-map.yml - Updated vendor permissions for payment methods and product management, enhancing vendor capabilities.

Possibly related PRs

  • Add: add product category & tags test #50: The changes in the main PR regarding the PaymentsPage class and its methods for managing payment settings are related to the modifications in payments.spec.ts, which also focuses on vendor payment methods and includes tests for disconnecting payment methods, aligning with the changes made in the main PR.
  • Product edit #51: The updates in the ProductsPage class for managing product categories and tags are relevant to the main PR's changes in the PaymentsPage class, as both involve enhancing functionality related to vendor capabilities within the application.

🐰 In the meadow where bunnies play,
New payment paths have come our way.
With settings bright and methods clear,
We hop along without a fear!
To manage funds, oh what a thrill,
Our code now dances, smooth and still! 🌼


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

@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: 4

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

28-28: Remove commented-out code for code cleanliness

The commented-out line // await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: [] }); may not be needed. Removing unused code helps keep the codebase clean and maintainable.

tests/pw/pages/paymentsPage.ts (2)

220-220: Review the Commented-Out Assertion

The assertion await this.notToHaveCount(paymentSettingsVendor.paymentMethods.noOfPaymentMethods, 0); is commented out. If this check is necessary to validate that payment methods are rendering properly, consider uncommenting it. If it's no longer needed, consider removing it to keep the codebase clean.


266-266: Consider Removing Commented-Out Code

The line // await this.clickIfVisible(paymentSettingsVendor.disconnectAccount); is commented out. If this action is no longer required, consider removing the line. If it's needed for future functionality, ensure it's tracked appropriately.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9a21a84 and 8d546e4.

📒 Files selected for processing (5)
  • tests/pw/pages/paymentsPage.ts (7 hunks)
  • tests/pw/tests/e2e/payments.spec.ts (3 hunks)
  • tests/pw/utils/dbData.ts (1 hunks)
  • tests/pw/utils/helpers.ts (2 hunks)
  • tests/pw/utils/testData.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/pw/utils/testData.ts
🧰 Additional context used
🪛 Biome
tests/pw/utils/helpers.ts

[error] 470-470: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (19)
tests/pw/utils/helpers.ts (2)

472-473: LGTM: Well-implemented utility method

The isPlainObject method is correctly implemented and provides a useful utility for checking if a value is a plain object.

The method effectively:

  1. Checks if the value is not null.
  2. Verifies that the value is of type 'object'.
  3. Ensures the value is not an array.

This implementation will be helpful in distinguishing plain objects from other types, including arrays and null values.


497-497: LGTM: Improved consistency with new utility method

The modification to use the isPlainObject method in deepMergeObjects is a good improvement.

This change:

  1. Enhances code consistency by utilizing the newly defined utility method.
  2. Improves readability by using a descriptive method name instead of a direct type check.
  3. Makes the code more maintainable, as any future changes to object type checking can be centralized in the isPlainObject method.

Good job on refactoring to use the new utility method!

tests/pw/utils/dbData.ts (1)

1423-1446: New payment settings added for vendor testing.

The new paymentSettings object has been added to the testData.dokan object, which appears to be used for testing purposes. This addition provides test data for various payment methods including PayPal, bank transfer, custom payment, and Skrill.

However, there are a few points to consider:

  1. Sensitive Data: The test data includes what appears to be mock sensitive information such as account numbers and IBANs. Ensure that this test data is not accidentally used in any public-facing or production environments.

  2. Consistency: The declaration field in the bank settings is set to 'on'. Consider using a boolean value (true/false) for consistency with other boolean fields in the configuration.

  3. Custom Payment: The purpose of the dokan_custom payment method is not clear. Consider adding a comment to explain its usage or provide more descriptive field names.

To ensure this test data doesn't contain any real sensitive information, run the following script:

If this script returns any matches, please double-check that they are indeed mock data and not real information.

✅ Verification successful

Sensitive data in test settings verified as mock data.

The shell script confirmed that the email addresses and account numbers within the paymentSettings object are mock data. No real sensitive information was found, ensuring that the test data is safe for use in non-production environments.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential real sensitive data in payment settings

# Test: Look for common patterns of real account numbers or emails
rg -i '\b(?:\d{10,}|[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\b' tests/pw/utils/dbData.ts

Length of output: 269

tests/pw/tests/e2e/payments.spec.ts (12)

6-9: Approved: New imports are appropriate

The added imports from @utils/dbUtils, @utils/dbData, and @utils/helpers are necessary for the database interactions and helper functions used in the tests.


83-83: Duplicate Issue: Avoid direct database manipulation in tests

As previously noted, using dbUtils.updateUserMeta directly can bypass application logic. Consider using appropriate apiUtils methods to ensure tests simulate real-world scenarios.


88-88: Duplicate Issue: Avoid direct database manipulation in tests

Refer to the earlier comment about using apiUtils instead of direct database updates for modifying user settings.


93-93: Duplicate Issue: Avoid direct database manipulation in tests

Same concern as previously mentioned regarding direct database updates.


98-98: Duplicate Issue: Avoid direct database manipulation in tests

Please consider using API methods instead of direct database manipulation as discussed earlier.


103-103: Duplicate Issue: Avoid direct database manipulation in tests

This is the same issue previously noted with using dbUtils.updateUserMeta directly.


113-113: Duplicate Issue: Avoid direct database manipulation in tests

As before, consider using apiUtils methods for updating user settings.


118-118: Duplicate Issue: Avoid direct database manipulation in tests

Refer to the earlier comments about using API methods over direct database updates.


123-123: Duplicate Issue: Avoid direct database manipulation in tests

Same concern applies here regarding direct manipulation of the database.


128-128: Duplicate Issue: Avoid direct database manipulation in tests

Please use apiUtils for modifying user settings to ensure consistency with previous comments.


133-133: Duplicate Issue: Avoid direct database manipulation in tests

Consider the earlier advice about using API methods for updating user settings.


138-138: Duplicate Issue: Avoid direct database manipulation in tests

As previously mentioned, avoid using direct database updates in tests.

tests/pw/pages/paymentsPage.ts (4)

19-21: Correct Implementation of the goToWcPaymentSettings() Method

The goToWcPaymentSettings() method correctly navigates to the WooCommerce payment settings page using await this.goIfNotThere(data.subUrls.backend.wc.paymentSettings);.


25-25: Consistent Update to Use goToWcPaymentSettings()

The calls to goToWcPaymentSettings() in the payment setup methods ensure that each method navigates to the correct WooCommerce payment settings page before proceeding.

Also applies to: 41-41, 66-66, 94-94, 141-141, 165-165


248-252: Correct Implementation of the setBasicPayment() Method

The setBasicPayment() method accurately navigates to the specified payment settings page and updates the payment email. The method ensures that the changes are saved and verifies success.


255-260: Proper Addition of disconnectBasicPayment() Method

The disconnectBasicPayment() method effectively handles the disconnection of a basic payment method by navigating to the appropriate settings page and performing the disconnect action.

tests/pw/utils/helpers.ts Show resolved Hide resolved
import { dbData } from '@utils/dbData';
import { helpers } from '@utils/helpers';

const { VENDOR_ID } = process.env;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for undefined VENDOR_ID

VENDOR_ID is retrieved from process.env, but there is no check to ensure it is defined. To prevent potential runtime errors during test execution, consider adding validation or a default value if VENDOR_ID is not set.

tests/pw/tests/e2e/payments.spec.ts Show resolved Hide resolved
tests/pw/pages/paymentsPage.ts Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (5)
tests/pw/tests/e2e/payments.spec.ts (5)

92-94: Approve new PayPal removal test with suggestion

The new test for removing the PayPal payment method is a good addition, improving coverage of the PayPal functionality. However, consider using API calls instead of direct database manipulation for setting up the initial state:

await apiUtils.setStoreSettings({ payment: { paypal: { email: 'paypal@g.c' } } }, payloads.vendorAuth);

This approach would make the test more representative of real-world scenarios.


98-104: Approve bank payment method tests with suggestions

  1. The tests for adding and updating bank payment methods are good additions, improving coverage of the functionality.

  2. However, consider using API calls instead of direct database manipulation:

    await apiUtils.setStoreSettings({ payment: { bank: emptyBankSettings } }, payloads.vendorAuth);

    This approach would make the tests more representative of real-world scenarios and help catch potential issues in the application's data handling.

  3. The use of helpers.emptyObjectValues() is a good practice for ensuring clean test data.


107-109: Approve bank payment method removal test with suggestion

The new test for removing the bank payment method is a good addition, improving coverage of the functionality. However, consider using API calls instead of direct database manipulation for setting up the initial state:

await apiUtils.setStoreSettings(dbData.testData.dokan.paymentSettings.bank, payloads.vendorAuth);

This approach would make the test more representative of real-world scenarios.


112-125: Approve Skrill payment method tests with suggestions

The new tests for adding, updating, and removing the Skrill payment method are excellent additions, improving coverage of the functionality. However, consider using API calls instead of direct database manipulation:

await apiUtils.setStoreSettings({ payment: { skrill: { email: '' } } }, payloads.vendorAuth);
await apiUtils.setStoreSettings({ payment: { skrill: { email: 'skrill@g.c' } } }, payloads.vendorAuth);

This approach would make the tests more representative of real-world scenarios and help catch potential issues in the application's data handling.

Also, ensure that the Skrill payment method is properly tagged as a pro feature, as indicated by the @pro tag in the test descriptions.


127-139: Approve custom payment method tests with suggestions

The new tests for adding, updating, and removing the custom payment method are excellent additions, improving coverage of the functionality. However, consider using API calls instead of direct database manipulation:

await apiUtils.setStoreSettings({ payment: { dokan_custom: { value: '' } } }, payloads.vendorAuth);
await apiUtils.setStoreSettings({ payment: { dokan_custom: { value: '0123456789' } } }, payloads.vendorAuth);

This approach would make the tests more representative of real-world scenarios and help catch potential issues in the application's data handling.

Also, ensure that the custom payment method is properly tagged as a pro feature, as indicated by the @pro tag in the test descriptions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8d546e4 and bfb0c77.

📒 Files selected for processing (3)
  • tests/pw/feature-map/feature-map.yml (1 hunks)
  • tests/pw/pages/paymentsPage.ts (7 hunks)
  • tests/pw/tests/e2e/payments.spec.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/pw/pages/paymentsPage.ts
🔇 Additional comments (5)
tests/pw/tests/e2e/payments.spec.ts (3)

Line range hint 1-139: Overall assessment of payment method tests

The changes in this file significantly improve the test coverage for various payment methods, including PayPal, bank transfer, Skrill, and custom payment methods. The addition of tests for adding, updating, and removing each payment method is commendable and aligns well with the PR objectives.

However, there are some areas for improvement:

  1. Consider using API calls instead of direct database manipulation throughout the tests. This would make the tests more representative of real-world scenarios and help catch potential issues in the application's data handling.

  2. Ensure proper error handling for the VENDOR_ID environment variable to prevent potential runtime errors.

  3. Review the commented-out code in the beforeAll hook and either implement or remove it.

  4. Verify that all pro features are correctly tagged with @pro in the test descriptions.

These changes will enhance the reliability and maintainability of the test suite while ensuring it accurately reflects real-world usage of the application.


6-10: ⚠️ Potential issue

Add error handling for undefined VENDOR_ID

The VENDOR_ID is retrieved from process.env without any validation. To prevent potential runtime errors during test execution, consider adding validation or a default value if VENDOR_ID is not set.

Example:

const VENDOR_ID = process.env.VENDOR_ID || throw new Error('VENDOR_ID is not set');

28-34: ⚠️ Potential issue

Review database operations in setup and teardown

  1. There's a commented-out line in the beforeAll hook:

    // await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: [] });

    If this operation is necessary for test setup, consider uncommenting and implementing it. If not, remove the comment to keep the code clean.

  2. In the afterAll hook, direct database manipulation is used instead of API calls:

    await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', dbData.testData.dokan.paymentSettings);
    // await apiUtils.setStoreSettings(payloads.defaultStoreSettings, payloads.vendorAuth);

    While this approach might be faster, it bypasses application logic and validation layers. Consider using API calls to ensure tests accurately reflect real-world scenarios and catch potential issues in the application's data handling.

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

187-197: LGTM! Changes align well with PR objectives.

The modifications to vendor permissions for payment methods are consistent with the PR's goal of adding vendor payment tests. These changes expand vendor capabilities in managing various payment methods (PayPal, bank, Skrill, and custom), allowing them to update and remove payment methods in addition to adding them.


Line range hint 1-1037: Overall changes look good and are well-focused.

The modifications in this file are concentrated in the "Payments" section and align well with the PR objective of adding vendor payment tests. The changes expand vendor capabilities for managing various payment methods, which should facilitate more comprehensive testing of vendor payment functionalities.

No unintended modifications or inconsistencies were found in other parts of the file, maintaining the integrity of existing feature permissions for different user roles and pages.

Comment on lines +82 to +90
// await apiUtils.setStoreSettings({ payment: { paypal: { email: '' } } }, payloads.vendorAuth);
await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { paypal: { email: '' } } });
await vendor.addBasicPayment({ ...data.vendor.payment, methodName: 'paypal' });
});

test('vendor can update paypal payment method', { tag: ['@lite', '@vendor'] }, async () => {
await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { paypal: { email: 'paypal@g.c' } } });
await vendor.addBasicPayment({ ...data.vendor.payment, methodName: 'paypal' });
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider using API calls for more realistic tests

  1. The test now uses direct database manipulation instead of API calls:

    await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { paypal: { email: '' } } });

    While this approach might be faster, it bypasses application logic and validation layers. Consider using API calls to ensure tests accurately reflect real-world scenarios and catch potential issues in the application's data handling.

  2. The new test for updating the PayPal payment method is a good addition, improving coverage of the PayPal functionality.

@shashwatahalder01 shashwatahalder01 changed the base branch from develop to develop_rk October 3, 2024 04:20
@shashwatahalder01 shashwatahalder01 merged commit 2fb317a into develop_rk Oct 3, 2024
1 check passed
@shashwatahalder01 shashwatahalder01 deleted the payments branch October 3, 2024 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant