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
Show 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
...
@@ -18,6 +18,8 @@ module Mutations
null:
true
,
null:
true
,
description:
"The alert after mutation"
description:
"The alert after mutation"
authorize
:update_alert_management_alerts
private
private
def
find_object
(
project_path
:,
iid
:)
def
find_object
(
project_path
:,
iid
:)
...
...
app/graphql/mutations/alert_management/update_alert_status.rb
View file @
dbb412f7
...
@@ -9,8 +9,6 @@ module Mutations
...
@@ -9,8 +9,6 @@ module Mutations
required:
true
,
required:
true
,
description:
'The status to set the alert'
description:
'The status to set the alert'
authorize
:read_alert_management_alerts
def
resolve
(
args
)
def
resolve
(
args
)
alert
=
authorized_find!
(
project_path:
args
[
:project_path
],
iid:
args
[
:iid
])
alert
=
authorized_find!
(
project_path:
args
[
:project_path
],
iid:
args
[
:iid
])
...
@@ -22,7 +20,7 @@ module Mutations
...
@@ -22,7 +20,7 @@ module Mutations
def
update_status
(
alert
,
status
)
def
update_status
(
alert
,
status
)
service
=
::
AlertManagement
::
UpdateAlertStatusService
.
new
(
alert
,
status
)
service
=
::
AlertManagement
::
UpdateAlertStatusService
.
new
(
alert
,
status
)
service
.
execute
!
service
.
execute
end
end
def
prepare_response
(
result
)
def
prepare_response
(
result
)
...
...
app/policies/project_policy.rb
View file @
dbb412f7
...
@@ -240,6 +240,7 @@ class ProjectPolicy < BasePolicy
...
@@ -240,6 +240,7 @@ class ProjectPolicy < BasePolicy
enable
:read_prometheus
enable
:read_prometheus
enable
:read_metrics_dashboard_annotation
enable
:read_metrics_dashboard_annotation
enable
:read_alert_management_alerts
enable
:read_alert_management_alerts
enable
:update_alert_management_alerts
enable
:metrics_dashboard
enable
:metrics_dashboard
end
end
...
...
app/services/alert_management/update_alert_status_service.rb
View file @
dbb412f7
...
@@ -7,7 +7,7 @@ module AlertManagement
...
@@ -7,7 +7,7 @@ module AlertManagement
@status
=
status
@status
=
status
end
end
def
execute
!
def
execute
return
error_response
(
'Invalid status'
)
unless
AlertManagement
::
Alert
.
statuses
.
key?
(
status
.
to_s
)
return
error_response
(
'Invalid status'
)
unless
AlertManagement
::
Alert
.
statuses
.
key?
(
status
.
to_s
)
alert
.
status
=
status
alert
.
status
=
status
...
...
spec/graphql/mutations/alert_management/update_alert_status_spec.rb
View file @
dbb412f7
...
@@ -29,28 +29,34 @@ describe Mutations::AlertManagement::UpdateAlertStatus do
...
@@ -29,28 +29,34 @@ describe Mutations::AlertManagement::UpdateAlertStatus do
end
end
context
'error occurs when updating'
do
context
'error occurs when updating'
do
before
do
it
'returns the alert with errors'
do
# Stub
bing and error on
alert
# Stub
an error on the
alert
allow_next_instance_of
(
Resolvers
::
AlertManagementAlertResolver
)
do
|
resolver
|
allow_next_instance_of
(
Resolvers
::
AlertManagementAlertResolver
)
do
|
resolver
|
allow
(
resolver
).
to
receive
(
:resolve
).
and_return
(
alert
)
allow
(
resolver
).
to
receive
(
:resolve
).
and_return
(
alert
)
end
end
expect
(
alert
).
to
receive
(
:save
).
and_return
(
false
)
expect
(
alert
).
to
receive
(
:save
).
and_return
(
false
)
expect
(
alert
).
to
receive
(
:errors
).
and_return
(
errors
=
ActiveModel
::
Errors
.
new
(
alert
)
double
(
full_messages:
%w(foo bar)
)
errors
.
add
(
:status
,
:invalid
)
)
expect
(
resolve
).
to
eq
(
expect
(
alert
).
to
receive
(
:errors
).
and_return
(
errors
)
alert:
alert
,
errors:
[
'foo and bar'
]
)
end
end
it
'returns the alert with no errors'
do
context
'invalid status given'
do
let
(
:new_status
)
{
'invalid_status'
}
it
'returns the alert with errors'
do
expect
(
resolve
).
to
eq
(
expect
(
resolve
).
to
eq
(
alert:
alert
,
alert:
alert
,
errors:
[
'Status is invalid
'
]
errors:
[
'Invalid status
'
]
)
)
end
end
end
end
end
end
end
it
'raises an error if the resource is not accessible to the user'
do
it
'raises an error if the resource is not accessible to the user'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
...
...
spec/services/alert_management/update_alert_status_service_spec.rb
View file @
dbb412f7
...
@@ -5,8 +5,8 @@ require 'spec_helper'
...
@@ -5,8 +5,8 @@ require 'spec_helper'
describe
AlertManagement
::
UpdateAlertStatusService
do
describe
AlertManagement
::
UpdateAlertStatusService
do
let_it_be
(
:alert
)
{
create
(
:alert_management_alert
,
status:
'triggered'
)
}
let_it_be
(
:alert
)
{
create
(
:alert_management_alert
,
status:
'triggered'
)
}
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
)
{
'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