Update order state when moving back through checkout step

Some important logic happens after the order transition from one state
to another. In particular, voucher are recalculated. To fix any
inconsistency, we make sure the order is the state matching the checkout
step we are on.
This commit is contained in:
Gaetan Craig-Riou
2023-10-18 09:45:05 +11:00
parent d0e38c8d10
commit b09054a76a
3 changed files with 54 additions and 2 deletions

View File

@@ -67,6 +67,42 @@ describe SplitCheckoutController, type: :controller do
expect(response).to redirect_to checkout_step_path(:payment)
end
end
context "when order state is 'confirmation'" do
before do
order.update!(state: "confirmation")
end
context "when loading payment step" do
it "updates the order state to payment" do
get :edit, params: { step: "payment" }
expect(order.reload.state).to eq("payment")
end
end
context "when loading address step" do
it "updates the order state to address" do
get :edit, params: { step: "details" }
expect(order.reload.state).to eq("address")
end
end
end
context "when order state is 'payment'" do
context "when loading address step" do
before do
order.update!(state: "payment")
end
it "updates the order state to address" do
get :edit, params: { step: "details" }
expect(order.reload.state).to eq("address")
end
end
end
end
end