mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Check step params and redirect if step is inconsistent to order state
This commit is contained in:
committed by
Maikel Linke
parent
a6e3f43344
commit
77eec6e6f3
@@ -21,6 +21,7 @@ class SplitCheckoutController < ::BaseController
|
||||
|
||||
def edit
|
||||
redirect_to_step_based_on_order unless params[:step]
|
||||
check_step if params[:step]
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -145,4 +146,13 @@ class SplitCheckoutController < ::BaseController
|
||||
end
|
||||
redirect_to_step_based_on_order
|
||||
end
|
||||
|
||||
def check_step
|
||||
case @order.state
|
||||
when "cart", "address", "delivery"
|
||||
redirect_to checkout_step_path(:details) unless params[:step] == "details"
|
||||
when "payment"
|
||||
redirect_to checkout_step_path(:payment) if params[:step] == "summary"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,6 +43,34 @@ describe SplitCheckoutController, type: :controller do
|
||||
expect(response).to redirect_to cart_path
|
||||
end
|
||||
end
|
||||
|
||||
context "when the given `step` params is inconsistent with the current order state" do
|
||||
context "when order state is `cart`" do
|
||||
before do
|
||||
order.update!(state: "cart")
|
||||
end
|
||||
|
||||
it "redirects to the valid step if params is `payment`" do
|
||||
get :edit, params: { step: "payment" }
|
||||
expect(response).to redirect_to checkout_step_path(:details)
|
||||
end
|
||||
it "redirects to the valid step if params is `summary`" do
|
||||
get :edit, params: { step: "summary" }
|
||||
expect(response).to redirect_to checkout_step_path(:details)
|
||||
end
|
||||
end
|
||||
|
||||
context "when order state is `payment`" do
|
||||
before do
|
||||
order.update!(state: "payment")
|
||||
end
|
||||
|
||||
it "redirects to the valid step if params is `summary`" do
|
||||
get :edit, params: { step: "summary" }
|
||||
expect(response).to redirect_to checkout_step_path(:payment)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#update" do
|
||||
|
||||
@@ -220,7 +220,6 @@ describe "As a consumer, I want to see adjustment breakdown" do
|
||||
# reproducing bug #9131
|
||||
context "redirection to /summary page with no shipping method selected" do
|
||||
it "fails to render the /summary page" do
|
||||
pending("#9131")
|
||||
visit checkout_step_path(:summary)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user