Commit 3c21e545 authored by syasonik's avatar syasonik

Use new integer value for status

parent 6bb5e629
......@@ -2,17 +2,19 @@
module AlertManagement
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)
@alert = alert
@status = status
end
def execute
return error('Invalid status') unless AlertManagement::Alert::STATUSES.key?(status.to_sym)
alert.status_event = AlertManagement::Alert::STATUS_EVENTS[status.to_sym]
return error('Invalid status') unless status_key
if alert.save
if alert.update(status_event: status_event)
success
else
error(alert.errors.full_messages.to_sentence)
......@@ -23,6 +25,16 @@ module AlertManagement
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
ServiceResponse.success(payload: { alert: alert })
end
......
......@@ -6,7 +6,7 @@ describe Mutations::AlertManagement::UpdateAlertStatus do
let_it_be(:current_user) { create(:user) }
let_it_be(:alert) { create(:alert_management_alert, status: 'triggered') }
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 } }
specify { expect(described_class).to require_graphql_authorizations(:update_alert_management_alert) }
......
......@@ -8,7 +8,7 @@ describe AlertManagement::UpdateAlertStatusService do
describe '#execute' do
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
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