diff options
Diffstat (limited to 'spec/serializers/group_link')
5 files changed, 112 insertions, 0 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 new file mode 100644 index 00000000000..15bcbbcb1d6 --- /dev/null +++ b/spec/serializers/group_link/group_group_link_entity_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GroupLink::GroupGroupLinkEntity do + include_context 'group_group_link' + + let_it_be(:current_user) { create(:user) } + let(:entity) { described_class.new(group_group_link) } + + before do + allow(entity).to receive(:current_user).and_return(current_user) + end + + it 'matches json schema' do + expect(entity.to_json).to match_schema('group_link/group_group_link') + 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 + + expect(json[:can_update]).to be true + expect(json[:can_remove]).to be true + end + end +end diff --git a/spec/serializers/group_link/group_group_link_serializer_spec.rb b/spec/serializers/group_link/group_group_link_serializer_spec.rb new file mode 100644 index 00000000000..a4ca32dae7b --- /dev/null +++ b/spec/serializers/group_link/group_group_link_serializer_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GroupLink::GroupGroupLinkSerializer do + include_context 'group_group_link' + + subject(:json) { described_class.new.represent(shared_group.shared_with_group_links).to_json } + + it 'matches json schema' do + expect(json).to match_schema('group_link/group_group_links') + end +end diff --git a/spec/serializers/group_link/group_link_entity_spec.rb b/spec/serializers/group_link/group_link_entity_spec.rb new file mode 100644 index 00000000000..941445feaa2 --- /dev/null +++ b/spec/serializers/group_link/group_link_entity_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GroupLink::GroupLinkEntity do + include_context 'group_group_link' + + let(:entity) { described_class.new(group_group_link) } + let(:entity_hash) { entity.as_json } + + it 'matches json schema' do + expect(entity.to_json).to match_schema('group_link/group_link') + end + + it 'correctly exposes `valid_roles`' do + expect(entity_hash[:valid_roles]).to include(Gitlab::Access.options_with_owner) + end + + it 'correctly exposes `shared_with_group.avatar_url`' do + avatar_url = 'https://gitlab.com/uploads/-/system/group/avatar/24/foobar.png?width=40' + allow(shared_with_group).to receive(:avatar_url).with(only_path: false, size: Member::AVATAR_SIZE).and_return(avatar_url) + + expect(entity_hash[:shared_with_group][:avatar_url]).to match(avatar_url) + end +end diff --git a/spec/serializers/group_link/project_group_link_entity_spec.rb b/spec/serializers/group_link/project_group_link_entity_spec.rb new file mode 100644 index 00000000000..0bb3d06933b --- /dev/null +++ b/spec/serializers/group_link/project_group_link_entity_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GroupLink::ProjectGroupLinkEntity do + let_it_be(:current_user) { create(:user) } + let_it_be(:project_group_link) { create(:project_group_link) } + let(:entity) { described_class.new(project_group_link) } + + before do + allow(entity).to receive(:current_user).and_return(current_user) + end + + it 'matches json schema' do + expect(entity.to_json).to match_schema('group_link/project_group_link') + end + + context 'when current user has `admin_project_member` permissions' do + before do + allow(entity).to receive(:can?).with(current_user, :admin_project_member, project_group_link.project).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 +end diff --git a/spec/serializers/group_link/project_group_link_serializer_spec.rb b/spec/serializers/group_link/project_group_link_serializer_spec.rb new file mode 100644 index 00000000000..ecd5d4d70e4 --- /dev/null +++ b/spec/serializers/group_link/project_group_link_serializer_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GroupLink::ProjectGroupLinkSerializer do + let_it_be(:project_group_links) { create_list(:project_group_link, 1) } + + subject(:json) { described_class.new.represent(project_group_links).to_json } + + it 'matches json schema' do + expect(json).to match_schema('group_link/project_group_links') + end +end |