Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
dbb412f7
Commit
dbb412f7
authored
May 04, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update specs to use doubles
- Rename execute! to execute - Add update_alert_management_alerts policy
parent
b81bd8ff
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
17 deletions
+24
-17
app/graphql/mutations/alert_management/base.rb
app/graphql/mutations/alert_management/base.rb
+2
-0
app/graphql/mutations/alert_management/update_alert_status.rb
...graphql/mutations/alert_management/update_alert_status.rb
+1
-3
app/policies/project_policy.rb
app/policies/project_policy.rb
+1
-0
app/services/alert_management/update_alert_status_service.rb
app/services/alert_management/update_alert_status_service.rb
+1
-1
spec/graphql/mutations/alert_management/update_alert_status_spec.rb
...ql/mutations/alert_management/update_alert_status_spec.rb
+17
-11
spec/services/alert_management/update_alert_status_service_spec.rb
...ices/alert_management/update_alert_status_service_spec.rb
+2
-2
No files found.
app/graphql/mutations/alert_management/base.rb
View file @
dbb412f7
...
...
@@ -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
:)
...
...
app/graphql/mutations/alert_management/update_alert_status.rb
View file @
dbb412f7
...
...
@@ -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
)
...
...
app/policies/project_policy.rb
View file @
dbb412f7
...
...
@@ -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
...
...
app/services/alert_management/update_alert_status_service.rb
View file @
dbb412f7
...
...
@@ -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
...
...
spec/graphql/mutations/alert_management/update_alert_status_spec.rb
View file @
dbb412f7
...
...
@@ -29,26 +29,32 @@ describe Mutations::AlertManagement::UpdateAlertStatus do
end
context
'error occurs when updating'
do
before
do
# Stub
bing 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
...
...
spec/services/alert_management/update_alert_status_service_spec.rb
View file @
dbb412f7
...
...
@@ -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'
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment