Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-09 06:09:01 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-09 06:09:01 +0300
commit0a9efe02885d9ad4dbdaf61746ae81daea0f575b (patch)
treeccd02a93eaaadb1c547c5f6e1d239d9276908bc6 /spec/services/alert_management
parentf44bf01f69a491d4dfca8d631b390371bd0eec7a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/alert_management')
-rw-r--r--spec/services/alert_management/alerts/update_service_spec.rb43
-rw-r--r--spec/services/alert_management/update_alert_status_service_spec.rb83
2 files changed, 38 insertions, 88 deletions
diff --git a/spec/services/alert_management/alerts/update_service_spec.rb b/spec/services/alert_management/alerts/update_service_spec.rb
index 3e312e739a4..dbd094bead3 100644
--- a/spec/services/alert_management/alerts/update_service_spec.rb
+++ b/spec/services/alert_management/alerts/update_service_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe AlertManagement::Alerts::UpdateService do
let_it_be(:user_with_permissions) { create(:user) }
let_it_be(:other_user_with_permissions) { create(:user) }
let_it_be(:user_without_permissions) { create(:user) }
- let_it_be(:alert, reload: true) { create(:alert_management_alert) }
+ let_it_be(:alert, reload: true) { create(:alert_management_alert, :triggered) }
let_it_be(:project) { alert.project }
let(:current_user) { user_with_permissions }
@@ -28,6 +28,10 @@ RSpec.describe AlertManagement::Alerts::UpdateService do
specify { expect { response }.not_to change(Note, :count) }
end
+ shared_examples 'adds a system note' do
+ specify { expect { response }.to change { alert.reload.notes.count }.by(1) }
+ end
+
shared_examples 'error response' do |message|
it_behaves_like 'does not add a todo'
it_behaves_like 'does not add a system note'
@@ -86,10 +90,6 @@ RSpec.describe AlertManagement::Alerts::UpdateService do
end
end
- shared_examples 'adds a system note' do
- specify { expect { response }.to change { alert.reload.notes.count }.by(1) }
- end
-
shared_examples 'successful assignment' do
it_behaves_like 'adds a system note'
it_behaves_like 'adds a todo'
@@ -143,5 +143,38 @@ RSpec.describe AlertManagement::Alerts::UpdateService do
it_behaves_like 'successful assignment'
end
end
+
+ context 'when a status is included' do
+ let(:params) { { status: new_status } }
+ let(:new_status) { AlertManagement::Alert::STATUSES[:acknowledged] }
+
+ it 'successfully changes the status' do
+ expect { response }.to change { alert.acknowledged? }.to(true)
+ expect(response).to be_success
+ expect(response.payload[:alert]).to eq(alert)
+ end
+
+ it_behaves_like 'adds a system note'
+
+ context 'with unknown status' do
+ let(:new_status) { -1 }
+
+ it_behaves_like 'error response', 'Invalid status'
+ end
+
+ context 'with resolving status' do
+ let(:new_status) { AlertManagement::Alert::STATUSES[:resolved] }
+
+ it 'changes the status' do
+ expect { response }.to change { alert.resolved? }.to(true)
+ end
+
+ it "resolves the current user's related todos" do
+ todo = create(:todo, :pending, target: alert, user: current_user, project: alert.project)
+
+ expect { response }.to change { todo.reload.state }.from('pending').to('done')
+ end
+ end
+ end
end
end
diff --git a/spec/services/alert_management/update_alert_status_service_spec.rb b/spec/services/alert_management/update_alert_status_service_spec.rb
deleted file mode 100644
index a3360c3e263..00000000000
--- a/spec/services/alert_management/update_alert_status_service_spec.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe AlertManagement::UpdateAlertStatusService do
- let(:project) { alert.project }
- let_it_be(:user) { build(:user) }
-
- let_it_be(:alert, reload: true) do
- create(:alert_management_alert, :triggered)
- end
-
- let(:service) { described_class.new(alert, user, new_status) }
-
- describe '#execute' do
- shared_examples 'update failure' do |error_message|
- it 'returns an error' do
- expect(response).to be_error
- expect(response.message).to eq(error_message)
- expect(response.payload[:alert]).to eq(alert)
- end
-
- it 'does not update the status' do
- expect { response }.not_to change { alert.status }
- end
- end
-
- let(:new_status) { AlertManagement::Alert::STATUSES[:acknowledged] }
- let(:can_update) { true }
-
- subject(:response) { service.execute }
-
- before do
- allow(user).to receive(:can?)
- .with(:update_alert_management_alert, project)
- .and_return(can_update)
- end
-
- it 'returns success' do
- expect(response).to be_success
- expect(response.payload[:alert]).to eq(alert)
- end
-
- it 'updates the status' do
- expect { response }.to change { alert.acknowledged? }.to(true)
- end
-
- context 'resolving status' do
- let(:new_status) { AlertManagement::Alert::STATUSES[:resolved] }
-
- it 'updates the status' do
- expect { response }.to change { alert.resolved? }.to(true)
- end
-
- context 'user has a pending todo' do
- let(:user) { create(:user) }
- let!(:todo) { create(:todo, :pending, target: alert, user: user, project: alert.project) }
-
- it 'resolves the todo' do
- expect { response }.to change { todo.reload.state }.from('pending').to('done')
- end
- end
- end
-
- context 'when user has no permissions' do
- let(:can_update) { false }
-
- include_examples 'update failure', _('You have no permissions')
- end
-
- context 'with no status' do
- let(:new_status) { nil }
-
- include_examples 'update failure', _('Invalid status')
- end
-
- context 'with unknown status' do
- let(:new_status) { -1 }
-
- include_examples 'update failure', _('Invalid status')
- end
- end
-end