summaryrefslogtreecommitdiff
path: root/spec/graphql
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-15 15:08:04 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-15 15:08:04 +0000
commitc4c1fc5fe7c756fc6f8f79eb1624b1bbe4fe2d69 (patch)
tree8c95e39fc4956cdd9178c46ea85cbeeeac3bc360 /spec/graphql
parent927df95cc4453bdacbc59960df32008b02c4e28a (diff)
downloadgitlab-ce-c4c1fc5fe7c756fc6f8f79eb1624b1bbe4fe2d69.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql')
-rw-r--r--spec/graphql/mutations/alert_management/create_alert_issue_spec.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb b/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb
new file mode 100644
index 00000000000..1e51767cf0e
--- /dev/null
+++ b/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Mutations::AlertManagement::CreateAlertIssue do
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:alert) { create(:alert_management_alert, project: project, status: 'triggered') }
+ let(:args) { { project_path: project.full_path, iid: alert.iid } }
+
+ specify { expect(described_class).to require_graphql_authorizations(:update_alert_management_alert) }
+
+ describe '#resolve' do
+ subject(:resolve) { mutation_for(project, current_user).resolve(args) }
+
+ context 'user has access to project' do
+ before do
+ project.add_developer(current_user)
+ end
+
+ context 'when CreateAlertIssueService responds with success' do
+ it 'returns the issue with no errors' do
+ expect(resolve).to eq(
+ alert: alert.reload,
+ issue: Issue.last!,
+ errors: []
+ )
+ end
+ end
+
+ context 'when CreateAlertIssue responds with an error' do
+ before do
+ allow_any_instance_of(::AlertManagement::CreateAlertIssueService)
+ .to receive(:execute)
+ .and_return(ServiceResponse.error(payload: { issue: nil }, message: 'An issue already exists'))
+ end
+
+ it 'returns errors' do
+ expect(resolve).to eq(
+ alert: alert,
+ issue: nil,
+ errors: ['An issue already exists']
+ )
+ 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