diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-17 15:09:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-17 15:09:19 +0300 |
commit | 359f9c9929177d6ea6c54c19b23959145f177a78 (patch) | |
tree | 8877699926eedf057f7663f431b77a0cfa6739a1 /spec/graphql | |
parent | 5f4d643165631ea503b8aa1e9abbecc8341c39c6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/mutations/release_asset_links/delete_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/graphql/mutations/release_asset_links/delete_spec.rb b/spec/graphql/mutations/release_asset_links/delete_spec.rb new file mode 100644 index 00000000000..15d320b58ee --- /dev/null +++ b/spec/graphql/mutations/release_asset_links/delete_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::ReleaseAssetLinks::Delete do + include GraphqlHelpers + + let_it_be(:project) { create(:project, :private, :repository) } + let_it_be_with_reload(:release) { create(:release, project: project) } + let_it_be(:developer) { create(:user).tap { |u| project.add_developer(u) } } + let_it_be(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } } + let_it_be_with_reload(:release_link) { create(:release_link, release: release) } + + let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) } + let(:mutation_arguments) { { id: release_link.to_global_id } } + + describe '#resolve' do + subject(:resolve) do + mutation.resolve(**mutation_arguments) + end + + let(:deleted_link) { subject[:link] } + + context 'when the current user has access to delete the link' do + let(:current_user) { maintainer } + + it 'deletes the link and returns it', :aggregate_failures do + expect(deleted_link).to eq(release_link) + + expect(release.links).to be_empty + end + + context "when the link doesn't exist" do + let(:mutation_arguments) { super().merge(id: "gid://gitlab/Releases::Link/#{non_existing_record_id}") } + + it 'raises an error' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + + context "when the provided ID is invalid" do + let(:mutation_arguments) { super().merge(id: 'not-a-valid-gid') } + + it 'raises an error' do + expect { subject }.to raise_error(::GraphQL::CoercionError) + end + end + end + + context 'when the current user does not have access to delete the link' do + let(:current_user) { developer } + + it 'raises an error' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + end +end |