diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /spec/graphql/mutations/custom_emoji/destroy_spec.rb | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'spec/graphql/mutations/custom_emoji/destroy_spec.rb')
-rw-r--r-- | spec/graphql/mutations/custom_emoji/destroy_spec.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/graphql/mutations/custom_emoji/destroy_spec.rb b/spec/graphql/mutations/custom_emoji/destroy_spec.rb new file mode 100644 index 00000000000..4667812cc80 --- /dev/null +++ b/spec/graphql/mutations/custom_emoji/destroy_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::CustomEmoji::Destroy do + let_it_be(:group) { create(:group) } + let_it_be(:user) { create(:user) } + let_it_be_with_reload(:custom_emoji) { create(:custom_emoji, group: group) } + + let(:args) { { id: custom_emoji.to_global_id } } + let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + + context 'field tests' do + subject { described_class } + + it { is_expected.to have_graphql_arguments(:id) } + it { is_expected.to have_graphql_field(:custom_emoji) } + end + + shared_examples 'does not delete custom emoji' do + it 'raises exception' do + expect { subject } + .to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + + shared_examples 'deletes custom emoji' do + it 'returns deleted custom emoji' do + result = subject + + expect(result[:custom_emoji][:name]).to eq(custom_emoji.name) + end + end + + describe '#resolve' do + subject { mutation.resolve(**args) } + + context 'when the user' do + context 'has no permissions' do + it_behaves_like 'does not delete custom emoji' + end + + context 'when the user is developer and not the owner of custom emoji' do + before do + group.add_developer(user) + end + + it_behaves_like 'does not delete custom emoji' + end + end + + context 'when user' do + context 'is maintainer' do + before do + group.add_maintainer(user) + end + + it_behaves_like 'deletes custom emoji' + end + + context 'is owner' do + before do + group.add_owner(user) + end + + it_behaves_like 'deletes custom emoji' + end + + context 'is developer and creator of the emoji' do + before do + group.add_developer(user) + custom_emoji.update_attribute(:creator, user) + end + + it_behaves_like 'deletes custom emoji' + end + end + end +end |