fix existing tests

This commit is contained in:
Mohamed ABDELLANI
2023-08-23 11:02:48 +01:00
parent c689e2da8b
commit f9e6f8bfa5
4 changed files with 37 additions and 18 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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