2021-05-19 01:15:24 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe AboutSerializer do
|
2021-05-19 01:15:24 -05:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "when login_required is enabled" do
|
2021-05-19 01:15:24 -05:00
|
|
|
before do
|
|
|
|
SiteSetting.login_required = true
|
|
|
|
SiteSetting.contact_url = "https://example.com/contact"
|
|
|
|
SiteSetting.contact_email = "example@foobar.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contact details are hidden from anonymous users" do
|
|
|
|
json = AboutSerializer.new(About.new(nil), scope: Guardian.new(nil), root: nil).as_json
|
|
|
|
expect(json[:contact_url]).to eq(nil)
|
|
|
|
expect(json[:contact_email]).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contact details are visible to regular users" do
|
|
|
|
json = AboutSerializer.new(About.new(user), scope: Guardian.new(user), root: nil).as_json
|
|
|
|
expect(json[:contact_url]).to eq(SiteSetting.contact_url)
|
|
|
|
expect(json[:contact_email]).to eq(SiteSetting.contact_email)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "when login_required is disabled" do
|
2021-05-19 01:15:24 -05:00
|
|
|
before do
|
|
|
|
SiteSetting.login_required = false
|
|
|
|
SiteSetting.contact_url = "https://example.com/contact"
|
|
|
|
SiteSetting.contact_email = "example@foobar.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contact details are visible to anonymous users" do
|
|
|
|
json = AboutSerializer.new(About.new(nil), scope: Guardian.new(nil), root: nil).as_json
|
|
|
|
expect(json[:contact_url]).to eq(SiteSetting.contact_url)
|
|
|
|
expect(json[:contact_email]).to eq(SiteSetting.contact_email)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contact details are visible to regular users" do
|
|
|
|
json = AboutSerializer.new(About.new(user), scope: Guardian.new(user), root: nil).as_json
|
|
|
|
expect(json[:contact_url]).to eq(SiteSetting.contact_url)
|
|
|
|
expect(json[:contact_email]).to eq(SiteSetting.contact_email)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|