Update tests for moving issues via API
This commit is contained in:
parent
482f67edb4
commit
2b036025d6
4 changed files with 51 additions and 30 deletions
|
@ -14,7 +14,7 @@ v 8.7.0 (unreleased)
|
||||||
- Expose label description in API (Mariusz Jachimowicz)
|
- Expose label description in API (Mariusz Jachimowicz)
|
||||||
- Allow back dating on issues when created through the API
|
- Allow back dating on issues when created through the API
|
||||||
- API: Ability to update a group (Robert Schilling)
|
- API: Ability to update a group (Robert Schilling)
|
||||||
- API: Ability to move issues
|
- API: Ability to move issues (Robert Schilling)
|
||||||
- Fix Error 500 after renaming a project path (Stan Hu)
|
- Fix Error 500 after renaming a project path (Stan Hu)
|
||||||
- Fix avatar stretching by providing a cropping feature
|
- Fix avatar stretching by providing a cropping feature
|
||||||
- API: Expose `subscribed` for issues and merge requests (Robert Schilling)
|
- API: Expose `subscribed` for issues and merge requests (Robert Schilling)
|
||||||
|
|
|
@ -353,7 +353,11 @@ curl -X DELETE -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.c
|
||||||
|
|
||||||
## Move an issue
|
## Move an issue
|
||||||
|
|
||||||
Moves an issue to a different project. If the operation is successful, a status code `200` together with moved issue is returned. If the project, issue, or target project is not found, error `404` is returned. If the target project equals the source project or the user has insufficient permissions to move an issue, error `400` together with an explaining error message is returned.
|
Moves an issue to a different project. If the operation is successful, a status
|
||||||
|
code `201` together with moved issue is returned. If the project, issue, or
|
||||||
|
target project is not found, error `404` is returned. If the target project
|
||||||
|
equals the source project or the user has insufficient permissions to move an
|
||||||
|
issue, error `400` together with an explaining error message is returned.
|
||||||
|
|
||||||
```
|
```
|
||||||
POST /projects/:id/issues/:issue_id/move
|
POST /projects/:id/issues/:issue_id/move
|
||||||
|
@ -363,7 +367,7 @@ POST /projects/:id/issues/:issue_id/move
|
||||||
| --------- | ---- | -------- | ----------- |
|
| --------- | ---- | -------- | ----------- |
|
||||||
| `id` | integer | yes | The ID of a project |
|
| `id` | integer | yes | The ID of a project |
|
||||||
| `issue_id` | integer | yes | The ID of a project's issue |
|
| `issue_id` | integer | yes | The ID of a project's issue |
|
||||||
| `new_project_id` | integer | yes | The ID the new project |
|
| `to_project_id` | integer | yes | The ID the new project |
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/4/issues/85/move
|
curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/4/issues/85/move
|
||||||
|
|
|
@ -198,20 +198,20 @@ module API
|
||||||
# Move an existing issue
|
# Move an existing issue
|
||||||
#
|
#
|
||||||
# Parameters:
|
# Parameters:
|
||||||
# id (required) - The ID of a project
|
# id (required) - The ID of a project
|
||||||
# issue_id (required) - The ID of a project issue
|
# issue_id (required) - The ID of a project issue
|
||||||
# new_project_id (required) - The ID of the new project
|
# to_project_id (required) - The ID of the new project
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# POST /projects/:id/issues/:issue_id/move
|
# POST /projects/:id/issues/:issue_id/move
|
||||||
post ":id/issues/:issue_id/move" do
|
post ':id/issues/:issue_id/move' do
|
||||||
required_attributes! [:new_project_id]
|
required_attributes! [:to_project_id]
|
||||||
|
|
||||||
issue = user_project.issues.find(params[:issue_id])
|
issue = user_project.issues.find(params[:issue_id])
|
||||||
new_project = Project.find(params[:new_project_id])
|
new_project = Project.find(params[:to_project_id])
|
||||||
|
|
||||||
begin
|
begin
|
||||||
issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project)
|
issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project)
|
||||||
present issue, with: Entities::Issue
|
present issue, with: Entities::Issue, current_user: current_user
|
||||||
rescue ::Issues::MoveService::MoveError => error
|
rescue ::Issues::MoveService::MoveError => error
|
||||||
render_api_error!(error.message, 400)
|
render_api_error!(error.message, 400)
|
||||||
end
|
end
|
||||||
|
|
|
@ -508,48 +508,65 @@ describe API::API, api: true do
|
||||||
|
|
||||||
it 'moves an issue' do
|
it 'moves an issue' do
|
||||||
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
||||||
new_project_id: target_project.id
|
to_project_id: target_project.id
|
||||||
|
|
||||||
expect(response.status).to eq(201)
|
expect(response.status).to eq(201)
|
||||||
expect(json_response['project_id']).to eq(target_project.id)
|
expect(json_response['project_id']).to eq(target_project.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an error if target and source project are the same' do
|
context 'when source and target projects are the same' do
|
||||||
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
it 'returns 400 when trying to move an issue' do
|
||||||
new_project_id: project.id
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
||||||
|
to_project_id: project.id
|
||||||
|
|
||||||
expect(response.status).to eq(400)
|
expect(response.status).to eq(400)
|
||||||
expect(json_response['message']).to eq('Cannot move issue to project it originates from!')
|
expect(json_response['message']).to eq('Cannot move issue to project it originates from!')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an error if I don't have the permission" do
|
context 'when the user does not have the permission to move issues' do
|
||||||
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
it 'returns 400 when trying to move an issue' do
|
||||||
new_project_id: target_project2.id
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
||||||
|
to_project_id: target_project2.id
|
||||||
|
|
||||||
expect(response.status).to eq(400)
|
expect(response.status).to eq(400)
|
||||||
expect(json_response['message']).to eq('Cannot move issue due to insufficient permissions!')
|
expect(json_response['message']).to eq('Cannot move issue due to insufficient permissions!')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'moves the issue to another namespace if I am admin' do
|
it 'moves the issue to another namespace if I am admin' do
|
||||||
post api("/projects/#{project.id}/issues/#{issue.id}/move", admin),
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", admin),
|
||||||
new_project_id: target_project2.id
|
to_project_id: target_project2.id
|
||||||
|
|
||||||
expect(response.status).to eq(201)
|
expect(response.status).to eq(201)
|
||||||
expect(json_response['project_id']).to eq(target_project2.id)
|
expect(json_response['project_id']).to eq(target_project2.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns 404 if the source issue is not found' do
|
context 'when issue does not exist' do
|
||||||
post api("/projects/#{project.id}/issues/123/move", user),
|
it 'returns 404 when trying to move an issue' do
|
||||||
new_project_id: target_project.id
|
post api("/projects/#{project.id}/issues/123/move", user),
|
||||||
|
to_project_id: target_project.id
|
||||||
|
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns 404 if the target project is not found' do
|
context 'when source project does not exist' do
|
||||||
post api("/projects/1234/issues/#{issue.id}/move", user),
|
it 'returns 404 when trying to move an issue' do
|
||||||
new_project_id: target_project.id
|
post api("/projects/123/issues/#{issue.id}/move", user),
|
||||||
|
to_project_id: target_project.id
|
||||||
|
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when target project does not exist' do
|
||||||
|
it 'returns 404 when trying to move an issue' do
|
||||||
|
post api("/projects/#{project.id}/issues/#{issue.id}/move", user),
|
||||||
|
to_project_id: 123
|
||||||
|
|
||||||
|
expect(response.status).to eq(404)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue