2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe BasicGroupSerializer do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:serializer) { described_class.new(group, scope: guardian, root: false) }
|
|
|
|
|
2018-04-17 03:56:55 -04:00
|
|
|
let(:guardian) { Guardian.new }
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:group)
|
2017-05-05 02:34:47 -04:00
|
|
|
|
|
|
|
describe "#display_name" do
|
|
|
|
describe "automatic group" do
|
|
|
|
let(:group) { Group.find(1) }
|
|
|
|
|
|
|
|
it "should include the display name" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.display_name).to eq(I18n.t("groups.default_names.admins"))
|
2017-05-05 02:34:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "normal group" do
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:group)
|
2017-05-05 02:34:47 -04:00
|
|
|
|
|
|
|
it "should not include the display name" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.display_name).to eq(nil)
|
2017-05-05 02:34:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-17 03:56:55 -04:00
|
|
|
|
|
|
|
describe "#bio_raw" do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:serializer) do
|
2018-05-17 06:10:17 -04:00
|
|
|
described_class.new(group, scope: guardian, root: false, owner_group_ids: [group.id])
|
2018-04-17 03:56:55 -04:00
|
|
|
end
|
|
|
|
|
2023-06-21 10:00:19 -04:00
|
|
|
fab!(:group) { Fabricate(:group, bio_raw: "testing :slightly_smiling_face:") }
|
|
|
|
|
2018-04-17 03:56:55 -04:00
|
|
|
describe "group owner" do
|
|
|
|
it "should include bio_raw" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.as_json[:bio_raw]).to eq("testing :slightly_smiling_face:")
|
|
|
|
expect(serializer.as_json[:bio_excerpt]).to start_with("testing <img")
|
2018-05-17 06:10:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#has_messages" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:group) { Fabricate(:group, has_messages: true) }
|
2018-05-17 06:10:17 -04:00
|
|
|
|
|
|
|
describe "for a staff user" do
|
2024-01-25 01:28:26 -05:00
|
|
|
let!(:guardian) { Guardian.new(Fabricate(:moderator)) }
|
2018-05-17 06:10:17 -04:00
|
|
|
|
|
|
|
it "should be present" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.as_json[:has_messages]).to eq(true)
|
2018-05-17 06:10:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "for a group user" do
|
2024-01-25 01:28:26 -05:00
|
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
2018-05-17 06:10:17 -04:00
|
|
|
let(:guardian) { Guardian.new(user) }
|
|
|
|
|
|
|
|
before { group.add(user) }
|
|
|
|
|
|
|
|
it "should be present" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.as_json[:has_messages]).to eq(true)
|
2018-05-17 06:10:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "for a normal user" do
|
|
|
|
let(:guardian) { Guardian.new(Fabricate(:user)) }
|
|
|
|
|
|
|
|
it "should not be present" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.as_json[:has_messages]).to eq(nil)
|
2018-04-17 03:56:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-08-14 09:30:04 -04:00
|
|
|
|
|
|
|
describe "#can_see_members" do
|
|
|
|
fab!(:group) { Fabricate(:group, members_visibility_level: Group.visibility_levels[:members]) }
|
|
|
|
|
|
|
|
describe "for a group user" do
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:user)
|
2019-08-14 09:30:04 -04:00
|
|
|
let(:guardian) { Guardian.new(user) }
|
|
|
|
|
|
|
|
before { group.add(user) }
|
|
|
|
|
|
|
|
it "should be true" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.as_json[:can_see_members]).to eq(true)
|
2019-08-14 09:30:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "for a normal user" do
|
|
|
|
let(:guardian) { Guardian.new(Fabricate(:user)) }
|
|
|
|
|
|
|
|
it "should be false" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.as_json[:can_see_members]).to eq(false)
|
2019-08-14 09:30:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-05 02:34:47 -04:00
|
|
|
end
|