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
b81bd8ff
Commit
b81bd8ff
authored
Apr 30, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test for errors additon
- Ensure we add model errors - Simplify resolve in mutation
parent
b55602e2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
12 deletions
+35
-12
app/graphql/mutations/alert_management/update_alert_status.rb
...graphql/mutations/alert_management/update_alert_status.rb
+3
-10
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
+31
-1
No files found.
app/graphql/mutations/alert_management/update_alert_status.rb
View file @
b81bd8ff
...
@@ -14,15 +14,8 @@ module Mutations
...
@@ -14,15 +14,8 @@ module Mutations
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
])
if
alert
result
=
update_status
(
alert
,
args
[
:status
])
result
=
update_status
(
alert
,
args
[
:status
])
prepare_response
(
result
)
prepare_response
(
result
)
else
{
alert:
alert
,
errors:
[
'Alert could not be found'
]
}
end
end
end
private
private
...
@@ -35,7 +28,7 @@ module Mutations
...
@@ -35,7 +28,7 @@ module Mutations
def
prepare_response
(
result
)
def
prepare_response
(
result
)
{
{
alert:
result
.
payload
[
:alert
],
alert:
result
.
payload
[
:alert
],
errors:
result
.
message
.
present?
?
[
result
.
message
]
:
[]
errors:
result
.
error?
?
[
result
.
message
].
compact
:
[]
}
}
end
end
end
end
...
...
app/services/alert_management/update_alert_status_service.rb
View file @
b81bd8ff
...
@@ -13,7 +13,7 @@ module AlertManagement
...
@@ -13,7 +13,7 @@ module AlertManagement
alert
.
status
=
status
alert
.
status
=
status
return
ServiceResponse
.
success
(
payload:
{
alert:
alert
})
if
alert
.
save
return
ServiceResponse
.
success
(
payload:
{
alert:
alert
})
if
alert
.
save
error_response
error_response
(
alert
.
errors
.
full_messages
.
to_sentence
)
end
end
private
private
...
...
spec/graphql/mutations/alert_management/update_alert_status_spec.rb
View file @
b81bd8ff
...
@@ -5,7 +5,7 @@ require 'spec_helper'
...
@@ -5,7 +5,7 @@ require 'spec_helper'
describe
Mutations
::
AlertManagement
::
UpdateAlertStatus
do
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
(
:project
)
{
alert
.
project
}
let
_it_be
(
:project
)
{
alert
.
project
}
let
(
:new_status
)
{
'acknowledged'
}
let
(
:new_status
)
{
'acknowledged'
}
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
}
}
...
@@ -20,6 +20,36 @@ describe Mutations::AlertManagement::UpdateAlertStatus do
...
@@ -20,6 +20,36 @@ describe Mutations::AlertManagement::UpdateAlertStatus do
it
'changes the status'
do
it
'changes the status'
do
expect
{
resolve
}.
to
change
{
alert
.
reload
.
status
}.
from
(
alert
.
status
).
to
(
new_status
)
expect
{
resolve
}.
to
change
{
alert
.
reload
.
status
}.
from
(
alert
.
status
).
to
(
new_status
)
end
end
it
'returns the alert with no errors'
do
expect
(
resolve
).
to
eq
(
alert:
alert
,
errors:
[]
)
end
context
'error occurs when updating'
do
before
do
# Stubbing and error on 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
(
resolve
).
to
eq
(
alert:
alert
,
errors:
[
'Status is invalid'
]
)
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
...
...
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