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
af6762f7
Commit
af6762f7
authored
Feb 13, 2020
by
Eugenia Grieff
Committed by
Robert Speicher
Feb 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor merge requests api requests specs
Resuse existing methods defined in api_helper
parent
3c8faad1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
135 additions
and
195 deletions
+135
-195
ee/spec/requests/api/merge_requests_spec.rb
ee/spec/requests/api/merge_requests_spec.rb
+7
-13
spec/requests/api/issues/issues_spec.rb
spec/requests/api/issues/issues_spec.rb
+2
-7
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+115
-175
spec/support/helpers/api_helpers.rb
spec/support/helpers/api_helpers.rb
+11
-0
No files found.
ee/spec/requests/api/merge_requests_spec.rb
View file @
af6762f7
...
...
@@ -212,12 +212,6 @@ describe API::MergeRequests do
end
context
'when authenticated'
do
def
expect_response_contain_exactly
(
*
items
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
.
map
{
|
element
|
element
[
'id'
]
}).
to
contain_exactly
(
*
items
.
map
(
&
:id
))
expect
(
json_response
.
length
).
to
eq
(
items
.
size
)
end
context
'filter merge requests by assignee ID'
do
let!
(
:merge_request2
)
do
create
(
:merge_request
,
:simple
,
assignees:
[
user2
],
source_project:
project
,
target_project:
project
,
source_branch:
'other-branch-2'
)
...
...
@@ -226,7 +220,7 @@ describe API::MergeRequests do
it
'returns merge requests with given assignee ID'
do
get
api
(
'/merge_requests'
,
user
),
params:
{
assignee_id:
user2
.
id
}
expect_
response_contain_exactly
(
merge_request
,
merge_request2
)
expect_
paginated_array_response
([
merge_request2
.
id
,
merge_request
.
id
]
)
end
end
...
...
@@ -243,7 +237,7 @@ describe API::MergeRequests do
let
(
:approvers_param
)
{
[
merge_request_with_approver
.
approvers
.
first
.
user_id
]
}
it
'returns an array of merge requests which have specified the user as an approver'
do
expect_
response_contain_exactly
(
merge_request_with_approver
)
expect_
paginated_array_response
([
merge_request_with_approver
.
id
]
)
end
end
...
...
@@ -251,7 +245,7 @@ describe API::MergeRequests do
let
(
:approvers_param
)
{
'None'
}
it
'returns an array of merge requests with no approvers'
do
expect_
response_contain_exactly
(
merge_request
)
expect_
paginated_array_response
([
merge_request
.
id
]
)
end
end
...
...
@@ -259,7 +253,7 @@ describe API::MergeRequests do
let
(
:approvers_param
)
{
'Any'
}
it
'returns an array of merge requests with any approver'
do
expect_
response_contain_exactly
(
merge_request_with_approver
)
expect_
paginated_array_response
([
merge_request_with_approver
.
id
]
)
end
end
...
...
@@ -288,7 +282,7 @@ describe API::MergeRequests do
let
(
:approvals_param
)
{
[
user2
.
id
]
}
it
'returns an array of merge requests which have specified the user as an approver'
do
expect_
response_contain_exactly
(
merge_request_with_approval
)
expect_
paginated_array_response
([
merge_request_with_approval
.
id
]
)
end
end
...
...
@@ -296,7 +290,7 @@ describe API::MergeRequests do
let
(
:approvals_param
)
{
'None'
}
it
'returns an array of merge requests with no approvers'
do
expect_
response_contain_exactly
(
merge_request
)
expect_
paginated_array_response
([
merge_request
.
id
]
)
end
end
...
...
@@ -304,7 +298,7 @@ describe API::MergeRequests do
let
(
:approvals_param
)
{
'Any'
}
it
'returns an array of merge requests with any approver'
do
expect_
response_contain_exactly
(
merge_request_with_approval
)
expect_
paginated_array_response
([
merge_request_with_approval
.
id
]
)
end
end
...
...
spec/requests/api/issues/issues_spec.rb
View file @
af6762f7
...
...
@@ -795,13 +795,13 @@ describe API::Issues do
it
'returns issues from non archived projects only by default'
do
get
api
(
"/groups/
#{
group1
.
id
}
/issues"
,
user
),
params:
{
scope:
'all'
}
expect_
response_contain_exactly
(
issue2
,
issue1
)
expect_
paginated_array_response
([
issue2
.
id
,
issue1
.
id
]
)
end
it
'returns issues from archived and non archived projects when non_archived is false'
do
get
api
(
"/groups/
#{
group1
.
id
}
/issues"
,
user
),
params:
{
non_archived:
false
,
scope:
'all'
}
expect_
response_contain_exactly
(
issue1
,
issue2
,
issue3
)
expect_
paginated_array_response
([
issue3
.
id
,
issue2
.
id
,
issue1
.
id
]
)
end
end
end
...
...
@@ -888,9 +888,4 @@ describe API::Issues do
include_examples
'time tracking endpoints'
,
'issue'
end
def
expect_response_contain_exactly
(
*
items
)
expect
(
json_response
.
length
).
to
eq
(
items
.
size
)
expect
(
json_response
.
map
{
|
element
|
element
[
'id'
]
}).
to
contain_exactly
(
*
items
.
map
(
&
:id
))
end
end
spec/requests/api/merge_requests_spec.rb
View file @
af6762f7
...
...
@@ -41,8 +41,7 @@ describe API::MergeRequests do
it
'returns merge requests for public projects'
do
get
api
(
endpoint_path
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
end
end
...
...
@@ -87,10 +86,11 @@ describe API::MergeRequests do
it
'returns an array of all merge_requests'
do
get
api
(
endpoint_path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
4
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
])
expect
(
json_response
.
last
[
'title'
]).
to
eq
(
merge_request
.
title
)
expect
(
json_response
.
last
).
to
have_key
(
'web_url'
)
expect
(
json_response
.
last
[
'sha'
]).
to
eq
(
merge_request
.
diff_head_sha
)
...
...
@@ -111,7 +111,7 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
_successful_response_with_paginated_array
expect
(
json_response
.
last
[
'labels'
].
pluck
(
'name'
)).
to
eq
([
label2
.
title
,
label
.
title
])
expect
(
json_response
.
last
[
'labels'
].
first
).
to
match_schema
(
'/public_api/v4/label_basic'
)
end
...
...
@@ -139,11 +139,11 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
])
expect
(
json_response
.
last
.
keys
).
to
match_array
(
%w(id iid title web_url created_at description project_id state updated_at)
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
json_response
.
last
[
'iid'
]).
to
eq
(
merge_request
.
iid
)
expect
(
json_response
.
last
[
'title'
]).
to
eq
(
merge_request
.
title
)
expect
(
json_response
.
last
).
to
have_key
(
'web_url'
)
...
...
@@ -157,10 +157,10 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
]
)
expect
(
json_response
.
last
[
'title'
]).
to
eq
(
merge_request
.
title
)
end
...
...
@@ -169,10 +169,7 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect_paginated_array_response
([
merge_request
.
id
])
expect
(
json_response
.
last
[
'title'
]).
to
eq
(
merge_request
.
title
)
end
...
...
@@ -181,10 +178,7 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect_paginated_array_response
([
merge_request_closed
.
id
])
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
merge_request_closed
.
title
)
end
...
...
@@ -193,10 +187,7 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect_paginated_array_response
([
merge_request_merged
.
id
])
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
merge_request_merged
.
title
)
end
...
...
@@ -210,17 +201,13 @@ describe API::MergeRequests do
it
'returns an empty array if no issue matches milestone'
do
get
api
(
endpoint_path
,
user
),
params:
{
milestone:
'1.0.0'
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
expect_empty_array_response
end
it
'returns an empty array if milestone does not exist'
do
get
api
(
endpoint_path
,
user
),
params:
{
milestone:
'foo'
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
expect_empty_array_response
end
it
'returns an array of merge requests in given milestone'
do
...
...
@@ -234,9 +221,7 @@ describe API::MergeRequests do
it
'returns an array of merge requests matching state in milestone'
do
get
api
(
endpoint_path
,
user
),
params:
{
milestone:
'0.9'
,
state:
'closed'
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect_paginated_array_response
([
merge_request_closed
.
id
])
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
merge_request_closed
.
id
)
end
...
...
@@ -248,8 +233,7 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
label2
.
title
,
label
.
title
])
end
...
...
@@ -259,9 +243,7 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
expect_empty_array_response
end
it
'returns an empty array if no merge request matches labels'
do
...
...
@@ -269,9 +251,7 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
expect_empty_array_response
end
it
'returns an array of labeled merge requests where all labels match'
do
...
...
@@ -279,8 +259,7 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
label2
.
title
,
label
.
title
])
end
...
...
@@ -288,8 +267,7 @@ describe API::MergeRequests do
it
'returns an array of merge requests with any label when filtering by any label'
do
get
api
(
endpoint_path
,
user
),
params:
{
labels:
[
"
#{
label
.
title
}
"
,
"
#{
label2
.
title
}
"
]
}
expect_paginated_array_response
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
label2
.
title
,
label
.
title
])
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
merge_request
.
id
)
...
...
@@ -298,8 +276,7 @@ describe API::MergeRequests do
it
'returns an array of merge requests with any label when filtering by any label'
do
get
api
(
endpoint_path
,
user
),
params:
{
labels:
[
"
#{
label
.
title
}
,
#{
label2
.
title
}
"
]
}
expect_paginated_array_response
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
label2
.
title
,
label
.
title
])
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
merge_request
.
id
)
...
...
@@ -308,7 +285,7 @@ describe API::MergeRequests do
it
'returns an array of merge requests with any label when filtering by any label'
do
get
api
(
endpoint_path
,
user
),
params:
{
labels:
IssuesFinder
::
FILTER_ANY
}
expect_
paginated_array_response
expect_
successful_response_with_paginated_array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
merge_request
.
id
)
end
...
...
@@ -316,10 +293,9 @@ describe API::MergeRequests do
it
'returns an array of merge requests without a label when filtering by no label'
do
get
api
(
endpoint_path
,
user
),
params:
{
labels:
IssuesFinder
::
FILTER_NONE
}
response_ids
=
json_response
.
map
{
|
merge_request
|
merge_request
[
'id'
]
}
expect_paginated_array_response
expect
(
response_ids
).
to
contain_exactly
(
merge_request_closed
.
id
,
merge_request_merged
.
id
,
merge_request_locked
.
id
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
])
end
end
...
...
@@ -339,10 +315,7 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
mr2
.
id
)
expect_paginated_array_response
([
mr2
.
id
])
end
context
'with ordering'
do
...
...
@@ -356,10 +329,10 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
_paginated_array_response
([
merge_request_closed
.
id
,
merge_request_locked
.
id
,
merge_request_merged
.
id
,
merge_request
.
id
]
)
response_dates
=
json_response
.
map
{
|
merge_request
|
merge_request
[
'created_at'
]
}
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
...
...
@@ -369,10 +342,10 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
_paginated_array_response
([
merge_request
.
id
,
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
]
)
response_dates
=
json_response
.
map
{
|
merge_request
|
merge_request
[
'created_at'
]
}
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
...
...
@@ -414,10 +387,10 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
_paginated_array_response
([
merge_request
.
id
,
merge_request_locked
.
id
,
merge_request_merged
.
id
,
merge_request_closed
.
id
]
)
response_dates
=
json_response
.
map
{
|
merge_request
|
merge_request
[
'updated_at'
]
}
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
...
...
@@ -427,10 +400,10 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
_paginated_array_response
([
merge_request_closed
.
id
,
merge_request_locked
.
id
,
merge_request_merged
.
id
,
merge_request
.
id
]
)
response_dates
=
json_response
.
map
{
|
merge_request
|
merge_request
[
'created_at'
]
}
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
...
...
@@ -440,7 +413,9 @@ describe API::MergeRequests do
it
'returns merge requests with the given source branch'
do
get
api
(
endpoint_path
,
user
),
params:
{
source_branch:
merge_request_closed
.
source_branch
,
state:
'all'
}
expect_response_contain_exactly
(
merge_request_closed
,
merge_request_merged
,
merge_request_locked
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
])
end
end
...
...
@@ -448,7 +423,9 @@ describe API::MergeRequests do
it
'returns merge requests with the given target branch'
do
get
api
(
endpoint_path
,
user
),
params:
{
target_branch:
merge_request_closed
.
target_branch
,
state:
'all'
}
expect_response_contain_exactly
(
merge_request_closed
,
merge_request_merged
,
merge_request_locked
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
])
end
end
end
...
...
@@ -471,7 +448,10 @@ describe API::MergeRequests do
it
'returns an array of all merge requests'
do
get
api
(
'/merge_requests'
,
user
),
params:
{
scope:
'all'
}
expect_paginated_array_response
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
])
end
it
"returns authentication error without any scope"
do
...
...
@@ -507,30 +487,23 @@ describe API::MergeRequests do
it
'returns an array of all merge requests except unauthorized ones'
do
get
api
(
'/merge_requests'
,
user
),
params:
{
scope: :all
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
map
{
|
mr
|
mr
[
'id'
]
})
.
to
contain_exactly
(
merge_request
.
id
,
merge_request_closed
.
id
,
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request2
.
id
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request2
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
])
end
it
"returns an array of no merge_requests when wip=yes"
do
get
api
(
"/merge_requests"
,
user
),
params:
{
wip:
'yes'
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
expect_empty_array_response
end
it
"returns an array of no merge_requests when wip=no"
do
get
api
(
"/merge_requests"
,
user
),
params:
{
wip:
'no'
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
map
{
|
mr
|
mr
[
'id'
]
})
.
to
contain_exactly
(
merge_request
.
id
,
merge_request_closed
.
id
,
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request2
.
id
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request2
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
])
end
it
'does not return unauthorized merge requests'
do
...
...
@@ -539,7 +512,9 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user
),
params:
{
scope: :all
}
expect_response_contain_exactly
(
merge_request2
,
merge_request_merged
,
merge_request_closed
,
merge_request
,
merge_request_locked
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request2
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
])
expect
(
json_response
.
map
{
|
mr
|
mr
[
'id'
]
}).
not_to
include
(
merge_request3
.
id
)
end
...
...
@@ -548,7 +523,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user2
)
expect_
response_ordered_exactly
(
merge_request3
)
expect_
paginated_array_response
([
merge_request3
.
id
]
)
end
it
'returns an array of merge requests authored by the given user'
do
...
...
@@ -556,7 +531,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user
),
params:
{
author_id:
user2
.
id
,
scope: :all
}
expect_
response_ordered_exactly
(
merge_request3
)
expect_
paginated_array_response
([
merge_request3
.
id
]
)
end
it
'returns an array of merge requests assigned to the given user'
do
...
...
@@ -564,7 +539,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user
),
params:
{
assignee_id:
user2
.
id
,
scope: :all
}
expect_
response_ordered_exactly
(
merge_request3
)
expect_
paginated_array_response
([
merge_request3
.
id
]
)
end
it
'returns an array of merge requests with no assignee'
do
...
...
@@ -572,7 +547,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user
),
params:
{
assignee_id:
'None'
,
scope: :all
}
expect_
response_ordered_exactly
(
merge_request3
)
expect_
paginated_array_response
([
merge_request3
.
id
]
)
end
it
'returns an array of merge requests with any assignee'
do
...
...
@@ -581,7 +556,10 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user
),
params:
{
assignee_id:
'Any'
,
scope: :all
}
expect_response_contain_exactly
(
merge_request
,
merge_request2
,
merge_request_closed
,
merge_request_merged
,
merge_request_locked
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request2
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
])
end
it
'returns an array of merge requests assigned to me'
do
...
...
@@ -589,7 +567,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user2
),
params:
{
scope:
'assigned_to_me'
}
expect_
response_ordered_exactly
(
merge_request3
)
expect_
paginated_array_response
([
merge_request3
.
id
]
)
end
it
'returns an array of merge requests assigned to me (kebab-case)'
do
...
...
@@ -597,7 +575,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user2
),
params:
{
scope:
'assigned-to-me'
}
expect_
response_ordered_exactly
(
merge_request3
)
expect_
paginated_array_response
([
merge_request3
.
id
]
)
end
it
'returns an array of merge requests created by me'
do
...
...
@@ -605,7 +583,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user2
),
params:
{
scope:
'created_by_me'
}
expect_
response_ordered_exactly
(
merge_request3
)
expect_
paginated_array_response
([
merge_request3
.
id
]
)
end
it
'returns an array of merge requests created by me (kebab-case)'
do
...
...
@@ -613,7 +591,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user2
),
params:
{
scope:
'created-by-me'
}
expect_
response_ordered_exactly
(
merge_request3
)
expect_
paginated_array_response
([
merge_request3
.
id
]
)
end
it
'returns merge requests reacted by the authenticated user by the given emoji'
do
...
...
@@ -622,14 +600,16 @@ describe API::MergeRequests do
get
api
(
'/merge_requests'
,
user2
),
params:
{
my_reaction_emoji:
award_emoji
.
name
,
scope:
'all'
}
expect_
response_ordered_exactly
(
merge_request3
)
expect_
paginated_array_response
([
merge_request3
.
id
]
)
end
context
'source_branch param'
do
it
'returns merge requests with the given source branch'
do
get
api
(
'/merge_requests'
,
user
),
params:
{
source_branch:
merge_request_closed
.
source_branch
,
state:
'all'
}
expect_response_contain_exactly
(
merge_request_closed
,
merge_request_merged
,
merge_request_locked
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
])
end
end
...
...
@@ -637,7 +617,9 @@ describe API::MergeRequests do
it
'returns merge requests with the given target branch'
do
get
api
(
'/merge_requests'
,
user
),
params:
{
target_branch:
merge_request_closed
.
target_branch
,
state:
'all'
}
expect_response_contain_exactly
(
merge_request_closed
,
merge_request_merged
,
merge_request_locked
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
])
end
end
...
...
@@ -646,7 +628,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests?created_before=2000-01-02T00:00:00.060Z'
,
user
)
expect_
response_ordered_exactly
(
merge_request2
)
expect_
paginated_array_response
([
merge_request2
.
id
]
)
end
it
'returns merge requests created after a specific date'
do
...
...
@@ -654,7 +636,7 @@ describe API::MergeRequests do
get
api
(
"/merge_requests?created_after=
#{
merge_request2
.
created_at
}
"
,
user
)
expect_
response_ordered_exactly
(
merge_request2
)
expect_
paginated_array_response
([
merge_request2
.
id
]
)
end
it
'returns merge requests updated before a specific date'
do
...
...
@@ -662,7 +644,7 @@ describe API::MergeRequests do
get
api
(
'/merge_requests?updated_before=2000-01-02T00:00:00.060Z'
,
user
)
expect_
response_ordered_exactly
(
merge_request2
)
expect_
paginated_array_response
([
merge_request2
.
id
]
)
end
it
'returns merge requests updated after a specific date'
do
...
...
@@ -670,7 +652,7 @@ describe API::MergeRequests do
get
api
(
"/merge_requests?updated_after=
#{
merge_request2
.
updated_at
}
"
,
user
)
expect_
response_ordered_exactly
(
merge_request2
)
expect_
paginated_array_response
([
merge_request2
.
id
]
)
end
context
'search params'
do
...
...
@@ -681,25 +663,25 @@ describe API::MergeRequests do
it
'returns merge requests matching given search string for title'
do
get
api
(
"/merge_requests"
,
user
),
params:
{
search:
merge_request
.
title
}
expect_
response_ordered_exactly
(
merge_request
)
expect_
paginated_array_response
([
merge_request
.
id
]
)
end
it
'returns merge requests matching given search string for title and scoped in title'
do
get
api
(
"/merge_requests"
,
user
),
params:
{
search:
merge_request
.
title
,
in:
'title'
}
expect_
response_ordered_exactly
(
merge_request
)
expect_
paginated_array_response
([
merge_request
.
id
]
)
end
it
'returns an empty array if no merge reques matches given search string for description and scoped in title'
do
it
'returns an empty array if no merge reques
t
matches given search string for description and scoped in title'
do
get
api
(
"/merge_requests"
,
user
),
params:
{
search:
merge_request
.
description
,
in:
'title'
}
expect_
response_contain_exactly
expect_
empty_array_response
end
it
'returns merge requests for project matching given search string for description'
do
get
api
(
"/merge_requests"
,
user
),
params:
{
project_id:
project
.
id
,
search:
merge_request
.
description
}
expect_
response_ordered_exactly
(
merge_request
)
expect_
paginated_array_response
([
merge_request
.
id
]
)
end
end
...
...
@@ -707,7 +689,7 @@ describe API::MergeRequests do
it
'returns merge requests with the given state'
do
get
api
(
'/merge_requests'
,
user
),
params:
{
state:
'locked'
}
expect_
response_contain_exactly
(
merge_request_locked
)
expect_
paginated_array_response
([
merge_request_locked
.
id
]
)
end
end
end
...
...
@@ -729,18 +711,13 @@ describe API::MergeRequests do
it
"returns an array of no merge_requests when wip=yes"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
),
params:
{
wip:
'yes'
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
expect_empty_array_response
end
it
'returns merge_request by "iids" array'
do
get
api
(
endpoint_path
,
user
),
params:
{
iids:
[
merge_request
.
iid
,
merge_request_closed
.
iid
]
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
expect_paginated_array_response
([
merge_request_closed
.
id
,
merge_request
.
id
])
expect
(
json_response
.
first
[
'title'
]).
to
eq
merge_request_closed
.
title
expect
(
json_response
.
first
[
'id'
]).
to
eq
merge_request_closed
.
id
end
...
...
@@ -815,12 +792,10 @@ describe API::MergeRequests do
it
'returns an array excluding merge_requests from archived projects'
do
get
api
(
endpoint_path
,
user
)
expect_response_contain_exactly
(
merge_request_merged
,
merge_request_locked
,
merge_request_closed
,
merge_request
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
])
end
context
'with non_archived param set as false'
do
...
...
@@ -829,13 +804,10 @@ describe API::MergeRequests do
get
api
(
path
,
user
)
expect_response_contain_exactly
(
merge_request_merged
,
merge_request_locked
,
merge_request_closed
,
merge_request
,
merge_request_archived
)
expect_paginated_array_response
([
merge_request_merged
.
id
,
merge_request_archived
.
id
,
merge_request_locked
.
id
,
merge_request_closed
.
id
,
merge_request
.
id
])
end
end
end
...
...
@@ -1079,9 +1051,7 @@ describe API::MergeRequests do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/commits"
,
user
)
commit
=
merge_request
.
commits
.
first
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
expect
(
json_response
.
size
).
to
eq
(
merge_request
.
commits
.
size
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
commit
.
id
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
commit
.
title
)
...
...
@@ -1105,9 +1075,7 @@ describe API::MergeRequests do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/context_commits"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
expect
(
json_response
.
size
).
to
eq
(
merge_request
.
context_commits
.
size
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
context_commit
.
id
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
context_commit
.
title
)
...
...
@@ -1147,9 +1115,7 @@ describe API::MergeRequests do
it
'returns a paginated array of corresponding pipelines'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/pipelines"
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
expect
(
json_response
.
count
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
pipeline
.
id
)
end
...
...
@@ -1395,7 +1361,7 @@ describe API::MergeRequests do
expect
(
json_response
[
'labels'
]).
to
eq
([])
end
x
it
'empty label param as array, does not add any labels'
do
it
'empty label param as array, does not add any labels'
do
params
[
:labels
]
=
[]
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
),
params:
params
...
...
@@ -2232,7 +2198,7 @@ describe API::MergeRequests do
expect
(
json_response
[
'labels'
]).
to
eq
[]
end
x
it
'empty label as array, removes labels'
do
it
'empty label as array, removes labels'
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
"
,
user
),
params:
{
title:
'new issue'
,
...
...
@@ -2240,7 +2206,6 @@ describe API::MergeRequests do
}
expect
(
response
.
status
).
to
eq
(
200
)
# fails, as grape ommits for some reason empty array as optional param value, so nothing it passed along
expect
(
json_response
[
'labels'
]).
to
eq
[]
end
...
...
@@ -2306,9 +2271,7 @@ describe API::MergeRequests do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
mr
.
iid
}
/closes_issues"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
issue
.
id
)
end
...
...
@@ -2316,10 +2279,7 @@ describe API::MergeRequests do
it
'returns an empty array when there are no issues to be closed'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/closes_issues"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
expect_empty_array_response
end
it
'handles external issues'
do
...
...
@@ -2332,9 +2292,7 @@ describe API::MergeRequests do
get
api
(
"/projects/
#{
jira_project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/closes_issues"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect_successful_response_with_paginated_array
expect
(
json_response
.
length
).
to
eq
(
2
)
expect
(
json_response
.
second
[
'title'
]).
to
eq
(
ext_issue
.
title
)
expect
(
json_response
.
second
[
'id'
]).
to
eq
(
ext_issue
.
id
)
...
...
@@ -2546,22 +2504,4 @@ describe API::MergeRequests do
merge_request_closed
.
save
merge_request_closed
end
def
expect_response_contain_exactly
(
*
items
)
expect_paginated_array_response
expect
(
json_response
.
length
).
to
eq
(
items
.
size
)
expect
(
json_response
.
map
{
|
element
|
element
[
'id'
]
}).
to
contain_exactly
(
*
items
.
map
(
&
:id
))
end
def
expect_response_ordered_exactly
(
*
items
)
expect_paginated_array_response
expect
(
json_response
.
length
).
to
eq
(
items
.
size
)
expect
(
json_response
.
map
{
|
element
|
element
[
'id'
]
}).
to
eq
(
items
.
map
(
&
:id
))
end
def
expect_paginated_array_response
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
end
end
spec/support/helpers/api_helpers.rb
View file @
af6762f7
...
...
@@ -40,6 +40,17 @@ module ApiHelpers
end
end
def
expect_empty_array_response
expect_successful_response_with_paginated_array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
def
expect_successful_response_with_paginated_array
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
end
def
expect_paginated_array_response
(
items
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
include_pagination_headers
...
...
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