From 447d146365526908917c6e9edcbc16537d186661 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 5 Jan 2022 16:49:50 +0000 Subject: [PATCH 01/10] Adds test out of stock product redirect --- spec/system/consumer/split_checkout_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 986e95dc4b..4e9ff6b2b9 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -85,4 +85,20 @@ describe "As a consumer, I want to checkout my order", js: true do expect(page).to have_current_path("/checkout/payment") end end + + context "when I have an out of stock product in my cart" 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 + 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 93478d4079cd64bbe2186b15d47afc1faa520688 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 6 Jan 2022 10:18:36 +0000 Subject: [PATCH 02/10] Adds split-checkout helper --- .../request/split_checkout_request_helper.rb | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 spec/support/request/split_checkout_request_helper.rb diff --git a/spec/support/request/split_checkout_request_helper.rb b/spec/support/request/split_checkout_request_helper.rb new file mode 100644 index 0000000000..8585d03d5a --- /dev/null +++ b/spec/support/request/split_checkout_request_helper.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module SplitCheckoutRequestsHelper + def have_split_checkout_details + have_content "Your details" + end + + def split_checkout_as_guest + click_button "Checkout as guest" + end + + def split_place_order + find("button", text: "Complete order").click + end + + def split_fill_out_details + # Section: Your Details + within(:xpath, './/div[@class="checkout-substep"][1]') do + fill_in "First Name", with: "Will" + fill_in "Last Name", with: "Marshall" + fill_in "Email", with: "test@test.com" + fill_in "Phone", with: "0468363090" + end + end + + def split_fill_out_billing_address + # Section: Your Billing Address + within(:xpath, './/div[@class="checkout-substep"][2]') do + fill_in "Address", with: "Rue de la Vie, 77" + fill_in "City", with: "Melbourne" + fill_in "Postcode", with: "3066" + select "Australia", from: "Country" + select "Victoria", from: "State" + end + end + + def split_fill_out_shipping_address + # Section: Delivery Address + within(:xpath, './/div[@class="checkout-substep"][3]') do + fill_in "Address", with: "Rue de la Vie, 66" + fill_in "City", with: "Perth" + fill_in "Postcode", with: "2899" + select "Australia", from: "Country" + select "New South Wales", from: "State" + end + end +end From 9685bb6ae9a03eae1192225382f4ed2954fe6928 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 6 Jan 2022 10:21:12 +0000 Subject: [PATCH 03/10] Adds tests for logged-in user scenarios --- spec/system/consumer/split_checkout_spec.rb | 51 ++++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 4e9ff6b2b9..9aa6a42acf 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -2,6 +2,8 @@ require "system_helper" +include SplitCheckoutRequestsHelper + describe "As a consumer, I want to checkout my order", js: true do include ShopWorkflow @@ -26,13 +28,13 @@ describe "As a consumer, I want to checkout my order", js: true do let(:enterprise_fee) { create(:enterprise_fee, amount: 1.23, tax_category: fee_tax_category) } let(:free_shipping) { - create(:shipping_method, require_ship_address: true, name: "Free Shipping", description: "yellow", + create(:shipping_method, require_ship_address: false, name: "Free Shipping", description: "yellow", calculator: Calculator::FlatRate.new(preferred_amount: 0.00)) } let(:shipping_tax_rate) { create(:tax_rate, amount: 0.25, zone: zone, included_in_price: true) } let(:shipping_tax_category) { create(:tax_category, tax_rates: [shipping_tax_rate]) } let(:shipping_with_fee) { - create(:shipping_method, require_ship_address: false, tax_category: shipping_tax_category, + create(:shipping_method, require_ship_address: true, tax_category: shipping_tax_category, name: "Shipping with Fee", description: "blue", calculator: Calculator::FlatRate.new(preferred_amount: 4.56)) } @@ -86,6 +88,51 @@ describe "As a consumer, I want to checkout my order", js: true do end end + describe 'login in as user' do + let(:user) { create(:user) } + + before do + login_as(user) + visit checkout_path + end + + describe "purchasing" do + context "takes us to the Payment Method" do + before do + split_fill_out_details + split_fill_out_billing_address + end + + context "selecting a pick-up shipping method and submiting the form" do + before do + choose free_shipping.name + end + + it "redirects the user to the Payment Method step" do + fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" + click_button "Next - Payment method" + expect(page).to have_current_path("/checkout/payment") + end + end + + context "selecting a delivery shipping method and submiting the form" do + + before do + choose shipping_with_fee.name + uncheck "ship_address_same_as_billing" + end + + it "redirects the user to the Payment Method step" do + split_fill_out_shipping_address + fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" + click_button "Next - Payment method" + expect(page).to have_current_path("/checkout/payment") + end + end + end + end + end + context "when I have an out of stock product in my cart" do before do variant.on_demand = false From 12d1e45e06d20957024405dc800fa8184d366c9d Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 6 Jan 2022 10:24:34 +0000 Subject: [PATCH 04/10] Fixes rubocop issues --- spec/system/consumer/split_checkout_spec.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 9aa6a42acf..fb439dd5df 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -2,10 +2,9 @@ require "system_helper" -include SplitCheckoutRequestsHelper - describe "As a consumer, I want to checkout my order", js: true do include ShopWorkflow + include SplitCheckoutRequestsHelper let!(:zone) { create(:zone_with_member) } let(:supplier) { create(:supplier_enterprise) } @@ -87,7 +86,7 @@ describe "As a consumer, I want to checkout my order", js: true do expect(page).to have_current_path("/checkout/payment") end end - + describe 'login in as user' do let(:user) { create(:user) } @@ -95,7 +94,7 @@ describe "As a consumer, I want to checkout my order", js: true do login_as(user) visit checkout_path end - + describe "purchasing" do context "takes us to the Payment Method" do before do @@ -107,22 +106,21 @@ describe "As a consumer, I want to checkout my order", js: true do before do choose free_shipping.name end - - it "redirects the user to the Payment Method step" do - fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" + + it "redirects the user to the Payment Method step" do + fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" click_button "Next - Payment method" - expect(page).to have_current_path("/checkout/payment") + expect(page).to have_current_path("/checkout/payment") end end context "selecting a delivery shipping method and submiting the form" do - before do choose shipping_with_fee.name uncheck "ship_address_same_as_billing" end - it "redirects the user to the Payment Method step" do + it "redirects the user to the Payment Method step" do split_fill_out_shipping_address fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" click_button "Next - Payment method" From 9149306fc13afc241caea46b01d2e67421a8f9ae Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 7 Jan 2022 12:55:09 +0000 Subject: [PATCH 05/10] Moves(up)/renames SplitCheckoutHelper --- .../split_checkout_request_helper.rb => split_checkout_helper.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/support/{request/split_checkout_request_helper.rb => split_checkout_helper.rb} (100%) diff --git a/spec/support/request/split_checkout_request_helper.rb b/spec/support/split_checkout_helper.rb similarity index 100% rename from spec/support/request/split_checkout_request_helper.rb rename to spec/support/split_checkout_helper.rb From ebbc028dda632069f23860ea0e76d6cd8d4b13b2 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 7 Jan 2022 12:56:15 +0000 Subject: [PATCH 06/10] Removes split_ prefix from helper --- spec/support/split_checkout_helper.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/support/split_checkout_helper.rb b/spec/support/split_checkout_helper.rb index 8585d03d5a..c012dc6728 100644 --- a/spec/support/split_checkout_helper.rb +++ b/spec/support/split_checkout_helper.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true module SplitCheckoutRequestsHelper - def have_split_checkout_details + def have_checkout_details have_content "Your details" end - def split_checkout_as_guest + def checkout_as_guest click_button "Checkout as guest" end - def split_place_order + def place_order find("button", text: "Complete order").click end - def split_fill_out_details + def fill_out_details # Section: Your Details within(:xpath, './/div[@class="checkout-substep"][1]') do fill_in "First Name", with: "Will" @@ -23,7 +23,7 @@ module SplitCheckoutRequestsHelper end end - def split_fill_out_billing_address + def fill_out_billing_address # Section: Your Billing Address within(:xpath, './/div[@class="checkout-substep"][2]') do fill_in "Address", with: "Rue de la Vie, 77" @@ -34,7 +34,7 @@ module SplitCheckoutRequestsHelper end end - def split_fill_out_shipping_address + def fill_out_shipping_address # Section: Delivery Address within(:xpath, './/div[@class="checkout-substep"][3]') do fill_in "Address", with: "Rue de la Vie, 66" From 2df841f63799c24a2b54815a6d202c2f1417503f Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 7 Jan 2022 13:03:44 +0000 Subject: [PATCH 07/10] Renames module - removes 'request' naming --- spec/support/split_checkout_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/split_checkout_helper.rb b/spec/support/split_checkout_helper.rb index c012dc6728..1fb8a1fcec 100644 --- a/spec/support/split_checkout_helper.rb +++ b/spec/support/split_checkout_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module SplitCheckoutRequestsHelper +module SplitCheckoutHelper def have_checkout_details have_content "Your details" end From e2c5c08c1e54efef78723014524e95c56aacb3b7 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 7 Jan 2022 13:06:28 +0000 Subject: [PATCH 08/10] Updates the spec to reflect the changes in the helper --- spec/system/consumer/split_checkout_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index fb439dd5df..728bfde667 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -4,7 +4,7 @@ require "system_helper" describe "As a consumer, I want to checkout my order", js: true do include ShopWorkflow - include SplitCheckoutRequestsHelper + include SplitCheckoutHelper let!(:zone) { create(:zone_with_member) } let(:supplier) { create(:supplier_enterprise) } @@ -98,8 +98,8 @@ describe "As a consumer, I want to checkout my order", js: true do describe "purchasing" do context "takes us to the Payment Method" do before do - split_fill_out_details - split_fill_out_billing_address + fill_out_details + fill_out_billing_address end context "selecting a pick-up shipping method and submiting the form" do @@ -121,7 +121,7 @@ describe "As a consumer, I want to checkout my order", js: true do end it "redirects the user to the Payment Method step" do - split_fill_out_shipping_address + fill_out_shipping_address fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" click_button "Next - Payment method" expect(page).to have_current_path("/checkout/payment") From 4276be11327aada0273bacdb105c693427631cb1 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 7 Jan 2022 13:11:27 +0000 Subject: [PATCH 09/10] Simplifies/re-writes 'before do' block --- spec/system/consumer/split_checkout_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 728bfde667..526b9bf80c 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -133,9 +133,7 @@ describe "As a consumer, I want to checkout my order", js: true do context "when I have an out of stock product in my cart" do before do - variant.on_demand = false - variant.on_hand = 0 - variant.save! + variant.update!(on_demand: false, on_hand: 0) end it "returns me to the cart with an error message" do From 0af025d948395692cb3e6a29a5ceccdbdc202720 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sat, 8 Jan 2022 17:59:04 +0000 Subject: [PATCH 10/10] Re-writes test structure, descrive vs. context --- spec/system/consumer/split_checkout_spec.rb | 52 ++++++++++----------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 526b9bf80c..37c0bb1c81 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -51,7 +51,7 @@ describe "As a consumer, I want to checkout my order", js: true do distributor.shipping_methods << shipping_with_fee end - context "guest checkout" do + context "as a guest user" do before do visit checkout_path end @@ -87,7 +87,7 @@ describe "As a consumer, I want to checkout my order", js: true do end end - describe 'login in as user' do + context "as a logged in user" do let(:user) { create(:user) } before do @@ -95,37 +95,35 @@ describe "As a consumer, I want to checkout my order", js: true do visit checkout_path end - describe "purchasing" do - context "takes us to the Payment Method" do + 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 before do - fill_out_details - fill_out_billing_address + choose free_shipping.name end - context "selecting a pick-up shipping method and submiting the form" do - before do - choose free_shipping.name - end + it "redirects the user to the Payment Method step" do + fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" + click_button "Next - Payment method" + expect(page).to have_current_path("/checkout/payment") + end + end - it "redirects the user to the Payment Method step" do - fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" - click_button "Next - Payment method" - expect(page).to have_current_path("/checkout/payment") - end + describe "selecting a delivery shipping method and submiting the form" do + before do + choose shipping_with_fee.name + uncheck "ship_address_same_as_billing" end - context "selecting a delivery shipping method and submiting the form" do - before do - choose shipping_with_fee.name - uncheck "ship_address_same_as_billing" - end - - it "redirects the user to the Payment Method step" do - fill_out_shipping_address - fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" - click_button "Next - Payment method" - expect(page).to have_current_path("/checkout/payment") - end + it "redirects the user to the Payment Method step" do + fill_out_shipping_address + fill_in 'Any comments or special instructions?', with: "SpEcIaL NoTeS" + click_button "Next - Payment method" + expect(page).to have_current_path("/checkout/payment") end end end