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