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
1a3c1a90
Commit
1a3c1a90
authored
Feb 17, 2022
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract timeline event tests into shared examples
parent
72201bf6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
59 deletions
+92
-59
ee/app/graphql/mutations/incident_management/timeline_event/promote_from_note.rb
...s/incident_management/timeline_event/promote_from_note.rb
+1
-1
ee/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb
...tations/incident_management/timeline_event/create_spec.rb
+15
-27
ee/spec/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb
...ident_management/timeline_event/promote_from_note_spec.rb
+18
-31
ee/spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb
...ns/incident_management_timeline_events_shared_examples.rb
+58
-0
No files found.
ee/app/graphql/mutations/incident_management/timeline_event/promote_from_note.rb
View file @
1a3c1a90
...
@@ -32,7 +32,7 @@ module Mutations
...
@@ -32,7 +32,7 @@ module Mutations
end
end
def
authorize!
(
object
)
def
authorize!
(
object
)
raise_noteable_not_incident!
if
object
&&
!
object
.
incident?
raise_noteable_not_incident!
if
object
&&
!
object
.
try
(
:incident?
)
super
super
end
end
...
...
ee/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb
View file @
1a3c1a90
...
@@ -19,44 +19,32 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::Create do
...
@@ -19,44 +19,32 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::Create do
subject
(
:resolve
)
{
mutation_for
(
project
,
current_user
).
resolve
(
incident_id:
incident
.
to_global_id
,
**
args
)
}
subject
(
:resolve
)
{
mutation_for
(
project
,
current_user
).
resolve
(
incident_id:
incident
.
to_global_id
,
**
args
)
}
context
'when a user has permissions to create a timeline event'
do
context
'when a user has permissions to create a timeline event'
do
let
(
:expected_timeline_event
)
do
instance_double
(
'IncidentManagement::TimelineEvent'
,
note:
args
[
:note
],
occurred_at:
args
[
:occurred_at
].
to_s
,
incident:
incident
,
author:
current_user
,
promoted_from_note:
nil
)
end
before
do
before
do
project
.
add_developer
(
current_user
)
project
.
add_developer
(
current_user
)
end
end
context
'when TimelineEvents::CreateService responds with success'
do
it_behaves_like
'creating an incident timeline event'
it
'adds timeline event to database'
do
expect
{
resolve
}.
to
change
(
IncidentManagement
::
TimelineEvent
,
:count
).
by
(
1
)
end
end
context
'when TimelineEvents::CreateService responds with an error'
do
context
'when TimelineEvents::CreateService responds with an error'
do
let
(
:args
)
{
{}
}
let
(
:args
)
{
{}
}
it
'returns errors'
do
it_behaves_like
'responding with an incident timeline errors'
,
expect
(
resolve
).
to
eq
(
timeline_event:
nil
,
errors:
[
"Occurred at can't be blank, Note can't be blank, and Note html can't be blank"
])
errors:
[
"Occurred at can't be blank, Note can't be blank, and Note html can't be blank"
]
end
end
end
context
'when a user has no permissions to create timeline event'
do
before
do
project
.
add_guest
(
current_user
)
end
it
'raises an error'
do
expect
{
resolve
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
end
end
context
'when timeline event feature is not available'
do
it_behaves_like
'failing to create an incident timeline event'
before
do
stub_licensed_features
(
incident_timeline_events:
false
)
end
it
'raises an error'
do
expect
{
resolve
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
end
end
private
private
...
...
ee/spec/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb
View file @
1a3c1a90
...
@@ -9,6 +9,8 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::PromoteFromNote do
...
@@ -9,6 +9,8 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::PromoteFromNote do
let_it_be
(
:comment
)
{
create
(
:note
,
project:
project
,
noteable:
incident
)
}
let_it_be
(
:comment
)
{
create
(
:note
,
project:
project
,
noteable:
incident
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let_it_be
(
:issue_comment
)
{
create
(
:note
,
project:
project
,
noteable:
issue
)
}
let_it_be
(
:issue_comment
)
{
create
(
:note
,
project:
project
,
noteable:
issue
)
}
let_it_be
(
:alert
)
{
create
(
:alert_management_alert
,
project:
project
)
}
let_it_be
(
:alert_comment
)
{
create
(
:note
,
project:
project
,
noteable:
alert
)
}
let
(
:args
)
{
{
note_id:
comment
.
to_global_id
.
to_s
}
}
let
(
:args
)
{
{
note_id:
comment
.
to_global_id
.
to_s
}
}
...
@@ -22,25 +24,22 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::PromoteFromNote do
...
@@ -22,25 +24,22 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::PromoteFromNote do
subject
(
:resolve
)
{
mutation_for
(
project
,
current_user
).
resolve
(
**
args
)
}
subject
(
:resolve
)
{
mutation_for
(
project
,
current_user
).
resolve
(
**
args
)
}
context
'when a user has permissions to create timeline event'
do
context
'when a user has permissions to create timeline event'
do
before
do
let
(
:expected_timeline_event
)
do
project
.
add_developer
(
current_user
)
instance_double
(
'IncidentManagement::TimelineEvent'
,
note:
comment
.
note
,
occurred_at:
comment
.
created_at
.
to_s
,
incident:
incident
,
author:
current_user
,
promoted_from_note:
comment
)
end
end
it
'creates a timeline event'
do
before
do
expect
{
resolve
}.
to
change
(
IncidentManagement
::
TimelineEvent
,
:count
).
by
(
1
)
project
.
add_developer
(
current_user
)
end
end
it
'responds with a timeline event'
,
:aggregate_failures
do
it_behaves_like
'creating an incident timeline event'
response
=
resolve
timeline_event
=
IncidentManagement
::
TimelineEvent
.
last!
expect
(
response
).
to
match
(
timeline_event:
timeline_event
,
errors:
be_empty
)
expect
(
timeline_event
.
promoted_from_note
).
to
eq
(
comment
)
expect
(
timeline_event
.
note
).
to
eq
(
comment
.
note
)
expect
(
timeline_event
.
occurred_at
.
to_s
).
to
eq
(
comment
.
created_at
.
to_s
)
expect
(
timeline_event
.
incident
).
to
eq
(
incident
)
expect
(
timeline_event
.
author
).
to
eq
(
current_user
)
end
context
'when TimelineEvents::CreateService responds with an error'
do
context
'when TimelineEvents::CreateService responds with an error'
do
before
do
before
do
...
@@ -51,9 +50,7 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::PromoteFromNote do
...
@@ -51,9 +50,7 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::PromoteFromNote do
end
end
end
end
it
'returns errors'
do
it_behaves_like
'responding with an incident timeline errors'
,
errors:
[
'Some error'
]
expect
(
resolve
).
to
eq
(
timeline_event:
nil
,
errors:
[
'Some error'
])
end
end
end
end
end
...
@@ -73,25 +70,15 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::PromoteFromNote do
...
@@ -73,25 +70,15 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::PromoteFromNote do
end
end
end
end
context
'when a user does not have permissions to create timeline event'
do
context
'when note belongs to anything else but issuable'
do
before
do
let
(
:args
)
{
{
note_id:
alert_comment
.
to_global_id
.
to_s
}
}
project
.
add_guest
(
current_user
)
end
it
'raises an error'
do
it
'raises an error'
do
expect
{
resolve
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
expect
{
resolve
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
end
end
context
'when timeline event feature is not available'
do
it_behaves_like
'failing to create an incident timeline event'
before
do
stub_licensed_features
(
incident_timeline_events:
false
)
end
it
'raises an error'
do
expect
{
resolve
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
end
end
private
private
...
...
ee/spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb
0 → 100644
View file @
1a3c1a90
# frozen_string_literal: true
require
'spec_helper'
# Requres:
# * subject with a 'resolve' name
# * Defined expected timeline event via `let(:expected_timeline_event) { instance_double(...) }`
RSpec
.
shared_examples
'creating an incident timeline event'
do
it
'creates a timeline event'
do
expect
{
resolve
}.
to
change
(
IncidentManagement
::
TimelineEvent
,
:count
).
by
(
1
)
end
it
'responds with a timeline event'
,
:aggregate_failures
do
response
=
resolve
timeline_event
=
IncidentManagement
::
TimelineEvent
.
last!
expect
(
response
).
to
match
(
timeline_event:
timeline_event
,
errors:
be_empty
)
expect
(
timeline_event
.
promoted_from_note
).
to
eq
(
expected_timeline_event
.
promoted_from_note
)
expect
(
timeline_event
.
note
).
to
eq
(
expected_timeline_event
.
note
)
expect
(
timeline_event
.
occurred_at
.
to_s
).
to
eq
(
expected_timeline_event
.
occurred_at
)
expect
(
timeline_event
.
incident
).
to
eq
(
expected_timeline_event
.
incident
)
expect
(
timeline_event
.
author
).
to
eq
(
expected_timeline_event
.
author
)
end
end
# Requres
# * subject with a 'resolve' name
# * a user factory with a 'current_user' name
RSpec
.
shared_examples
'failing to create an incident timeline event'
do
context
'when a user has no permissions to create timeline event'
do
before
do
project
.
add_guest
(
current_user
)
end
it
'raises an error'
do
expect
{
resolve
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
context
'when timeline event feature is not available'
do
before
do
stub_licensed_features
(
incident_timeline_events:
false
)
end
it
'raises an error'
do
expect
{
resolve
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
end
# Requres:
# * subject with a 'resolve' name
RSpec
.
shared_examples
'responding with an incident timeline errors'
do
|
errors
:|
it
'returns errors'
do
expect
(
resolve
).
to
eq
(
timeline_event:
nil
,
errors:
errors
)
end
end
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