From 0f80aca6757ebebce6311f5eb9b20b82782799a6 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 30 Apr 2024 12:23:39 +0100 Subject: [PATCH] Updates checkout tests Adds out of stock check as helper --- spec/support/checkout_helper.rb | 8 ++++++++ spec/system/consumer/checkout/details_spec.rb | 12 ++++++++++++ spec/system/consumer/checkout/payment_spec.rb | 13 ++++++++++++- spec/system/consumer/checkout/summary_spec.rb | 17 +++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/spec/support/checkout_helper.rb b/spec/support/checkout_helper.rb index fd85d4a779..6fa1bbd6aa 100644 --- a/spec/support/checkout_helper.rb +++ b/spec/support/checkout_helper.rb @@ -66,4 +66,12 @@ module CheckoutHelper click_on "Complete order" expect(page).to have_content "Back To Store" end + + def out_of_stock_check(step) + visit checkout_step_path(step) + + 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 diff --git a/spec/system/consumer/checkout/details_spec.rb b/spec/system/consumer/checkout/details_spec.rb index 6f83576155..060c5a4476 100644 --- a/spec/system/consumer/checkout/details_spec.rb +++ b/spec/system/consumer/checkout/details_spec.rb @@ -82,6 +82,18 @@ describe "As a consumer, I want to checkout my order" do visit checkout_path end + context "when a line item is out of stock" do + before do + variant.on_demand = false + variant.on_hand = 0 + variant.save! + end + + it "returns me to the cart with an error message" do + out_of_stock_check(:details) + end + end + context "when no selecting a shipping method" do before do fill_out_details diff --git a/spec/system/consumer/checkout/payment_spec.rb b/spec/system/consumer/checkout/payment_spec.rb index 0646e40185..d6f0df0c33 100644 --- a/spec/system/consumer/checkout/payment_spec.rb +++ b/spec/system/consumer/checkout/payment_spec.rb @@ -27,7 +27,6 @@ describe "As a consumer, I want to checkout my order" do ship_address_id: nil, state: "cart", line_items: [create(:line_item, variant:)]) } - let(:fee_tax_rate) { create(:tax_rate, amount: 0.10, zone:, included_in_price: true) } let(:fee_tax_category) { create(:tax_category, tax_rates: [fee_tax_rate]) } let(:enterprise_fee) { create(:enterprise_fee, amount: 1.23, tax_category: fee_tax_category) } @@ -58,6 +57,18 @@ describe "As a consumer, I want to checkout my order" do visit checkout_path end + context "when a line item is out of stock" do + before do + variant.on_demand = false + variant.on_hand = 0 + variant.save! + end + + it "returns me to the cart with an error message" do + out_of_stock_check(:payment) + end + end + context "payment step" do let(:order) { create(:order_ready_for_payment, distributor:) } diff --git a/spec/system/consumer/checkout/summary_spec.rb b/spec/system/consumer/checkout/summary_spec.rb index 1b27719717..a1c8a393ce 100644 --- a/spec/system/consumer/checkout/summary_spec.rb +++ b/spec/system/consumer/checkout/summary_spec.rb @@ -35,6 +35,11 @@ describe "As a consumer, I want to checkout my order" do create(:shipping_method, require_ship_address: true, name: "A Free Shipping with required address") } + let!(:payment_with_fee) { + create(:payment_method, distributors: [distributor], + name: "Payment with Fee", description: "Payment with fee", + calculator: Calculator::FlatRate.new(preferred_amount: 1.23)) + } before do add_enterprise_fee enterprise_fee @@ -51,6 +56,18 @@ describe "As a consumer, I want to checkout my order" do visit checkout_path end + context "when a line item is out of stock" do + before do + variant.on_demand = false + variant.on_hand = 0 + variant.save! + end + + it "returns me to the cart with an error message" do + out_of_stock_check(:summary) + end + end + context "summary step" do let(:order) { create(:order_ready_for_confirmation, distributor:)