Commit dbb412f7 authored by Sean Arnold's avatar Sean Arnold

Update specs to use doubles

- Rename execute! to execute
- Add update_alert_management_alerts policy
parent b81bd8ff
......@@ -18,6 +18,8 @@ module Mutations
null: true,
description: "The alert after mutation"
authorize :update_alert_management_alerts
private
def find_object(project_path:, iid:)
......
......@@ -9,8 +9,6 @@ module Mutations
required: true,
description: 'The status to set the alert'
authorize :read_alert_management_alerts
def resolve(args)
alert = authorized_find!(project_path: args[:project_path], iid: args[:iid])
......@@ -22,7 +20,7 @@ module Mutations
def update_status(alert, status)
service = ::AlertManagement::UpdateAlertStatusService.new(alert, status)
service.execute!
service.execute
end
def prepare_response(result)
......
......@@ -240,6 +240,7 @@ class ProjectPolicy < BasePolicy
enable :read_prometheus
enable :read_metrics_dashboard_annotation
enable :read_alert_management_alerts
enable :update_alert_management_alerts
enable :metrics_dashboard
end
......
......@@ -7,7 +7,7 @@ module AlertManagement
@status = status
end
def execute!
def execute
return error_response('Invalid status') unless AlertManagement::Alert.statuses.key?(status.to_s)
alert.status = status
......
......@@ -29,26 +29,32 @@ describe Mutations::AlertManagement::UpdateAlertStatus do
end
context 'error occurs when updating' do
before do
# Stubbing and error on alert
it 'returns the alert with errors' do
# Stub an error on the alert
allow_next_instance_of(Resolvers::AlertManagementAlertResolver) do |resolver|
allow(resolver).to receive(:resolve).and_return(alert)
end
expect(alert).to receive(:save).and_return(false)
errors = ActiveModel::Errors.new(alert)
errors.add(:status, :invalid)
expect(alert).to receive(:errors).and_return(errors)
end
it 'returns the alert with no errors' do
expect(alert).to receive(:errors).and_return(
double(full_messages: %w(foo bar))
)
expect(resolve).to eq(
alert: alert,
errors: ['Status is invalid']
errors: ['foo and bar']
)
end
context 'invalid status given' do
let(:new_status) { 'invalid_status' }
it 'returns the alert with errors' do
expect(resolve).to eq(
alert: alert,
errors: ['Invalid status']
)
end
end
end
end
......
......@@ -5,8 +5,8 @@ require 'spec_helper'
describe AlertManagement::UpdateAlertStatusService do
let_it_be(:alert) { create(:alert_management_alert, status: 'triggered') }
describe '#execute!' do
subject(:execute) { described_class.new(alert, new_status).execute! }
describe '#execute' do
subject(:execute) { described_class.new(alert, new_status).execute }
let(:new_status) { 'acknowledged' }
......
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