summaryrefslogtreecommitdiff
path: root/spec/graphql/mutations/alert_management
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/graphql/mutations/alert_management
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/graphql/mutations/alert_management')
-rw-r--r--spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb2
-rw-r--r--spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb58
-rw-r--r--spec/graphql/mutations/alert_management/update_alert_status_spec.rb2
3 files changed, 60 insertions, 2 deletions
diff --git a/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb b/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb
index a025b3d344a..f8b61c5064a 100644
--- a/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb
+++ b/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Mutations::AlertManagement::Alerts::SetAssignees do
+RSpec.describe Mutations::AlertManagement::Alerts::SetAssignees do
let_it_be(:starting_assignee) { create(:user) }
let_it_be(:unassigned_user) { create(:user) }
let_it_be(:alert) { create(:alert_management_alert, assignees: [starting_assignee]) }
diff --git a/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb
new file mode 100644
index 00000000000..11ee40a4c7e
--- /dev/null
+++ b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::AlertManagement::Alerts::Todo::Create do
+ subject(:mutation) { described_class.new(object: project, context: { current_user: current_user }, field: nil) }
+
+ let_it_be(:alert) { create(:alert_management_alert) }
+ let_it_be(:project) { alert.project }
+ let(:current_user) { project.owner }
+
+ 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.resolve(args) }
+
+ context 'when user does not have permissions' do
+ let(:current_user) { nil }
+
+ specify { expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) }
+ end
+
+ context 'when project is invalid' do
+ let(:args) { { project_path: 'bunk/path', iid: alert.iid } }
+
+ specify { expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) }
+ end
+
+ context 'when alert is invalid' do
+ let(:args) { { project_path: project.full_path, iid: "-1" } }
+
+ specify { expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) }
+ end
+
+ context 'when the create service yields errors' do
+ let(:error_response) { double(error?: true, message: 'error', payload: { alert: {} }) }
+
+ before do
+ allow_next_instance_of(::AlertManagement::Alerts::Todo::CreateService) do |service|
+ allow(service).to receive(:execute).and_return(error_response)
+ end
+ end
+
+ specify { expect { resolve }.not_to change(Todo, :count) }
+ specify { expect(resolve[:errors]).to eq([error_response.message]) }
+ end
+
+ context 'with valid inputs' do
+ it 'creates a new todo' do
+ expect { resolve }.to change { Todo.where(user: current_user, action: Todo::MARKED).count }.by(1)
+ end
+
+ it { is_expected.to eq(alert: alert, todo: Todo.last, errors: []) }
+ end
+ end
+end
diff --git a/spec/graphql/mutations/alert_management/update_alert_status_spec.rb b/spec/graphql/mutations/alert_management/update_alert_status_spec.rb
index 68513c02040..a224b564de9 100644
--- a/spec/graphql/mutations/alert_management/update_alert_status_spec.rb
+++ b/spec/graphql/mutations/alert_management/update_alert_status_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe Mutations::AlertManagement::UpdateAlertStatus do
allow(alert).to receive(:save).and_return(false)
allow(alert).to receive(:errors).and_return(
- double(full_messages: %w(foo bar))
+ double(full_messages: %w(foo bar), :[] => nil)
)
expect(resolve).to eq(
alert: alert,