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 Grumpy Cat on shop page (cart with items from a closed OC) #5440

Merged
merged 12 commits into from
May 22, 2020

Conversation

luisramos0
Copy link
Contributor

@luisramos0 luisramos0 commented May 15, 2020

What? Why?

Closes #5340

This issue was caused by landing on a shop page with some variants in the cart from an Order Cycle that was no longer visible to the user (either closed or some new tag rules). The code is now smart enough to verify the order_cycle is not visible and will empty the order.

Thsi was a simple if statement on the enterprise_controller but sometimes we have to make the world a better place, I mean OFN, so I went on an afternoon of refactoring by extracting new OrderCartRest service (and add some unit tests) and renaming 2 other services according to service naming conventions so now we have related services together:

  • OrderCheckoutRestart (restart order workflow)
  • OrderCompletionReset (reset order after completion)
  • OrderCartReset (reset order on shop page).

It's when we extract these services (and see how complex they are) that we see how obviously overloaded our controllers are!!! We need more of this in OFN.

What should we test?

Verify the issue is fixed. When OC is closed and there are items in the cart, the cart will be cleared up and the normal redirection rules will apply:
1- no other OCs: flash message and redirect to shops page
2- if there is only one more OC, that one will be selected and displayed
3- if there are two or more OCs, the red Oc selector will show up.

We should also try to break it by changing things in the Backoffice and load different shops pages #variation #exploratorytesting

Note: now I realize I havent tested with 3 OCs.

Release notes

Changelog Category: Fixed
Fixed grumpy cat page (422 http error) when Order Cycle was closed while user was shopping (the broken case was only when there other Order Cycles open for the same shop)

@luisramos0 luisramos0 marked this pull request as ready for review May 15, 2020 19:24
@luisramos0 luisramos0 changed the title Grumpy cat Fix Grumpy Cat on shop page (cart with items from a closed OC) May 15, 2020
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to eq(order_cycle2)
expect(controller.current_order.line_items).to be_empty
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it's worth adding specs for the cases here?

master...Matt-Yorkley:enterprise-controller-stock

  • Line item variants are all in stock
  • Line item variants are not all in stock
  • A line item's variant has been soft-deleted
  • A line item's variant has been removed from the OC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was planning to do this as part of this PR but now that Pau moved it to Test Ready with the two approvals, we can probably get this into the release.
I will work on these specs anyway and create a new PR. I am a bit all over 10's of PRs, I may get to this only on Monday.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it's fine as is. The services seem mostly covered with unit tests and we might just need to increase the integration coverage at controller level a little bit.

Copy link
Contributor

@Matt-Yorkley Matt-Yorkley left a comment

Choose a reason for hiding this comment

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

👍

OrderCycle.not_closed.with_distributor(current_distributor)
end
end

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll go to heaven for this 😍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👼

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or 👿

# frozen_string_literal: false

# Resets a completed order by building a new order based on the one specified.
# This implements the "continue shopping" feature once an order is completed.
Copy link
Contributor

Choose a reason for hiding this comment

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

pretty useful 👌

@filipefurtad0 filipefurtad0 self-assigned this May 22, 2020
@filipefurtad0 filipefurtad0 added pr-staged-fr staging.coopcircuits.fr and removed pr-staged-fr staging.coopcircuits.fr labels May 22, 2020
@filipefurtad0
Copy link
Contributor

filipefurtad0 commented May 22, 2020

Hi @luisramos0

I've checked this bug and the test cases you describe.

In summary, the bug is gone 🎉
However, I can't seem to trigger the flash warning - which was displayed before the PR, when being redirected to the homepage:
image

The test cases:
Closing OC while on checkout, with a product on cart from that OC:

1- no other OCs: redirect to shops page, but a flash message does not appear
image
2- if there is only one more OC, that one will be selected and displayed - OK

3- if there are two or more OCs, the red Oc selector will show up - OK (verified this with 3 open OCs as well)

If two open OCs have the same products, and one of them is closes before checkout, the products on the cart are not automatically allocated to the OC remaining open. Instead, one is redirected to the /shop page, either with remaining OC open (test case 2) or with the selector showing up in red (case 3).

Other tests:

  • changing prices to items in cart - all good
  • keeping the OC open but removing item - leads to the now fixed stuck on cart issue 🎉
  • adding other items to OC - all good

This is ready to go. It think the warning would be nice to have, but I don't think we should block this, for this reason. I can open a separate issue to add this.

@filipefurtad0 filipefurtad0 removed the pr-staged-fr staging.coopcircuits.fr label May 22, 2020
@sauloperez sauloperez merged commit 3f593d6 into openfoodfoundation:master May 22, 2020
@luisramos0 luisramos0 deleted the grumpy_cat branch May 22, 2020 21:20
@luisramos0
Copy link
Contributor Author

ok, thanks Filipe. Yes, let's open an issue for that missing message. We need to tackle it now.
I dont understand how it can redirect but not show the warning: the two things are just one after the other in the code... maybe some problem displaying the flash message?

@filipefurtad0
Copy link
Contributor

filipefurtad0 commented May 23, 2020

Hi @luisramos0 ,

I checked this PR again, and found a small but relevant imprecision in my notes above (confusion between shops /shops /shop). In test case 1, the user gets redirected to the /shop page, as the pic shows (not confuse with /shops - sorry for that).

To see which flash message to expect in these test cases, I had a look in the code. So, should it be this error:

a) "The shop you are looking for doesn't exist or is inactive on OFN. Please check other shops."

or this info?

b) "The order cycle you've selected has just closed. Please try again!"

According to the code it should be a), right? I could trigger both these flash messages in my system, but only when visiting or getting redirected to the /shops page. This can happen if the user is in the checkout menu with items in cart, and:

a) the shop closes (by changing the package from shop/hub to producer profile) and the user attempts to edit is cart (navigating back with the browser):

image

b) the OC closes on checkout page and the user clicks Boutiques:

image

So, both of these flash messages appear in the /shops# page. In the covered test cases the user rather gets redirected to the /shop page (not /shops or shops), so could this be the reason why I am not observing any the flash messages?

Should this be dealt in a separate issue (should I open one)?

PS - I found other issues which I don't think are related to this PR (opening issues on these):

  • Bug switching between different shops, which can be observed by the disagreement between the address bar and the actual page the user finds himself in (gif):
    Update: I can't reproduce this in production, nor on the latest release (draft)... So perhaps, this was fixed, which is good news.

switching_between_shops

  • Missing translation for the flash error b) - it seems not to exist in the en.yml

@luisramos0
Copy link
Contributor Author

luisramos0 commented May 25, 2020

Hey Filipe, thanks for the detailed update!

I understand the problem, the user has a cart and is shopping, the manager closes the OC in the backoffice (there are no other OCs), user loads the shopfront and the cart is empty and the closed shop message displays. The closed shop message is already evidently saying the cause of the empty cart. I think we are ok here.

So we would change the test case and leave it as is:
Instead of:
"no other OCs: flash message and redirect to shops page"
We have:
"no other OCs: stay on shop page where the closed shop message is displayed"

I think you did find a bug though: the missing translation of that flash message in b) 👍

@luisramos0
Copy link
Contributor Author

luisramos0 commented May 25, 2020

re that gif... @Matt-Yorkley will be happy to use his new catchphrase about caching issues!
Can you have a look at this last gif Matt?

If anyone sees that problem again I think we should open an issue for it.

@luisramos0
Copy link
Contributor Author

luisramos0 commented May 25, 2020

actually, I can replicate this problem in staging FR.
You just have to access the shop with a direct link I think.
click here: https://staging.openfoodfrance.org/fricando-hub/shop
and then click here: https://staging.openfoodfrance.org/chop-suey-farm/shop
Look at the pages...
If you refresh the page with the chop suey url, the chop suey shop will load.

@luisramos0
Copy link
Contributor Author

I cant replicate this in prod. Maybe a problem with the release?

@luisramos0
Copy link
Contributor Author

I can replicate this in staging FR by clicking around actually 🙈

  • click /shops in main menu
  • click fricando shop
  • click /shops in main menu
  • click chop seuy shop (I see Fricando shop 🙈 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grumpy cat (http 422) trying to access the shopfront
4 participants