2016-10-02 23:12:59 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-21 16:32:02 -04:00
|
|
|
describe API::Boards do
|
2017-09-19 10:11:23 -04:00
|
|
|
set(:user) { create(:user) }
|
|
|
|
set(:user2) { create(:user) }
|
|
|
|
set(:non_member) { create(:user) }
|
|
|
|
set(:guest) { create(:user) }
|
|
|
|
set(:admin) { create(:user, :admin) }
|
|
|
|
set(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) }
|
|
|
|
|
|
|
|
set(:dev_label) do
|
2016-10-02 23:12:59 -04:00
|
|
|
create(:label, title: 'Development', color: '#FFAABB', project: project)
|
|
|
|
end
|
|
|
|
|
2017-09-19 10:11:23 -04:00
|
|
|
set(:test_label) do
|
2016-10-02 23:12:59 -04:00
|
|
|
create(:label, title: 'Testing', color: '#FFAACC', project: project)
|
|
|
|
end
|
|
|
|
|
2017-09-19 10:11:23 -04:00
|
|
|
set(:ux_label) do
|
2016-10-02 23:12:59 -04:00
|
|
|
create(:label, title: 'UX', color: '#FF0000', project: project)
|
|
|
|
end
|
|
|
|
|
2017-09-19 10:11:23 -04:00
|
|
|
set(:dev_list) do
|
2016-10-02 23:12:59 -04:00
|
|
|
create(:list, label: dev_label, position: 1)
|
|
|
|
end
|
|
|
|
|
2017-09-19 10:11:23 -04:00
|
|
|
set(:test_list) do
|
2016-10-02 23:12:59 -04:00
|
|
|
create(:list, label: test_label, position: 2)
|
|
|
|
end
|
|
|
|
|
2017-09-19 10:11:23 -04:00
|
|
|
set(:board) do
|
2016-10-02 23:12:59 -04:00
|
|
|
create(:board, project: project, lists: [dev_list, test_list])
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :reporter]
|
|
|
|
project.team << [guest, :guest]
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/boards" do
|
|
|
|
let(:base_url) { "/projects/#{project.id}/boards" }
|
|
|
|
|
|
|
|
context "when unauthenticated" do
|
|
|
|
it "returns authentication error" do
|
|
|
|
get api(base_url)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when authenticated" do
|
|
|
|
it "returns the project issue board" do
|
|
|
|
get api(base_url, user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-10-02 23:12:59 -04:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['id']).to eq(board.id)
|
|
|
|
expect(json_response.first['lists']).to be_an Array
|
|
|
|
expect(json_response.first['lists'].length).to eq(2)
|
|
|
|
expect(json_response.first['lists'].last).to have_key('position')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/boards/:board_id/lists" do
|
|
|
|
let(:base_url) { "/projects/#{project.id}/boards/#{board.id}/lists" }
|
|
|
|
|
|
|
|
it 'returns issue board lists' do
|
|
|
|
get api(base_url, user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-10-02 23:12:59 -04:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.first['label']['name']).to eq(dev_label.title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 if board not found' do
|
|
|
|
get api("/projects/#{project.id}/boards/22343/lists", user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/boards/:board_id/lists/:list_id" do
|
|
|
|
let(:base_url) { "/projects/#{project.id}/boards/#{board.id}/lists" }
|
|
|
|
|
|
|
|
it 'returns a list' do
|
|
|
|
get api("#{base_url}/#{dev_list.id}", user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-10-02 23:12:59 -04:00
|
|
|
expect(json_response['id']).to eq(dev_list.id)
|
|
|
|
expect(json_response['label']['name']).to eq(dev_label.title)
|
|
|
|
expect(json_response['position']).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 if list not found' do
|
|
|
|
get api("#{base_url}/5324", user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/board/lists" do
|
|
|
|
let(:base_url) { "/projects/#{project.id}/boards/#{board.id}/lists" }
|
|
|
|
|
2016-10-13 17:48:59 -04:00
|
|
|
it 'creates a new issue board list for group labels' do
|
|
|
|
group = create(:group)
|
|
|
|
group_label = create(:group_label, group: group)
|
|
|
|
project.update(group: group)
|
|
|
|
|
|
|
|
post api(base_url, user), label_id: group_label.id
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(201)
|
2016-10-13 17:48:59 -04:00
|
|
|
expect(json_response['label']['name']).to eq(group_label.title)
|
|
|
|
expect(json_response['position']).to eq(3)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new issue board list for project labels' do
|
|
|
|
post api(base_url, user), label_id: ux_label.id
|
2016-10-02 23:12:59 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(201)
|
2016-10-02 23:12:59 -04:00
|
|
|
expect(json_response['label']['name']).to eq(ux_label.title)
|
|
|
|
expect(json_response['position']).to eq(3)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 400 when creating a new list if label_id is invalid' do
|
2016-10-13 17:48:59 -04:00
|
|
|
post api(base_url, user), label_id: 23423
|
2016-10-02 23:12:59 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(400)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
2016-10-13 17:48:59 -04:00
|
|
|
it 'returns 403 for project members with guest role' do
|
|
|
|
put api("#{base_url}/#{test_list.id}", guest), position: 1
|
2016-10-02 23:12:59 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /projects/:id/boards/:board_id/lists/:list_id to update only position" do
|
|
|
|
let(:base_url) { "/projects/#{project.id}/boards/#{board.id}/lists" }
|
|
|
|
|
|
|
|
it "updates a list" do
|
|
|
|
put api("#{base_url}/#{test_list.id}", user),
|
|
|
|
position: 1
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-10-02 23:12:59 -04:00
|
|
|
expect(json_response['position']).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 error if list id not found" do
|
|
|
|
put api("#{base_url}/44444", user),
|
|
|
|
position: 1
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 403 for project members with guest role" do
|
|
|
|
put api("#{base_url}/#{test_list.id}", guest),
|
|
|
|
position: 1
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "DELETE /projects/:id/board/lists/:list_id" do
|
|
|
|
let(:base_url) { "/projects/#{project.id}/boards/#{board.id}/lists" }
|
|
|
|
|
|
|
|
it "rejects a non member from deleting a list" do
|
|
|
|
delete api("#{base_url}/#{dev_list.id}", non_member)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "rejects a user with guest role from deleting a list" do
|
|
|
|
delete api("#{base_url}/#{dev_list.id}", guest)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 error if list id not found" do
|
|
|
|
delete api("#{base_url}/44444", user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is project owner" do
|
2017-09-19 10:11:23 -04:00
|
|
|
set(:owner) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update(namespace: owner.namespace)
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
|
|
|
|
it "deletes the list if an admin requests it" do
|
|
|
|
delete api("#{base_url}/#{dev_list.id}", owner)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(204)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
2017-08-24 12:03:39 -04:00
|
|
|
|
|
|
|
it_behaves_like '412 response' do
|
|
|
|
let(:request) { api("#{base_url}/#{dev_list.id}", owner) }
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|