Commit baac193a authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'sy-correct-status-type' into 'master'

Use new integer value for status

See merge request gitlab-org/gitlab!31525
parents 85b196b4 3c21e545
...@@ -2,17 +2,19 @@ ...@@ -2,17 +2,19 @@
module AlertManagement module AlertManagement
class UpdateAlertStatusService class UpdateAlertStatusService
include Gitlab::Utils::StrongMemoize
# @param alert [AlertManagement::Alert]
# @param status [Integer] Must match a value from AlertManagement::Alert::STATUSES
def initialize(alert, status) def initialize(alert, status)
@alert = alert @alert = alert
@status = status @status = status
end end
def execute def execute
return error('Invalid status') unless AlertManagement::Alert::STATUSES.key?(status.to_sym) return error('Invalid status') unless status_key
alert.status_event = AlertManagement::Alert::STATUS_EVENTS[status.to_sym]
if alert.save if alert.update(status_event: status_event)
success success
else else
error(alert.errors.full_messages.to_sentence) error(alert.errors.full_messages.to_sentence)
...@@ -23,6 +25,16 @@ module AlertManagement ...@@ -23,6 +25,16 @@ module AlertManagement
attr_reader :alert, :status attr_reader :alert, :status
def status_key
strong_memoize(:status_key) do
AlertManagement::Alert::STATUSES.key(status)
end
end
def status_event
AlertManagement::Alert::STATUS_EVENTS[status_key]
end
def success def success
ServiceResponse.success(payload: { alert: alert }) ServiceResponse.success(payload: { alert: alert })
end end
......
...@@ -6,7 +6,7 @@ describe Mutations::AlertManagement::UpdateAlertStatus do ...@@ -6,7 +6,7 @@ describe Mutations::AlertManagement::UpdateAlertStatus do
let_it_be(:current_user) { create(:user) } let_it_be(:current_user) { create(:user) }
let_it_be(:alert) { create(:alert_management_alert, status: 'triggered') } let_it_be(:alert) { create(:alert_management_alert, status: 'triggered') }
let_it_be(:project) { alert.project } let_it_be(:project) { alert.project }
let(:new_status) { 'acknowledged' } let(:new_status) { Types::AlertManagement::StatusEnum.values['ACKNOWLEDGED'].value }
let(:args) { { status: new_status, project_path: project.full_path, iid: alert.iid } } let(:args) { { status: new_status, project_path: project.full_path, iid: alert.iid } }
specify { expect(described_class).to require_graphql_authorizations(:update_alert_management_alert) } specify { expect(described_class).to require_graphql_authorizations(:update_alert_management_alert) }
......
...@@ -8,7 +8,7 @@ describe AlertManagement::UpdateAlertStatusService do ...@@ -8,7 +8,7 @@ describe AlertManagement::UpdateAlertStatusService do
describe '#execute' do describe '#execute' do
subject(:execute) { described_class.new(alert, new_status).execute } subject(:execute) { described_class.new(alert, new_status).execute }
let(:new_status) { 'acknowledged' } let(:new_status) { Types::AlertManagement::StatusEnum.values['ACKNOWLEDGED'].value }
it 'updates the status' do it 'updates the status' do
expect { execute }.to change { alert.acknowledged? }.to(true) expect { execute }.to change { alert.acknowledged? }.to(true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment