Don't show the banner if no ToS file uploaded

This commit is contained in:
Gaetan Craig-Riou
2023-12-01 13:28:15 +11:00
committed by Konrad
parent 17fa6b6168
commit 9609ba4268
2 changed files with 17 additions and 1 deletions

View File

@@ -7,6 +7,8 @@ module Admin
return false if Spree::Config.enterprises_require_tos == false
return false if TermsOfServiceFile.current.nil?
!accepted_tos?
end

View File

@@ -13,7 +13,11 @@ describe "/admin", type: :request do
describe "GET /admin" do
before do
allow(TermsOfServiceFile).to receive(:updated_at).and_return(2.hours.ago)
mocked_tos = double(TermsOfServiceFile, updated_at: 2.hours.ago)
allow(TermsOfServiceFile).to receive(:current).and_return(mocked_tos)
# Mock current_url so we don't have to set up a complicated TermsOfServiceFile mock
# with attachement
allow(TermsOfServiceFile).to receive(:current_url).and_return("tmp/tos.pdf")
end
it "loads the dashboard page" do
@@ -56,6 +60,16 @@ describe "/admin", type: :request do
end
end
context "when no ToS has been uploaded" do
it "doesn't show accept new ToS banner" do
allow(TermsOfServiceFile).to receive(:current).and_return(nil)
get "/admin"
expect(response.body).to_not include("Terms of Service have been updated")
end
end
context "when enterprises don't need to accept ToS" do
before do
Spree::Config.enterprises_require_tos = false