From 1fdd36e491a59f378ca201bea5b6818b72562998 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 8 Mar 2022 22:30:14 +0000 Subject: [PATCH 1/4] Adds coverage on shipping fees, on split checkout --- spec/system/consumer/split_checkout_spec.rb | 31 ++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 294c9cdaa9..29c053a3fc 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -199,7 +199,7 @@ describe "As a consumer, I want to checkout my order", js: true do end end - describe "selecting a delivery method" do + describe "selecting a delivery method with a shipping fee" do before do choose shipping_with_fee.name end @@ -208,6 +208,11 @@ describe "As a consumer, I want to checkout my order", js: true do before do check "ship_address_same_as_billing" end + + it "displays the shipping fee" do + expect(page).to have_content("#{shipping_with_fee.name} " + "#{with_currency(4.56)}") + end + it "does not display the shipping address form" do expect(page).not_to have_field "order_ship_address_attributes_address1" end @@ -220,6 +225,30 @@ describe "As a consumer, I want to checkout my order", js: true do expect(Spree::Address.where(id: bill_add_id).pluck(:address1) == Spree::Address.where(id: ship_add_id).pluck(:address1)).to be true end + + context "with a shipping fee" do + before do + proceed_to_payment + click_button "Next - Order summary" + end + + shared_examples "displays the shipping fee" do |checkout_page| + it "on the #{checkout_page} page" do + within "#line-items" do + expect(page).to have_content("Shipping #{with_currency(4.56)}") + end + end + end + + it_behaves_like "displays the shipping fee", "order summary" + + context "after completing the order" do + before do + click_on "Complete order" + end + it_behaves_like "displays the shipping fee", "order confirmation" + end + end end context "with different shipping and billing address" do From 509a114d51d8831227bee429eb7d78a04d40cf9c Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 8 Mar 2022 23:10:48 +0000 Subject: [PATCH 2/4] Adds coverage on transaction fees for split checkout --- spec/system/consumer/split_checkout_spec.rb | 41 ++++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 29c053a3fc..7a9b18785d 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -43,7 +43,9 @@ describe "As a consumer, I want to checkout my order", js: true do name: "Shipping with Fee", description: "blue", calculator: Calculator::FlatRate.new(preferred_amount: 4.56)) } - let!(:payment_method) { create(:payment_method, distributors: [distributor]) } + 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 allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) @@ -345,24 +347,51 @@ describe "As a consumer, I want to checkout my order", js: true do context "payment step" do let(:order) { create(:order_ready_for_payment, distributor: distributor) } - context "with one payment method" do - it "preselect the payment method if only one is available" do + context "with one payment method, with a fee" do + before do visit checkout_step_path(:payment) + end + it "preselect the payment method if only one is available" do + expect(page).to have_checked_field "payment_method_#{payment_with_fee.id}" + end + it "displays the transaction fee" do + expect(page).to have_content("#{payment_with_fee.name} " + "(#{with_currency(1.23)})") + end + end - expect(page).to have_checked_field "payment_method_#{payment_method.id}" + context "with a transaction fee" do + before do + click_button "Next - Order summary" + end + + shared_examples "displays the transaction fee" do |checkout_page| + it "on the #{checkout_page} page" do + within "#line-items" do + expect(page).to have_content("Transaction fee #{with_currency(1.23)}") + end + end + end + + it_behaves_like "displays the transaction fee", "order summary" + + context "after completing the order" do + before do + click_on "Complete order" + end + it_behaves_like "displays the transaction fee", "order confirmation" end end context "with more than one payment method" do - let!(:payment_method2) { create(:payment_method, distributors: [distributor]) } + let!(:payment_method) { create(:payment_method, distributors: [distributor]) } before do visit checkout_step_path(:payment) end it "don't preselect the payment method if more than one is available" do + expect(page).to have_field "payment_method_#{payment_with_fee.id}", checked: false expect(page).to have_field "payment_method_#{payment_method.id}", checked: false - expect(page).to have_field "payment_method_#{payment_method2.id}", checked: false end it "requires choosing a payment method" do From a6486c270176123e2962c7f7efa302797b8e4695 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 8 Mar 2022 23:12:05 +0000 Subject: [PATCH 3/4] Adds assertion on the order confirmation page --- spec/system/consumer/split_checkout_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 7a9b18785d..6fa88f436c 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -239,6 +239,9 @@ describe "As a consumer, I want to checkout my order", js: true do within "#line-items" do expect(page).to have_content("Shipping #{with_currency(4.56)}") end + if checkout_page.eql?("order confirmation") + expect(page).to have_content "Your order has been processed successfully" + end end end @@ -369,6 +372,9 @@ describe "As a consumer, I want to checkout my order", js: true do within "#line-items" do expect(page).to have_content("Transaction fee #{with_currency(1.23)}") end + if checkout_page.eql?("order confirmation") + expect(page).to have_content "Your order has been processed successfully" + end end end From 16fcde7053fe693ccfda1009a1d11a67d3549d41 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 8 Mar 2022 23:13:24 +0000 Subject: [PATCH 4/4] Fixes rubocop offenses --- spec/system/consumer/split_checkout_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 6fa88f436c..a203276e66 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -43,9 +43,11 @@ describe "As a consumer, I want to checkout my order", js: true do name: "Shipping with Fee", description: "blue", calculator: Calculator::FlatRate.new(preferred_amount: 4.56)) } - 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)) } + 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 allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) @@ -212,7 +214,7 @@ describe "As a consumer, I want to checkout my order", js: true do end it "displays the shipping fee" do - expect(page).to have_content("#{shipping_with_fee.name} " + "#{with_currency(4.56)}") + expect(page).to have_content("#{shipping_with_fee.name} " + with_currency(4.56).to_s) end it "does not display the shipping address form" do @@ -244,7 +246,7 @@ describe "As a consumer, I want to checkout my order", js: true do end end end - + it_behaves_like "displays the shipping fee", "order summary" context "after completing the order" do @@ -377,7 +379,7 @@ describe "As a consumer, I want to checkout my order", js: true do end end end - + it_behaves_like "displays the transaction fee", "order summary" context "after completing the order" do