2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe GroupShowSerializer do
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:user)
|
|
|
|
fab!(:group)
|
2017-07-27 04:51:25 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with an admin user" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user) { Fabricate(:admin) }
|
|
|
|
fab!(:group) { Fabricate(:group, users: [user]) }
|
2016-11-29 03:25:02 -05:00
|
|
|
|
|
|
|
it "should return the right attributes" do
|
|
|
|
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
|
|
|
|
|
2020-08-18 12:30:08 -04:00
|
|
|
expect(json[:group_show][:is_group_owner]).to eq(nil)
|
2016-11-29 03:25:02 -05:00
|
|
|
expect(json[:group_show][:is_group_user]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with a group owner" do
|
2016-11-29 03:25:02 -05:00
|
|
|
before { group.add_owner(user) }
|
|
|
|
|
|
|
|
it "should return the right attributes" do
|
|
|
|
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
|
|
|
|
|
|
|
|
expect(json[:group_show][:is_group_owner]).to eq(true)
|
|
|
|
expect(json[:group_show][:is_group_user]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
2017-07-27 04:51:25 -04:00
|
|
|
|
|
|
|
describe "#mentionable" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:group) { Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:everyone]) }
|
2017-07-27 04:51:25 -04:00
|
|
|
|
|
|
|
it "should return the right value" do
|
|
|
|
json = GroupShowSerializer.new(group, scope: Guardian.new).as_json
|
|
|
|
|
|
|
|
expect(json[:group_show][:mentionable]).to eq(nil)
|
|
|
|
|
|
|
|
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
|
|
|
|
|
|
|
|
expect(json[:group_show][:mentionable]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
2020-09-16 14:58:52 -04:00
|
|
|
|
|
|
|
describe "#automatic_membership_email_domains" do
|
|
|
|
fab!(:group) { Fabricate(:group, automatic_membership_email_domains: "ilovediscourse.com") }
|
|
|
|
let(:admin_guardian) { Guardian.new(Fabricate(:admin)) }
|
|
|
|
|
|
|
|
it "should include email domains for admin" do
|
|
|
|
subject =
|
|
|
|
described_class.new(group, scope: admin_guardian, root: false, owner_group_ids: [group.id])
|
|
|
|
expect(subject.as_json[:automatic_membership_email_domains]).to eq("ilovediscourse.com")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not include email domains for other users" do
|
|
|
|
subject =
|
|
|
|
described_class.new(group, scope: Guardian.new, root: false, owner_group_ids: [group.id])
|
|
|
|
expect(subject.as_json[:automatic_membership_email_domains]).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "admin only fields" do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:serializer) { described_class.new(group, scope: guardian, root: false) }
|
|
|
|
|
2020-09-16 14:58:52 -04:00
|
|
|
fab!(:group) { Fabricate(:group, email_username: "foo@bar.com", email_password: "pa$$w0rd") }
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "for a user" do
|
2020-09-16 14:58:52 -04:00
|
|
|
let(:guardian) { Guardian.new(Fabricate(:user)) }
|
|
|
|
|
|
|
|
it "are not visible" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.as_json[:email_username]).to be_nil
|
|
|
|
expect(serializer.as_json[:email_password]).to be_nil
|
2020-09-16 14:58:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "for an admin" do
|
2020-09-16 14:58:52 -04:00
|
|
|
let(:guardian) { Guardian.new(Fabricate(:admin)) }
|
|
|
|
|
|
|
|
it "are visible" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.as_json[:email_username]).to eq("foo@bar.com")
|
|
|
|
expect(serializer.as_json[:email_password]).to eq("pa$$w0rd")
|
|
|
|
expect(serializer.as_json[:message_count]).to eq(0)
|
2020-09-16 14:58:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "default notification settings" do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:serializer) { described_class.new(group, scope: guardian, root: false) }
|
|
|
|
|
2020-09-16 14:58:52 -04:00
|
|
|
let(:category1) { Fabricate(:category) }
|
|
|
|
let(:category2) { Fabricate(:category) }
|
|
|
|
let(:tag1) { Fabricate(:tag) }
|
|
|
|
let(:tag2) { Fabricate(:tag) }
|
|
|
|
|
|
|
|
before do
|
2020-09-16 16:02:28 -04:00
|
|
|
SiteSetting.tagging_enabled = true
|
|
|
|
|
2020-09-16 14:58:52 -04:00
|
|
|
GroupCategoryNotificationDefault.create!(
|
|
|
|
group: group,
|
|
|
|
category: category1,
|
|
|
|
notification_level: GroupCategoryNotificationDefault.notification_levels[:watching],
|
|
|
|
)
|
|
|
|
GroupCategoryNotificationDefault.create!(
|
|
|
|
group: group,
|
|
|
|
category: category2,
|
|
|
|
notification_level: GroupCategoryNotificationDefault.notification_levels[:tracking],
|
|
|
|
)
|
|
|
|
GroupTagNotificationDefault.create!(
|
|
|
|
group: group,
|
|
|
|
tag: tag1,
|
|
|
|
notification_level: GroupTagNotificationDefault.notification_levels[:watching],
|
|
|
|
)
|
|
|
|
GroupTagNotificationDefault.create!(
|
|
|
|
group: group,
|
|
|
|
tag: tag2,
|
|
|
|
notification_level: GroupTagNotificationDefault.notification_levels[:tracking],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "for a user" do
|
2020-09-16 14:58:52 -04:00
|
|
|
let(:guardian) { Guardian.new(Fabricate(:user)) }
|
|
|
|
|
|
|
|
it "are not visible" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(
|
|
|
|
serializer.as_json.keys.select { |k| k.to_s.ends_with?("_category_ids") },
|
|
|
|
).to be_empty
|
|
|
|
expect(serializer.as_json.keys.select { |k| k.to_s.ends_with?("_tags") }).to be_empty
|
2020-09-16 14:58:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "for admin" do
|
2020-09-16 14:58:52 -04:00
|
|
|
let(:guardian) { Guardian.new(Fabricate(:admin)) }
|
|
|
|
|
|
|
|
it "are correct" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(serializer.as_json[:watching_category_ids]).to eq([category1.id])
|
|
|
|
expect(serializer.as_json[:tracking_category_ids]).to eq([category2.id])
|
|
|
|
expect(serializer.as_json[:watching_first_post_category_ids]).to eq([])
|
|
|
|
expect(serializer.as_json[:regular_category_ids]).to eq([])
|
|
|
|
expect(serializer.as_json[:muted_category_ids]).to eq([])
|
|
|
|
|
|
|
|
expect(serializer.as_json[:watching_tags]).to eq([tag1.name])
|
|
|
|
expect(serializer.as_json[:tracking_tags]).to eq([tag2.name])
|
|
|
|
expect(serializer.as_json[:watching_first_post_tags]).to eq([])
|
|
|
|
expect(serializer.as_json[:regular_tags]).to eq([])
|
|
|
|
expect(serializer.as_json[:muted_tags]).to eq([])
|
2020-09-16 14:58:52 -04:00
|
|
|
end
|
2020-09-16 16:02:28 -04:00
|
|
|
|
|
|
|
it "doesn't include tag fields if tags are disabled" do
|
|
|
|
SiteSetting.tagging_enabled = false
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(
|
|
|
|
serializer.as_json.keys.select { |k| k.to_s.ends_with?("_category_ids") }.length,
|
|
|
|
).to eq(5)
|
|
|
|
expect(serializer.as_json.keys.select { |k| k.to_s.ends_with?("_tags") }).to be_empty
|
2020-09-16 16:02:28 -04:00
|
|
|
end
|
2020-09-16 14:58:52 -04:00
|
|
|
end
|
|
|
|
end
|
2016-11-29 03:25:02 -05:00
|
|
|
end
|