2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-29 02:25:02 -06:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe GroupShowSerializer do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:group) { Fabricate(:group) }
|
2017-07-27 03:51:25 -05:00
|
|
|
|
2016-11-29 02:25:02 -06:00
|
|
|
context 'admin user' do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:user) { Fabricate(:admin) }
|
|
|
|
fab!(:group) { Fabricate(:group, users: [user]) }
|
2016-11-29 02:25:02 -06:00
|
|
|
|
|
|
|
it 'should return the right attributes' do
|
|
|
|
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
|
|
|
|
|
2020-07-28 11:11:15 -05:00
|
|
|
expect(json[:group_show][:is_group_owner]).to eq(false)
|
2016-11-29 02:25:02 -06:00
|
|
|
expect(json[:group_show][:is_group_user]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'group owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
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 03:51:25 -05:00
|
|
|
|
|
|
|
describe '#mentionable' do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:group) { Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:everyone]) }
|
2017-07-27 03:51:25 -05: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
|
2016-11-29 02:25:02 -06:00
|
|
|
end
|