From eb560275050f416125cbd37af7f6f96788d3917a Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 27 Feb 2022 19:56:45 +0000 Subject: [PATCH 1/2] Moves out-of-stock block within correct context --- spec/system/consumer/split_checkout_spec.rb | 29 +++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 91a98d0e3f..278b84ea79 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -121,6 +121,21 @@ describe "As a consumer, I want to checkout my order", js: true do expect(page).to have_current_path("/checkout/details") end end + + context "when I have an out of stock product in my cart" do + before do + variant.update!(on_demand: false, on_hand: 0) + end + + it "returns me to the cart with an error message" do + visit checkout_path + + expect(page).not_to have_selector 'closing', text: "Checkout now" + expect(page).to have_selector 'closing', text: "Your shopping cart" + expect(page).to have_content "An item in your cart has become unavailable" + expect(page).to have_content "Update" + end + end end context "as a logged in user" do @@ -427,18 +442,4 @@ describe "As a consumer, I want to checkout my order", js: true do end end end - - context "when I have an out of stock product in my cart" do - before do - variant.update!(on_demand: false, on_hand: 0) - end - - it "returns me to the cart with an error message" do - visit checkout_path - - expect(page).not_to have_selector 'closing', text: "Checkout now" - expect(page).to have_selector 'closing', text: "Your shopping cart" - expect(page).to have_content "An item in your cart has become unavailable" - end - end end From 7a6f3d67e2ddea5265780e96772eeac4588075aa Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 27 Feb 2022 21:33:06 +0000 Subject: [PATCH 2/2] Implements shared example; Checks stock restriction on payment step --- spec/system/consumer/split_checkout_spec.rb | 43 +++++++++++++++------ 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 278b84ea79..58008fe9cf 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -70,6 +70,21 @@ describe "As a consumer, I want to checkout my order", js: true do end end + shared_examples "when I have an out of stock product in my cart" do + before do + variant.update!(on_demand: false, on_hand: 0) + end + + it "returns me to the cart with an error message" do + visit checkout_path + + expect(page).not_to have_selector 'closing', text: "Checkout now" + expect(page).to have_selector 'closing', text: "Your shopping cart" + expect(page).to have_content "An item in your cart has become unavailable" + expect(page).to have_content "Update" + end + end + context "as a guest user" do before do visit checkout_path @@ -114,26 +129,32 @@ describe "As a consumer, I want to checkout my order", js: true do expect(page).to have_button("Next - Order summary") end - context "when order is state: 'payment'" do - it "should allow visit '/checkout/details'" do - order.update(state: "payment") + context "on the 'details' step" do + before do visit checkout_step_path(:details) + end + + it "should allow visit '/checkout/details'" do expect(page).to have_current_path("/checkout/details") end + + it_behaves_like "when I have an out of stock product in my cart" end - context "when I have an out of stock product in my cart" do + context "on the 'payment' step" do before do - variant.update!(on_demand: false, on_hand: 0) + order.update(state: "payment") + visit checkout_step_path(:payment) end - it "returns me to the cart with an error message" do - visit checkout_path + it "should allow visit '/checkout/payment'" do + expect(page).to have_current_path("/checkout/payment") + end - expect(page).not_to have_selector 'closing', text: "Checkout now" - expect(page).to have_selector 'closing', text: "Your shopping cart" - expect(page).to have_content "An item in your cart has become unavailable" - expect(page).to have_content "Update" + context "when I have an out of stock product in my cart" do + pending("awaiting closure bug #8940") do + it_behaves_like "when I have an out of stock product in my cart" + end end end end