diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb')
-rw-r--r-- | spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb b/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb new file mode 100644 index 00000000000..f74f9186743 --- /dev/null +++ b/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::AlertManagement::HttpIntegration::Destroy do + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { create(:project) } + let(:integration) { create(:alert_management_http_integration, project: project) } + let(:args) { { id: GitlabSchema.id_from_object(integration) } } + + specify { expect(described_class).to require_graphql_authorizations(:admin_operations) } + + describe '#resolve' do + subject(:resolve) { mutation_for(project, current_user).resolve(args) } + + context 'user has access to project' do + before do + project.add_maintainer(current_user) + end + + context 'when HttpIntegrations::DestroyService responds with success' do + it 'returns the integration with no errors' do + expect(resolve).to eq( + integration: integration, + errors: [] + ) + end + end + + context 'when HttpIntegrations::DestroyService responds with an error' do + before do + allow_any_instance_of(::AlertManagement::HttpIntegrations::DestroyService) + .to receive(:execute) + .and_return(ServiceResponse.error(payload: { integration: nil }, message: 'An error has occurred')) + end + + it 'returns errors' do + expect(resolve).to eq( + integration: nil, + errors: ['An error has occurred'] + ) + end + end + end + + context 'when resource is not accessible to the user' do + it 'raises an error if the resource is not accessible to the user' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + end + + private + + def mutation_for(project, user) + described_class.new(object: project, context: { current_user: user }, field: nil) + end +end |