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
d476e636
Commit
d476e636
authored
Feb 18, 2021
by
Markus Koller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec for failing Jira issue transitions
parent
126e0158
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
27 deletions
+47
-27
spec/models/project_services/jira_service_spec.rb
spec/models/project_services/jira_service_spec.rb
+47
-27
No files found.
spec/models/project_services/jira_service_spec.rb
View file @
d476e636
...
...
@@ -472,7 +472,7 @@ RSpec.describe JiraService do
shared_examples
'close_issue'
do
let
(
:issue_key
)
{
'JIRA-123'
}
let
(
:issue_url
)
{
"
http://jira.example.com
/rest/api/2/issue/
#{
issue_key
}
"
}
let
(
:issue_url
)
{
"
#{
url
}
/rest/api/2/issue/
#{
issue_key
}
"
}
let
(
:transitions_url
)
{
"
#{
issue_url
}
/transitions"
}
let
(
:comment_url
)
{
"
#{
issue_url
}
/comment"
}
let
(
:remote_link_url
)
{
"
#{
issue_url
}
/remotelink"
}
...
...
@@ -487,24 +487,16 @@ RSpec.describe JiraService do
end
subject
(
:close_issue
)
do
@
jira_service
.
close_issue
(
resource
,
ExternalIssue
.
new
(
issue_key
,
project
))
jira_service
.
close_issue
(
resource
,
ExternalIssue
.
new
(
issue_key
,
project
))
end
before
do
@jira_service
=
described_class
.
new
allow
(
@jira_service
).
to
receive_messages
(
project_id:
project
.
id
,
project:
project
,
url:
'http://jira.example.com'
,
username:
'gitlab_jira_username'
,
password:
'gitlab_jira_password'
,
jira_issue_transition_id:
'999'
)
allow
(
jira_service
).
to
receive_messages
(
jira_issue_transition_id:
'999'
)
# These stubs are needed to test JiraService#close_issue.
# We close the issue then do another request to API to check if it got closed.
# Here is stubbed the API return with a closed and an opened issues.
open_issue
=
JIRA
::
Resource
::
Issue
.
new
(
@
jira_service
.
client
,
attrs:
issue_fields
.
deep_stringify_keys
)
open_issue
=
JIRA
::
Resource
::
Issue
.
new
(
jira_service
.
client
,
attrs:
issue_fields
.
deep_stringify_keys
)
closed_issue
=
open_issue
.
dup
allow
(
open_issue
).
to
receive
(
:resolution
).
and_return
(
false
)
allow
(
closed_issue
).
to
receive
(
:resolution
).
and_return
(
true
)
...
...
@@ -513,18 +505,16 @@ RSpec.describe JiraService do
allow_any_instance_of
(
JIRA
::
Resource
::
Issue
).
to
receive
(
:key
).
and_return
(
issue_key
)
allow
(
JIRA
::
Resource
::
Remotelink
).
to
receive
(
:all
).
and_return
([])
@jira_service
.
save!
WebMock
.
stub_request
(
:get
,
issue_url
).
with
(
basic_auth:
%w(gitlab_jira_username gitlab_jira_password)
)
WebMock
.
stub_request
(
:post
,
transitions_url
).
with
(
basic_auth:
%w(gitlab_jira_username gitlab_jira_password)
)
WebMock
.
stub_request
(
:post
,
comment_url
).
with
(
basic_auth:
%w(gitlab_jira_username gitlab_jira_password)
)
WebMock
.
stub_request
(
:post
,
remote_link_url
).
with
(
basic_auth:
%w(gitlab_jira_username gitlab_jira_password)
)
WebMock
.
stub_request
(
:get
,
issue_url
).
with
(
basic_auth:
%w(jira-username jira-password)
)
WebMock
.
stub_request
(
:post
,
transitions_url
).
with
(
basic_auth:
%w(jira-username jira-password)
)
WebMock
.
stub_request
(
:post
,
comment_url
).
with
(
basic_auth:
%w(jira-username jira-password)
)
WebMock
.
stub_request
(
:post
,
remote_link_url
).
with
(
basic_auth:
%w(jira-username jira-password)
)
end
let
(
:external_issue
)
{
ExternalIssue
.
new
(
'JIRA-123'
,
project
)
}
def
close_issue
@
jira_service
.
close_issue
(
resource
,
external_issue
,
current_user
)
jira_service
.
close_issue
(
resource
,
external_issue
,
current_user
)
end
it
'calls Jira API'
do
...
...
@@ -575,7 +565,7 @@ RSpec.describe JiraService do
context
'when "comment_on_event_enabled" is set to false'
do
it
'creates Remote Link reference but does not create comment'
do
allow
(
@
jira_service
).
to
receive_messages
(
comment_on_event_enabled:
false
)
allow
(
jira_service
).
to
receive_messages
(
comment_on_event_enabled:
false
)
close_issue
expect
(
WebMock
).
not_to
have_requested
(
:post
,
comment_url
)
...
...
@@ -648,12 +638,12 @@ RSpec.describe JiraService do
end
it
'logs exception when transition id is not valid'
do
allow
(
@
jira_service
).
to
receive
(
:log_error
)
WebMock
.
stub_request
(
:post
,
transitions_url
).
with
(
basic_auth:
%w(
gitlab_jira_username gitlab_jira_
password)
).
and_raise
(
"Bad Request"
)
allow
(
jira_service
).
to
receive
(
:log_error
)
WebMock
.
stub_request
(
:post
,
transitions_url
).
with
(
basic_auth:
%w(
jira-username jira-
password)
).
and_raise
(
"Bad Request"
)
close_issue
expect
(
@
jira_service
).
to
have_received
(
:log_error
).
with
(
expect
(
jira_service
).
to
have_received
(
:log_error
).
with
(
"Issue transition failed"
,
error:
hash_including
(
exception_class:
'StandardError'
,
...
...
@@ -682,7 +672,7 @@ RSpec.describe JiraService do
end
before
do
allow
(
@
jira_service
).
to
receive_messages
(
jira_issue_transition_id:
''
)
allow
(
jira_service
).
to
receive_messages
(
jira_issue_transition_id:
''
)
close_issue
end
...
...
@@ -715,9 +705,11 @@ RSpec.describe JiraService do
end
context
'when using multiple transition ids'
do
it
'calls the api with transition ids separated by comma'
do
allow
(
@jira_service
).
to
receive_messages
(
jira_issue_transition_id:
'1,2,3'
)
before
do
allow
(
jira_service
).
to
receive_messages
(
jira_issue_transition_id:
'1,2,3'
)
end
it
'calls the api with transition ids separated by comma'
do
close_issue
1
.
upto
(
3
)
do
|
transition_id
|
...
...
@@ -725,10 +717,12 @@ RSpec.describe JiraService do
body:
/"id":"
#{
transition_id
}
"/
).
once
end
expect
(
WebMock
).
to
have_requested
(
:post
,
comment_url
)
end
it
'calls the api with transition ids separated by semicolon'
do
allow
(
@
jira_service
).
to
receive_messages
(
jira_issue_transition_id:
'1;2;3'
)
allow
(
jira_service
).
to
receive_messages
(
jira_issue_transition_id:
'1;2;3'
)
close_issue
...
...
@@ -737,6 +731,32 @@ RSpec.describe JiraService do
body:
/"id":"
#{
transition_id
}
"/
).
once
end
expect
(
WebMock
).
to
have_requested
(
:post
,
comment_url
)
end
context
'when a transition fails'
do
before
do
WebMock
.
stub_request
(
:post
,
transitions_url
).
with
(
basic_auth:
%w(jira-username jira-password)
).
to_return
do
|
request
|
{
status:
request
.
body
.
include?
(
'"id":"2"'
)
?
500
:
200
}
end
end
it
'stops the sequence'
do
close_issue
1
.
upto
(
2
)
do
|
transition_id
|
expect
(
WebMock
).
to
have_requested
(
:post
,
transitions_url
).
with
(
body:
/"id":"
#{
transition_id
}
"/
)
end
expect
(
WebMock
).
not_to
have_requested
(
:post
,
transitions_url
).
with
(
body:
/"id":"3"/
)
expect
(
WebMock
).
not_to
have_requested
(
:post
,
comment_url
)
end
end
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