Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Fix: OrdersController#spree_current_user should be stubbed in Venmo s…
Browse files Browse the repository at this point in the history
…pecs

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 <top (required)>'

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 c8000c5 - 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 4890572 - 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.
  • Loading branch information
gsmendoza committed Jul 19, 2022
1 parent beb170d commit 770159f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spec/features/frontend/venmo_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 770159f

Please sign in to comment.