2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe API::V3::Boards do
|
2018-03-17 18:26:18 +05:30
|
|
|
set(:user) { create(:user) }
|
|
|
|
set(:guest) { create(:user) }
|
|
|
|
set(:non_member) { create(:user) }
|
|
|
|
set(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
set(:dev_label) do
|
2017-08-17 22:00:37 +05:30
|
|
|
create(:label, title: 'Development', color: '#FFAABB', project: project)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
set(:test_label) do
|
2017-08-17 22:00:37 +05:30
|
|
|
create(:label, title: 'Testing', color: '#FFAACC', project: project)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
set(:dev_list) do
|
2017-08-17 22:00:37 +05:30
|
|
|
create(:list, label: dev_label, position: 1)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
set(:test_list) do
|
2017-08-17 22:00:37 +05:30
|
|
|
create(:list, label: test_label, position: 2)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
set(:board) do
|
2017-08-17 22:00:37 +05:30
|
|
|
create(:board, project: project, lists: [dev_list, test_list])
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_reporter(user)
|
|
|
|
project.add_guest(guest)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/boards" do
|
|
|
|
let(:base_url) { "/projects/#{project.id}/boards" }
|
|
|
|
|
|
|
|
context "when unauthenticated" do
|
|
|
|
it "returns authentication error" do
|
|
|
|
get v3_api(base_url)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when authenticated" do
|
|
|
|
it "returns the project issue board" do
|
|
|
|
get v3_api(base_url, user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-17 22:00:37 +05:30
|
|
|
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 v3_api(base_url, user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-17 22:00:37 +05:30
|
|
|
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 v3_api("/projects/#{project.id}/boards/22343/lists", user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-08-17 22:00:37 +05:30
|
|
|
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 v3_api("#{base_url}/#{dev_list.id}", non_member)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "rejects a user with guest role from deleting a list" do
|
|
|
|
delete v3_api("#{base_url}/#{dev_list.id}", guest)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 error if list id not found" do
|
|
|
|
delete v3_api("#{base_url}/44444", user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is project owner" do
|
2018-03-17 18:26:18 +05:30
|
|
|
set(:owner) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update(namespace: owner.namespace)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it "deletes the list if an admin requests it" do
|
|
|
|
delete v3_api("#{base_url}/#{dev_list.id}", owner)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|