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

Fix: pass expected checkout validation WP_Error instance #531

Conversation

jeebay
Copy link
Contributor

@jeebay jeebay commented Jul 27, 2021

Your checklist for this pull request

Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below.

🚨Please review the guidelines for contributing to this repository.

  • Make sure you are making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Make sure you are requesting to pull request from a topic/feature/bugfix/devops branch (right side). Don't pull request from your master!
  • Have you ensured/updated that CLI tests to extend coverage to any new logic. Learn how to modify the tests here.

What does this implement/fix? Explain your changes.

Passes an empty instance of WP_Error to the woocommerce_after_checkout_validation action hook. WooCommerce passes an error object as the second argument to the hook and several 3rd party plugins expect it to be provided. Dokan for example doesn't even check is_wp_error before calling $errors->add() resulting in runtime errors.

Normally I'd expect plugin developers to know better, do better but in this case, the wp-graphql-woocommerce breaks from Woocommerce in not passing the second argument. Supplying an empty

Does this close any currently open issues?

#448

Any relevant logs, error output, GraphiQL screenshots, etc?

Example error from my application

errors: [{,…}]
0: {,…}
debugMessage: "Too few arguments to function WeDevs\\DokanPro\\Modules\\Moip\\Module::check_vendor_configure_moip(), 1 passed in /var/www/html/web/wp/wp-includes/class-wp-hook.php on line 292 and exactly 2 expected"
extensions: {category: "internal"}
locations: [{line: 2, column: 3}]
message: "Internal server error"
path: ["checkout"]
trace: [{file: "/var/www/html/web/wp/wp-includes/class-wp-hook.php", line: 292,…},…]

Any other comments?

I attempted to add a unit test but I the tests for CheckoutMutationTest aren't passing locally on a fresh clone. Arguably no test is needed as it would just be testing WordPress internals.

Output from a fresh install

Wpunit (docker) Tests (6) ------------------------------------------------------------------------------------------------------------
✖ CheckoutMutationTest: Checkout mutation (15.33s)
✖ CheckoutMutationTest: Checkout mutation with new account (7.11s)
✖ CheckoutMutationTest: Checkout mutation with no account (6.10s)
✖ CheckoutMutationTest: Checkout mutation with prepaid order (4.53s)
S CheckoutMutationTest: Checkout mutation with stripe (2.45s)
✔ CheckoutMutationTest: Checkout mutation cart item validation (2.72s)
--------------------------------------------------------------------------------------------------------------------------------------

Time: 2.73 seconds, Memory: 103.00 MB

There were 4 failures:

---------
1) CheckoutMutationTest: Checkout mutation
 Test  tests/wpunit/CheckoutMutationTest.php:testCheckoutMutation
Failed asserting that two arrays are equal.
- Expected | + Actual
@@ @@
'metaData' => Array (
0 => Array (...)
1 => Array (...)
+                    2 => Array (...)
)
'couponLines' => Array (
'nodes' => Array (
0 => Array (
-                            'databaseId' => 131
-                            'orderId' => 20
+                            'databaseId' => null
+                            'orderId' => null
'code' => '62off'
'discount' => '398.5'
-                            'discountTax' => '79.7'
+                            'discountTax' => null

.......

It looks like a database issue with some rows not updating? I'm glad to attempt again with some guidance on how to resolve.

Where has this been tested?

N/A

  • WooGraphQL Version:
  • WPGraphQL Version:
  • WordPress Version:
  • WooCommerce Version:

@jeebay
Copy link
Contributor Author

jeebay commented Aug 5, 2021

@kidunot89 does this look reasonable to you? I did this based on how woocommerce passes an error object as the second argument to this filter.

Thank you for everything you do!

Copy link
Member

@kidunot89 kidunot89 left a comment

Choose a reason for hiding this comment

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

@jeebay So sorry about the delay review on this. Can you rebase to the develop branch and confirm if your change is passing CI/CD.

@jeebay jeebay force-pushed the bugfix/checkout-validation-hook-arg-count branch from 78672e3 to 2027873 Compare August 23, 2021 00:20
@jeebay
Copy link
Contributor Author

jeebay commented Aug 23, 2021

@kidunot89 I rebased, still failing a codeclimate check that wants the class Checkout_Mutation one of its methods to be camelcase... That feels a bit out of scope but happy to include it if you like.

@jeebay
Copy link
Contributor Author

jeebay commented Aug 31, 2021

@kidunot89 do you mind taking another look? I'm unable to run tests in CI as I'm not a maintainer.

@kidunot89
Copy link
Member

kidunot89 commented Aug 31, 2021

@jeebay Activated 👌. CI running now

@codeclimate
Copy link

codeclimate bot commented Aug 31, 2021

Code Climate has analyzed commit 2027873 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 2

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 77.0% (0.0% change).

View more on Code Climate.

@jeebay
Copy link
Contributor Author

jeebay commented Sep 1, 2021

@kidunot89 tests pass except for code climate but it looks like these two issues have been ignored previously. Do you want me to address in this PR? Also happy to do in a followup.

Copy link
Member

@kidunot89 kidunot89 left a comment

Choose a reason for hiding this comment

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

@jeebay Thanks for the work on this 👍🏿

@kidunot89 kidunot89 merged commit 69ee73b into wp-graphql:develop Sep 1, 2021
@kidunot89 kidunot89 added the bugfix Implements bugfix label Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Implements bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants