summaryrefslogtreecommitdiff
path: root/spec/serializers/group_link/group_group_link_entity_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/serializers/group_link/group_group_link_entity_spec.rb')
-rw-r--r--spec/serializers/group_link/group_group_link_entity_spec.rb50
1 files changed, 45 insertions, 5 deletions
diff --git a/spec/serializers/group_link/group_group_link_entity_spec.rb b/spec/serializers/group_link/group_group_link_entity_spec.rb
index 2821c433784..502cdc5c048 100644
--- a/spec/serializers/group_link/group_group_link_entity_spec.rb
+++ b/spec/serializers/group_link/group_group_link_entity_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe GroupLink::GroupGroupLinkEntity do
let_it_be(:current_user) { create(:user) }
- let(:entity) { described_class.new(group_group_link) }
+ let(:entity) { described_class.new(group_group_link, { current_user: current_user, source: shared_group }) }
before do
allow(entity).to receive(:current_user).and_return(current_user)
@@ -17,16 +17,56 @@ RSpec.describe GroupLink::GroupGroupLinkEntity do
expect(entity.to_json).to match_schema('group_link/group_group_link')
end
+ context 'source' do
+ it 'exposes `source`' do
+ expect(entity.as_json[:source]).to include(
+ id: shared_group.id,
+ full_name: shared_group.full_name,
+ web_url: shared_group.web_url
+ )
+ end
+ end
+
+ context 'is_direct_member' do
+ it 'exposes `is_direct_member` as true for corresponding group' do
+ expect(entity.as_json[:is_direct_member]).to be true
+ end
+
+ it 'exposes `is_direct_member` as false for other source' do
+ entity = described_class.new(group_group_link, { current_user: current_user, source: shared_with_group })
+ expect(entity.as_json[:is_direct_member]).to be false
+ end
+ end
+
context 'when current user has `:admin_group_member` permissions' do
before do
allow(entity).to receive(:can?).with(current_user, :admin_group_member, shared_group).and_return(true)
end
- it 'exposes `can_update` and `can_remove` as `true`' do
- json = entity.as_json
+ context 'when direct_member? is true' do
+ before do
+ allow(entity).to receive(:direct_member?).and_return(true)
+ end
+
+ it 'exposes `can_update` and `can_remove` as `true`' do
+ json = entity.as_json
+
+ expect(json[:can_update]).to be true
+ expect(json[:can_remove]).to be true
+ end
+ end
+
+ context 'when direct_member? is false' do
+ before do
+ allow(entity).to receive(:direct_member?).and_return(false)
+ end
+
+ it 'exposes `can_update` and `can_remove` as `true`' do
+ json = entity.as_json
- expect(json[:can_update]).to be true
- expect(json[:can_remove]).to be true
+ expect(json[:can_update]).to be false
+ expect(json[:can_remove]).to be false
+ end
end
end
end