From 9dceda7e208bf23c88d432e35d6737bd71beeabc Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 22 Feb 2022 12:21:12 +0000 Subject: [PATCH 1/8] Creates a details test block; moves respective tests inside --- spec/system/consumer/split_checkout_spec.rb | 219 ++++++++++---------- 1 file changed, 111 insertions(+), 108 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 91a98d0e3f..39e52c818c 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -131,133 +131,136 @@ describe "As a consumer, I want to checkout my order", js: true do visit checkout_path end - describe "filling out delivery details" do - before do - fill_out_details - fill_out_billing_address - end - describe "selecting a pick-up shipping method and submiting the form" do + context "details step" do + describe "filling out delivery details" do before do - choose free_shipping.name + fill_out_details + fill_out_billing_address end - it "redirects the user to the Payment Method step" do - fill_notes("SpEcIaL NoTeS") - proceed_to_payment - end - end - - describe "selecting a delivery method" do - before do - choose shipping_with_fee.name - end - - context "with same shipping and billing address" do + describe "selecting a pick-up shipping method and submiting the form" do before do - check "ship_address_same_as_billing" - end - it "does not display the shipping address form" do - expect(page).not_to have_field "order_ship_address_attributes_address1" + choose free_shipping.name end - it "redirects the user to the Payment Method step, when submiting the form" do - proceed_to_payment - # asserts whether shipping and billing addresses are the same - ship_add_id = order.reload.ship_address_id - bill_add_id = order.reload.bill_address_id - expect(Spree::Address.where(id: bill_add_id).pluck(:address1) == - Spree::Address.where(id: ship_add_id).pluck(:address1)).to be true - end - end - - context "with different shipping and billing address" do - before do - uncheck "ship_address_same_as_billing" - end - it "displays the shipping address form and the option to save it as default" do - expect(page).to have_field "order_ship_address_attributes_address1" - end - - it "displays error messages when submitting incomplete billing address" do - click_button "Next - Payment method" - expect(page).to have_content "Saving failed, please update the highlighted fields." - expect(page).to have_field("Address", with: "") - expect(page).to have_field("City", with: "") - expect(page).to have_field("Postcode", with: "") - expect(page).to have_content("can't be blank", count: 3) - end - - it "fills in shipping details and redirects the user to the Payment Method step, - when submiting the form" do - fill_out_shipping_address + it "redirects the user to the Payment Method step" do fill_notes("SpEcIaL NoTeS") proceed_to_payment - # asserts whether shipping and billing addresses are the same - ship_add_id = Spree::Order.first.ship_address_id - bill_add_id = Spree::Order.first.bill_address_id - expect(Spree::Address.where(id: bill_add_id).pluck(:address1) == - Spree::Address.where(id: ship_add_id).pluck(:address1)).to be false + end + end + + describe "selecting a delivery method" do + before do + choose shipping_with_fee.name + end + + context "with same shipping and billing address" do + before do + check "ship_address_same_as_billing" + end + it "does not display the shipping address form" do + expect(page).not_to have_field "order_ship_address_attributes_address1" + end + + it "redirects the user to the Payment Method step, when submiting the form" do + proceed_to_payment + # asserts whether shipping and billing addresses are the same + ship_add_id = order.reload.ship_address_id + bill_add_id = order.reload.bill_address_id + expect(Spree::Address.where(id: bill_add_id).pluck(:address1) == + Spree::Address.where(id: ship_add_id).pluck(:address1)).to be true + end + end + + context "with different shipping and billing address" do + before do + uncheck "ship_address_same_as_billing" + end + it "displays the shipping address form and the option to save it as default" do + expect(page).to have_field "order_ship_address_attributes_address1" + end + + it "displays error messages when submitting incomplete billing address" do + click_button "Next - Payment method" + expect(page).to have_content "Saving failed, please update the highlighted fields." + expect(page).to have_field("Address", with: "") + expect(page).to have_field("City", with: "") + expect(page).to have_field("Postcode", with: "") + expect(page).to have_content("can't be blank", count: 3) + end + + it "fills in shipping details and redirects the user to the Payment Method step, + when submiting the form" do + fill_out_shipping_address + fill_notes("SpEcIaL NoTeS") + proceed_to_payment + # asserts whether shipping and billing addresses are the same + ship_add_id = Spree::Order.first.ship_address_id + bill_add_id = Spree::Order.first.bill_address_id + expect(Spree::Address.where(id: bill_add_id).pluck(:address1) == + Spree::Address.where(id: ship_add_id).pluck(:address1)).to be false + end + end + end + + describe "pre-selecting a shipping method" do + it "preselect a shipping method if only one is available" do + order.distributor.update! shipping_methods: [free_shipping] + + visit checkout_step_path(:details) + + expect(page).to have_checked_field "shipping_method_#{free_shipping.id}" + end + + it "don't preselect a shipping method if more than one is available" do + order.distributor.update! shipping_methods: [free_shipping, shipping_with_fee] + + visit checkout_step_path(:details) + + expect(page).to have_field "shipping_method_#{free_shipping.id}", checked: false + expect(page).to have_field "shipping_method_#{shipping_with_fee.id}", checked: false end end end - describe "pre-selecting a shipping method" do - it "preselect a shipping method if only one is available" do - order.distributor.update! shipping_methods: [free_shipping] - - visit checkout_step_path(:details) - - expect(page).to have_checked_field "shipping_method_#{free_shipping.id}" + describe "not filling out delivery details" do + before do + fill_in "Email", with: "" end - - it "don't preselect a shipping method if more than one is available" do - order.distributor.update! shipping_methods: [free_shipping, shipping_with_fee] - - visit checkout_step_path(:details) - - expect(page).to have_field "shipping_method_#{free_shipping.id}", checked: false - expect(page).to have_field "shipping_method_#{shipping_with_fee.id}", checked: false + it "should display error when fields are empty" do + click_button "Next - Payment method" + expect(page).to have_content("Saving failed, please update the highlighted fields") + expect(page).to have_field("First Name", with: "") + expect(page).to have_field("Last Name", with: "") + expect(page).to have_field("Email", with: "") + expect(page).to have_content("is invalid") + expect(page).to have_field("Phone number", with: "") + expect(page).to have_field("Address", with: "") + expect(page).to have_field("City", with: "") + expect(page).to have_field("Postcode", with: "") + expect(page).to have_content("can't be blank", count: 7) + expect(page).to have_content("Select a shipping method") end end - end - describe "not filling out delivery details" do - before do - fill_in "Email", with: "" - end - it "should display error when fields are empty" do - click_button "Next - Payment method" - expect(page).to have_content("Saving failed, please update the highlighted fields") - expect(page).to have_field("First Name", with: "") - expect(page).to have_field("Last Name", with: "") - expect(page).to have_field("Email", with: "") - expect(page).to have_content("is invalid") - expect(page).to have_field("Phone number", with: "") - expect(page).to have_field("Address", with: "") - expect(page).to have_field("City", with: "") - expect(page).to have_field("Postcode", with: "") - expect(page).to have_content("can't be blank", count: 7) - expect(page).to have_content("Select a shipping method") - end - end + context "with a saved address" do + let!(:address_state) do + create(:state, name: "Testville", abbr: "TST", country: DefaultCountry.country ) + end + let(:saved_address) do + create(:bill_address, state: address_state, zipcode: "TST01" ) + end - context "with a saved address" do - let!(:address_state) do - create(:state, name: "Testville", abbr: "TST", country: DefaultCountry.country ) - end - let(:saved_address) do - create(:bill_address, state: address_state, zipcode: "TST01" ) - end + before do + user.update_columns bill_address_id: saved_address.id + end - before do - user.update_columns bill_address_id: saved_address.id - end - - it "pre-fills address details" do - visit checkout_path - expect(page).to have_select "order_bill_address_attributes_state_id", selected: "Testville" - expect(page).to have_field "order_bill_address_attributes_zipcode", with: "TST01" + it "pre-fills address details" do + visit checkout_path + expect(page).to have_select "order_bill_address_attributes_state_id", selected: "Testville" + expect(page).to have_field "order_bill_address_attributes_zipcode", with: "TST01" + end end end From 9449c7c9196a24d3d6126d9339f1e94481a47abb Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 22 Feb 2022 12:35:14 +0000 Subject: [PATCH 2/8] Adds a context for existing test case --- spec/system/consumer/split_checkout_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 39e52c818c..80b23e9a03 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -267,10 +267,12 @@ describe "As a consumer, I want to checkout my order", js: true do context "payment method step" do let(:order) { create(:order_ready_for_payment, distributor: distributor) } - it "preselect the payment method if only one is available" do - visit checkout_step_path(:payment) + context "with one payment method" do + it "preselect the payment method if only one is available" do + visit checkout_step_path(:payment) - expect(page).to have_checked_field "payment_method_#{payment_method.id}" + expect(page).to have_checked_field "payment_method_#{payment_method.id}" + end end context "with more than one payment method" do From 09cd9b8462710ab476ab644c7794a646d059d553 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 22 Feb 2022 13:45:52 +0000 Subject: [PATCH 3/8] Adds a test on payment method requirement --- spec/system/consumer/split_checkout_spec.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 80b23e9a03..7b47a7a8e5 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -264,7 +264,7 @@ describe "As a consumer, I want to checkout my order", js: true do end end - context "payment method step" do + context "payment step" do let(:order) { create(:order_ready_for_payment, distributor: distributor) } context "with one payment method" do @@ -278,12 +278,19 @@ describe "As a consumer, I want to checkout my order", js: true do context "with more than one payment method" do let!(:payment_method2) { create(:payment_method, distributors: [distributor]) } - it "don't preselect the payment method if more than one is available" do + 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_method.id}", checked: false expect(page).to have_field "payment_method_#{payment_method2.id}", checked: false end + + it "requires choosing a payment method" do + click_on "Next - Order summary" + expect(page).to have_content "Select a payment method" + end end end From ae3eb90668c874b1660ad62a0e25f47f23b25659 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 22 Feb 2022 13:53:05 +0000 Subject: [PATCH 4/8] Adds shared examples block, with cash --- spec/system/consumer/split_checkout_spec.rb | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 7b47a7a8e5..4774c0f179 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -292,6 +292,30 @@ describe "As a consumer, I want to checkout my order", js: true do expect(page).to have_content "Select a payment method" end end + + describe "choosing" do + shared_examples "bewteen different payment methods" do |pay_method| + let!(:payment_method3) { create(:payment_method, distributors: [distributor], name: "Cash") } + let!(:payment_method4) { create(:payment_method, distributors: [distributor], name: "BoGuS") } + + before do + visit checkout_step_path(:payment) + end + + context "like #{pay_method}" do + it "selects it and proceeds to the summary step" do + choose "#{pay_method}" + click_on "Next - Order summary" + expect(page).to have_content "Shopping @ #{distributor.name}" + end + end + end + describe "shared examples" do + context "legacy checkout" do + it_behaves_like "bewteen different payment methods", "Cash" + end + end + end end context "summary step" do From d336ab52a1f9fb192785dc991729f6e1281badf1 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 22 Feb 2022 16:14:29 +0000 Subject: [PATCH 5/8] Adds Paypal to shared examples block --- spec/system/consumer/split_checkout_spec.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 4774c0f179..af9aed6600 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -131,7 +131,6 @@ describe "As a consumer, I want to checkout my order", js: true do visit checkout_path end - context "details step" do describe "filling out delivery details" do before do @@ -281,7 +280,7 @@ describe "As a consumer, I want to checkout my order", js: true do 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_method.id}", checked: false expect(page).to have_field "payment_method_#{payment_method2.id}", checked: false @@ -296,15 +295,21 @@ describe "As a consumer, I want to checkout my order", js: true do describe "choosing" do shared_examples "bewteen different payment methods" do |pay_method| let!(:payment_method3) { create(:payment_method, distributors: [distributor], name: "Cash") } - let!(:payment_method4) { create(:payment_method, distributors: [distributor], name: "BoGuS") } + let!(:paypal) do + Spree::Gateway::PayPalExpress.create!( + name: "Paypal", + environment: "test", + distributor_ids: [distributor.id] + ) + end before do visit checkout_step_path(:payment) end context "like #{pay_method}" do - it "selects it and proceeds to the summary step" do - choose "#{pay_method}" + it "selects it and proceeds to the summary step" do + choose pay_method.to_s click_on "Next - Order summary" expect(page).to have_content "Shopping @ #{distributor.name}" end @@ -313,6 +318,7 @@ describe "As a consumer, I want to checkout my order", js: true do describe "shared examples" do context "legacy checkout" do it_behaves_like "bewteen different payment methods", "Cash" + it_behaves_like "bewteen different payment methods", "Paypal" end end end From c4bf36d402686ae0c877e64934316373cda6a7f3 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 22 Feb 2022 17:05:14 +0000 Subject: [PATCH 6/8] Adds Stripe SCA to shared examples block --- spec/system/consumer/split_checkout_spec.rb | 30 ++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index af9aed6600..17965917a3 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -6,6 +6,8 @@ describe "As a consumer, I want to checkout my order", js: true do include ShopWorkflow include SplitCheckoutHelper include FileHelper + include StripeHelper + include StripeStubs let!(:zone) { create(:zone_with_member) } let(:supplier) { create(:supplier_enterprise) } @@ -303,22 +305,42 @@ describe "As a consumer, I want to checkout my order", js: true do ) end - before do - visit checkout_step_path(:payment) - end + context "like #{pay_method}", if: pay_method.eql?("Stripe SCA") == false do + before do + visit checkout_step_path(:payment) + end - context "like #{pay_method}" do it "selects it and proceeds to the summary step" do choose pay_method.to_s click_on "Next - Order summary" expect(page).to have_content "Shopping @ #{distributor.name}" end end + + context "for Stripe SCA", if: pay_method.eql?("Stripe SCA") do + let!(:stripe_account) { create(:stripe_account, enterprise: distributor) } + let!(:stripe_sca_payment_method) { + create(:stripe_sca_payment_method, distributors: [distributor], name: "Stripe SCA") + } + + before do + setup_stripe + visit checkout_step_path(:payment) + end + + it "selects Stripe SCA and proceeds to the summary step" do + choose pay_method.to_s + fill_out_card_details + click_on "Next - Order summary" + expect(page).to have_content "Shopping @ #{distributor.name}" + end + end end describe "shared examples" do context "legacy checkout" do it_behaves_like "bewteen different payment methods", "Cash" it_behaves_like "bewteen different payment methods", "Paypal" + it_behaves_like "bewteen different payment methods", "Stripe SCA" end end end From daffe333c5232989f336c5f49ee204e514cbd181 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 23 Feb 2022 19:03:03 +0000 Subject: [PATCH 7/8] Adds coverage on order completition for Cash/Paypal --- spec/system/consumer/split_checkout_spec.rb | 66 ++++++++++++++------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 17965917a3..98d282c732 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -8,6 +8,7 @@ describe "As a consumer, I want to checkout my order", js: true do include FileHelper include StripeHelper include StripeStubs + include PaypalHelper let!(:zone) { create(:zone_with_member) } let(:supplier) { create(:supplier_enterprise) } @@ -295,34 +296,27 @@ describe "As a consumer, I want to checkout my order", js: true do end describe "choosing" do - shared_examples "bewteen different payment methods" do |pay_method| - let!(:payment_method3) { create(:payment_method, distributors: [distributor], name: "Cash") } - let!(:paypal) do - Spree::Gateway::PayPalExpress.create!( - name: "Paypal", - environment: "test", - distributor_ids: [distributor.id] - ) - end + shared_examples "different payment methods" do |pay_method| - context "like #{pay_method}", if: pay_method.eql?("Stripe SCA") == false do + context "checking out with #{pay_method}", if: pay_method.eql?("Stripe SCA") == false do before do visit checkout_step_path(:payment) end - it "selects it and proceeds to the summary step" do + it "proceeds to the summary step and completes the order" do choose pay_method.to_s click_on "Next - Order summary" expect(page).to have_content "Shopping @ #{distributor.name}" + + click_on "Complete order" + expect(page).to have_content "Back To Store" + expect(page).to have_content "Paying via: #{pay_method}" + expect(order.reload.state).to eq "complete" end + end context "for Stripe SCA", if: pay_method.eql?("Stripe SCA") do - let!(:stripe_account) { create(:stripe_account, enterprise: distributor) } - let!(:stripe_sca_payment_method) { - create(:stripe_sca_payment_method, distributors: [distributor], name: "Stripe SCA") - } - before do setup_stripe visit checkout_step_path(:payment) @@ -336,11 +330,43 @@ describe "As a consumer, I want to checkout my order", js: true do end end end + describe "shared examples" do - context "legacy checkout" do - it_behaves_like "bewteen different payment methods", "Cash" - it_behaves_like "bewteen different payment methods", "Paypal" - it_behaves_like "bewteen different payment methods", "Stripe SCA" + let!(:payment_method3) { create(:payment_method, distributors: [distributor], name: "Cash") } + + context "Cash" do + it_behaves_like "different payment methods", "Cash" + end + + context "Paypal" do + let!(:paypal) do + Spree::Gateway::PayPalExpress.create!( + name: "Paypal", + environment: "test", + distributor_ids: [distributor.id] + ) + end + + before do + stub_paypal_response( + success: true, + redirect: payment_gateways_confirm_paypal_path( + payment_method_id: paypal.id, token: "t123", PayerID: 'p123' + ) + ) + stub_paypal_confirm + end + + it_behaves_like "different payment methods", "Paypal" + end + + context "Stripe SCA" do + let!(:stripe_account) { create(:stripe_account, enterprise: distributor) } + let!(:stripe_sca_payment_method) { + create(:stripe_sca_payment_method, distributors: [distributor], name: "Stripe SCA") + } + + it_behaves_like "different payment methods", "Stripe SCA" end end end From 82b6d39191ee2fde5eb61dd7683e16db6c09fd8c Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 25 Feb 2022 16:03:33 +0000 Subject: [PATCH 8/8] Re-names payment; addresses style issues --- spec/system/consumer/split_checkout_spec.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 98d282c732..009038fc6c 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -297,7 +297,6 @@ describe "As a consumer, I want to checkout my order", js: true do describe "choosing" do shared_examples "different payment methods" do |pay_method| - context "checking out with #{pay_method}", if: pay_method.eql?("Stripe SCA") == false do before do visit checkout_step_path(:payment) @@ -313,7 +312,6 @@ describe "As a consumer, I want to checkout my order", js: true do expect(page).to have_content "Paying via: #{pay_method}" expect(order.reload.state).to eq "complete" end - end context "for Stripe SCA", if: pay_method.eql?("Stripe SCA") do @@ -330,14 +328,14 @@ describe "As a consumer, I want to checkout my order", js: true do end end end - + describe "shared examples" do - let!(:payment_method3) { create(:payment_method, distributors: [distributor], name: "Cash") } - + let!(:cash) { create(:payment_method, distributors: [distributor], name: "Cash") } + context "Cash" do it_behaves_like "different payment methods", "Cash" end - + context "Paypal" do let!(:paypal) do Spree::Gateway::PayPalExpress.create!( @@ -359,7 +357,7 @@ describe "As a consumer, I want to checkout my order", js: true do it_behaves_like "different payment methods", "Paypal" end - + context "Stripe SCA" do let!(:stripe_account) { create(:stripe_account, enterprise: distributor) } let!(:stripe_sca_payment_method) {