From f9e6f8bfa5be4432d246f2739bc7681783697d9b Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Wed, 23 Aug 2023 11:02:48 +0100 Subject: [PATCH] fix existing tests --- .../terms_and_conditions_helper_spec.rb | 29 ++++++++++++++----- spec/models/terms_of_service_file_spec.rb | 4 +-- .../terms_of_service_files_spec.rb | 3 +- spec/system/consumer/split_checkout_spec.rb | 19 +++++++----- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/spec/helpers/terms_and_conditions_helper_spec.rb b/spec/helpers/terms_and_conditions_helper_spec.rb index 4121725d2a..320426ea51 100644 --- a/spec/helpers/terms_and_conditions_helper_spec.rb +++ b/spec/helpers/terms_and_conditions_helper_spec.rb @@ -4,14 +4,29 @@ require 'spec_helper' describe TermsAndConditionsHelper, type: :helper do describe "#platform_terms_required?" do - it "returns true" do - expect(Spree::Config).to receive(:shoppers_require_tos).and_return(true) - expect(helper.platform_terms_required?).to eq true - end + context 'when ToS file is present' do + before do + allow(TermsOfServiceFile).to receive(:exists?).and_return(true) + end + it "returns true" do + expect(Spree::Config).to receive(:shoppers_require_tos).and_return(true) + expect(helper.platform_terms_required?).to eq true + end - it "returns false" do - expect(Spree::Config).to receive(:shoppers_require_tos).and_return(false) - expect(helper.platform_terms_required?).to eq false + it "returns false" do + expect(Spree::Config).to receive(:shoppers_require_tos).and_return(false) + expect(helper.platform_terms_required?).to eq false + end + end + context 'when ToS file is not present' do + before do + allow(TermsOfServiceFile).to receive(:exists?).and_return(false) + end + + it "returns false" do + expect(Spree::Config).not_to receive(:shoppers_require_tos) + expect(helper.platform_terms_required?).to eq false + end end end end diff --git a/spec/models/terms_of_service_file_spec.rb b/spec/models/terms_of_service_file_spec.rb index ca30c64546..21718a0e9b 100644 --- a/spec/models/terms_of_service_file_spec.rb +++ b/spec/models/terms_of_service_file_spec.rb @@ -24,8 +24,8 @@ describe TermsOfServiceFile do describe ".current_url" do let(:subject) { TermsOfServiceFile.current_url } - it "points to the old default" do - expect(subject).to eq "/Terms-of-service.pdf" + it "points to nil if not ToS file is present" do + expect(subject).to eq nil end it "points to a stored file" do diff --git a/spec/system/admin/configuration/terms_of_service_files_spec.rb b/spec/system/admin/configuration/terms_of_service_files_spec.rb index fc3f0c6185..f917c54dbd 100644 --- a/spec/system/admin/configuration/terms_of_service_files_spec.rb +++ b/spec/system/admin/configuration/terms_of_service_files_spec.rb @@ -15,8 +15,6 @@ describe "Terms of Service files" do click_link "Terms of Service" expect(page).to have_content "No terms of services have been uploaded yet." - expect(page).to have_content "your old Terms of service" - expect(page).to have_link "Terms of service", href: "/Terms-of-service.pdf" end it "can be uploaded" do @@ -25,6 +23,7 @@ describe "Terms of Service files" do click_button "Create Terms of service file" expect(page).to have_link "Terms of Service" + expect(page).to have_link "Delete file" end it "provides Rails' standard action for a new file" do diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index d648476e20..00d6608b6f 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -1051,13 +1051,16 @@ describe "As a consumer, I want to checkout my order" do context "when the platform's terms of service have to be accepted" do before do allow(Spree::Config).to receive(:shoppers_require_tos).and_return(true) - allow(Spree::Config).to receive(:footer_tos_url).and_return(tos_url) + end + + let!(:tos) do + TermsOfServiceFile.create!(attachment: system_terms) end it "shows the terms which need to be accepted" do visit checkout_step_path(:summary) - expect(page).to have_link "Terms of service", href: tos_url + expect(page).to have_link("Terms of service", href: /Terms-of-service.pdf/, count: 2) expect(find_link("Terms of service")[:target]).to eq "_blank" expect(page).to have_field "order_accept_terms", checked: false end @@ -1065,9 +1068,8 @@ describe "As a consumer, I want to checkout my order" do context "when the terms have been accepted in the past" do context "with a dedicated ToS file" do before do - TermsOfServiceFile.create!( - attachment: system_terms, - updated_at: 1.day.ago, + tos.update!( + updated_at: 1.day.ago ) customer.update(terms_and_conditions_accepted_at: Time.zone.now) end @@ -1102,14 +1104,17 @@ describe "As a consumer, I want to checkout my order" do order.distributor.update!(terms_and_conditions: shop_terms) allow(Spree::Config).to receive(:shoppers_require_tos).and_return(true) - allow(Spree::Config).to receive(:footer_tos_url).and_return(tos_url) + end + + let!(:tos) do + TermsOfServiceFile.create!(attachment: system_terms) end it "shows links to both terms and all need accepting" do visit checkout_step_path(:summary) expect(page).to have_link "Terms and Conditions", href: /#{shop_terms_path.basename}$/ - expect(page).to have_link "Terms of service", href: tos_url + expect(page).to have_link("Terms of service", href: /Terms-of-service.pdf/, count: 2) expect(page).to have_field "order_accept_terms", checked: false end end