From 770159f6f62f7d8bdda67a0f37b184579347cebb Mon Sep 17 00:00:00 2001 From: George Mendoza Date: Tue, 19 Jul 2022 17:37:27 +0800 Subject: [PATCH] Fix: OrdersController#spree_current_user should be stubbed in Venmo specs Summary ------- When `spec/features/frontend/venmo_checkout_spec.rb` is enabled and ran against a working Braintree sandbox, it will fail with the following error: ``` 1) Checkout with Venmo checkout with Venmo transactions meet's Braintree's acceptance criteria during checkout Failure/Error: expect(page).to have_content('Venmo Account: venmojoe') expected to find text "Venmo Account: venmojoe" in "LOGIN\nAll departments\nHOME\nCART: (EMPTY)\nYour order has been processed successfully\nLOGIN AS EXISTING CUSTOMER\nEmail\nPassword\nRemember me\nor Create a new account | Forgot Password?\nPowered by Solidus" # ./spec/features/frontend/venmo_checkout_spec.rb:111:in `block (4 levels) in ' Finished in 16.59 seconds (files took 3.87 seconds to load) 1 example, 1 failure ``` Expected spec behavior ----------------------- Given I am logged in And I am checking out an order And I am paying for the order with Venmo When I finalize the checkout Then I should be redirected to the order page Actual spec behavior before "Deprecate try_spree_current_user" commit in Solidus -------------------------------------------------------------------------------- I am redirected to the order page as a guest. This was tested in a test app with the following setup: * Rails 6.1.6.1 * Solidus 3.1.7 * SolidusAuthDevise - 2.5.4 * SolidusPaypalBraintree c8000c559163596bbdcbc488bdfd4269db4c7ec4 - Merge pull request #317 from tvdeyen/fix-rubocop-complaints * Personal Braintree sandbox account * `checkout/valid_venmo_transaction` cassettes updated to match personal Braintree sandbox account. Actual spec behavior after "Deprecate try_spree_current_user" commit in Solidus ------------------------------------------------------------------------------- I am not allowed to go to the order page and am redirected to the login page. This was tested in a test app with the following setup: * Rails 7.0.3.1 * Solidus 3.2.0 alpha (8e5adb49eee121e3dad648bed9d6e834abcf450e) * SolidusPaypalBraintree 4890572cd2aade00b1f00315c7b9d9d6bc5b9df7 - Fix specs to stub spree_current_user) * SolidusAuthDevise 2.5.4 * "Temporarily disable failing Venmo specs" reverted * Personal Braintree sandbox account * `checkout/valid_venmo_transaction` cassettes updated to match personal Braintree sandbox account. Cause ----- `Spree::CheckoutController` uses `Spree::CheckoutControllerDecorator#completion_route` in SolidusAuthDevise to determine where the user is redirected after finalizing the order: ```rb def completion_route return spree.order_path(@order) if spree_current_user spree.token_order_path(@order, @order.guest_token) end ``` In the post-deprecation scenario, the Venmo specs stub `Spree::CheckoutsController#spree_current_user`. As a result, when finalizing the order, the user is redirected to the order path. However, the Venmo specs do not stub `Spree::OrdersController#spree_current_user`. Because of this, when the user reaches the order page, he is identified as a guest and is forced to log in. Why did it used to work before? ------------------------------- In the pre-deprecation scenario, only `Spree::CheckoutsController#try_spree_current_user` is stubbed and not `Spree::CheckoutsController#spree_current_user`. As a result, `completion_route` identifies the checkout user as a guest, and the user is redirected to the token order path. `Spree::OrdersController#show` then accepts the user as a guest because the order token is included in the URL. --- spec/features/frontend/venmo_checkout_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/features/frontend/venmo_checkout_spec.rb b/spec/features/frontend/venmo_checkout_spec.rb index b6e00560..94311b9b 100644 --- a/spec/features/frontend/venmo_checkout_spec.rb +++ b/spec/features/frontend/venmo_checkout_spec.rb @@ -146,6 +146,9 @@ def go_to_payment_checkout_page(order_number: 'R300000001' ) allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: first_user) allow_any_instance_of(Spree::CheckoutController).to receive_messages(spree_current_user: first_user) + allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: first_user) + allow_any_instance_of(Spree::OrdersController).to receive_messages(spree_current_user: first_user) + allow_any_instance_of(Spree::Payment).to receive(:gateway_order_id).and_return(order_number) visit spree.checkout_state_path(order.state)