2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-01 19:23:16 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-31 18:18:35 +00:00
|
|
|
describe Boards::ListsController do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2016-10-06 20:14:39 +00:00
|
|
|
let(:board) { create(:board, project: project) }
|
2016-08-01 19:23:16 +00:00
|
|
|
let(:user) { create(:user) }
|
2016-08-08 22:03:41 +00:00
|
|
|
let(:guest) { create(:user) }
|
2016-08-01 19:23:16 +00:00
|
|
|
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_guest(guest)
|
2016-08-01 19:23:16 +00:00
|
|
|
end
|
2016-08-15 22:50:23 +00:00
|
|
|
|
2016-08-17 14:55:12 +00:00
|
|
|
describe 'GET index' do
|
2016-08-15 22:50:23 +00:00
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
read_board_list user: user, board: board
|
2016-08-15 22:50:23 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-15 22:50:23 +00:00
|
|
|
expect(response.content_type).to eq 'application/json'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a list of board lists' do
|
|
|
|
create(:list, board: board)
|
|
|
|
|
2016-10-05 22:25:29 +00:00
|
|
|
read_board_list user: user, board: board
|
2016-08-15 22:50:23 +00:00
|
|
|
|
|
|
|
parsed_response = JSON.parse(response.body)
|
|
|
|
|
2016-08-16 14:13:21 +00:00
|
|
|
expect(response).to match_response_schema('lists')
|
2017-05-31 14:34:02 +00:00
|
|
|
expect(parsed_response.length).to eq 3
|
2016-08-15 22:50:23 +00:00
|
|
|
end
|
|
|
|
|
2016-08-17 15:15:51 +00:00
|
|
|
context 'with unauthorized user' do
|
2019-01-17 17:40:37 +00:00
|
|
|
let(:unauth_user) { create(:user) }
|
2016-08-15 22:50:23 +00:00
|
|
|
|
2016-08-22 14:50:41 +00:00
|
|
|
it 'returns a forbidden 403 response' do
|
2019-01-17 17:40:37 +00:00
|
|
|
read_board_list user: unauth_user, board: board
|
2016-08-15 22:50:23 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-17 15:15:51 +00:00
|
|
|
end
|
2016-08-15 22:50:23 +00:00
|
|
|
end
|
|
|
|
|
2016-10-05 22:25:29 +00:00
|
|
|
def read_board_list(user:, board:)
|
2016-08-15 22:50:23 +00:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-12-17 22:52:17 +00:00
|
|
|
get :index, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
board_id: board.to_param
|
|
|
|
},
|
2016-08-15 22:50:23 +00:00
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
end
|
2016-08-01 19:23:16 +00:00
|
|
|
|
2016-08-17 14:55:12 +00:00
|
|
|
describe 'POST create' do
|
2016-08-08 22:03:41 +00:00
|
|
|
context 'with valid params' do
|
2016-08-22 14:50:41 +00:00
|
|
|
let(:label) { create(:label, project: project, name: 'Development') }
|
|
|
|
|
2016-08-01 19:23:16 +00:00
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
create_board_list user: user, board: board, label_id: label.id
|
2016-08-01 19:23:16 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-01 19:23:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the created list' do
|
2016-10-05 22:25:29 +00:00
|
|
|
create_board_list user: user, board: board, label_id: label.id
|
2016-08-01 19:23:16 +00:00
|
|
|
|
|
|
|
expect(response).to match_response_schema('list')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid params' do
|
2016-08-22 14:50:41 +00:00
|
|
|
context 'when label is nil' do
|
|
|
|
it 'returns a not found 404 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
create_board_list user: user, board: board, label_id: nil
|
2016-08-22 14:50:41 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-22 14:50:41 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-01 19:23:16 +00:00
|
|
|
|
2016-08-22 14:50:41 +00:00
|
|
|
context 'when label that does not belongs to project' do
|
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
label = create(:label, name: 'Development')
|
2016-08-01 19:23:16 +00:00
|
|
|
|
2016-10-05 22:25:29 +00:00
|
|
|
create_board_list user: user, board: board, label_id: label.id
|
2016-08-22 14:50:41 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-22 14:50:41 +00:00
|
|
|
end
|
2016-08-01 19:23:16 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-03 02:01:45 +00:00
|
|
|
|
2016-08-08 22:03:41 +00:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 14:50:41 +00:00
|
|
|
it 'returns a forbidden 403 response' do
|
|
|
|
label = create(:label, project: project, name: 'Development')
|
2016-08-08 22:03:41 +00:00
|
|
|
|
2016-10-05 22:25:29 +00:00
|
|
|
create_board_list user: guest, board: board, label_id: label.id
|
2016-08-08 22:03:41 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-08 22:03:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 22:25:29 +00:00
|
|
|
def create_board_list(user:, board:, label_id:)
|
2016-08-08 22:03:41 +00:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-12-17 22:52:17 +00:00
|
|
|
post :create, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
board_id: board.to_param,
|
|
|
|
list: { label_id: label_id }
|
|
|
|
},
|
2016-08-03 02:01:45 +00:00
|
|
|
format: :json
|
|
|
|
end
|
2016-08-01 19:23:16 +00:00
|
|
|
end
|
2016-08-01 20:11:56 +00:00
|
|
|
|
2016-08-17 14:55:12 +00:00
|
|
|
describe 'PATCH update' do
|
2016-08-03 15:09:03 +00:00
|
|
|
let!(:planning) { create(:list, board: board, position: 0) }
|
|
|
|
let!(:development) { create(:list, board: board, position: 1) }
|
2016-08-01 20:11:56 +00:00
|
|
|
|
|
|
|
context 'with valid position' do
|
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
move user: user, board: board, list: planning, position: 1
|
2016-08-01 20:11:56 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-01 20:11:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'moves the list to the desired position' do
|
2016-10-05 22:25:29 +00:00
|
|
|
move user: user, board: board, list: planning, position: 1
|
2016-08-01 20:11:56 +00:00
|
|
|
|
2016-08-03 15:09:03 +00:00
|
|
|
expect(planning.reload.position).to eq 1
|
2016-08-01 20:11:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid position' do
|
2016-08-22 14:50:41 +00:00
|
|
|
it 'returns an unprocessable entity 422 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
move user: user, board: board, list: planning, position: 6
|
2016-08-01 20:11:56 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(422)
|
2016-08-01 20:11:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid list id' do
|
|
|
|
it 'returns a not found 404 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
move user: user, board: board, list: 999, position: 1
|
2016-08-01 20:11:56 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-01 20:11:56 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-03 02:01:45 +00:00
|
|
|
|
2016-08-08 22:03:41 +00:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 14:50:41 +00:00
|
|
|
it 'returns a forbidden 403 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
move user: guest, board: board, list: planning, position: 6
|
2016-08-08 22:03:41 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-08 22:03:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 22:25:29 +00:00
|
|
|
def move(user:, board:, list:, position:)
|
2016-08-08 22:03:41 +00:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-06-09 20:58:28 +00:00
|
|
|
params = { namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
board_id: board.to_param,
|
|
|
|
id: list.to_param,
|
|
|
|
list: { position: position },
|
|
|
|
format: :json }
|
|
|
|
|
2018-12-15 09:06:56 +00:00
|
|
|
patch :update, params: params, as: :json
|
2016-08-03 02:01:45 +00:00
|
|
|
end
|
2016-08-01 20:11:56 +00:00
|
|
|
end
|
2016-08-01 21:44:33 +00:00
|
|
|
|
2016-08-17 14:55:12 +00:00
|
|
|
describe 'DELETE destroy' do
|
2016-08-08 22:03:41 +00:00
|
|
|
let!(:planning) { create(:list, board: board, position: 0) }
|
2016-08-01 21:44:33 +00:00
|
|
|
|
2016-08-08 22:03:41 +00:00
|
|
|
context 'with valid list id' do
|
2016-08-01 21:44:33 +00:00
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
remove_board_list user: user, board: board, list: planning
|
2016-08-01 21:44:33 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-01 21:44:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes list from board' do
|
2016-10-05 22:25:29 +00:00
|
|
|
expect { remove_board_list user: user, board: board, list: planning }.to change(board.lists, :size).by(-1)
|
2016-08-01 21:44:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid list id' do
|
|
|
|
it 'returns a not found 404 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
remove_board_list user: user, board: board, list: 999
|
2016-08-01 21:44:33 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-01 21:44:33 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-03 02:01:45 +00:00
|
|
|
|
2016-08-08 22:03:41 +00:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 14:50:41 +00:00
|
|
|
it 'returns a forbidden 403 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
remove_board_list user: guest, board: board, list: planning
|
2016-08-08 22:03:41 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-08 22:03:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 22:25:29 +00:00
|
|
|
def remove_board_list(user:, board:, list:)
|
2016-08-08 22:03:41 +00:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-12-17 22:52:17 +00:00
|
|
|
delete :destroy, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
board_id: board.to_param,
|
|
|
|
id: list.to_param
|
|
|
|
},
|
2016-08-03 02:01:45 +00:00
|
|
|
format: :json
|
|
|
|
end
|
2016-08-01 20:11:56 +00:00
|
|
|
end
|
2016-08-08 19:49:09 +00:00
|
|
|
|
2016-08-17 14:55:12 +00:00
|
|
|
describe 'POST generate' do
|
2016-08-08 19:49:09 +00:00
|
|
|
context 'when board lists is empty' do
|
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
generate_default_lists user: user, board: board
|
2016-08-08 19:49:09 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-08 19:49:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the defaults lists' do
|
2016-10-05 22:25:29 +00:00
|
|
|
generate_default_lists user: user, board: board
|
2016-08-08 19:49:09 +00:00
|
|
|
|
2016-08-16 14:13:21 +00:00
|
|
|
expect(response).to match_response_schema('lists')
|
2016-08-08 19:49:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when board lists is not empty' do
|
2016-08-22 14:50:41 +00:00
|
|
|
it 'returns an unprocessable entity 422 response' do
|
2016-08-08 19:49:09 +00:00
|
|
|
create(:list, board: board)
|
|
|
|
|
2016-10-05 22:25:29 +00:00
|
|
|
generate_default_lists user: user, board: board
|
2016-08-08 19:49:09 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(422)
|
2016-08-08 19:49:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-08 22:03:41 +00:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 14:50:41 +00:00
|
|
|
it 'returns a forbidden 403 response' do
|
2016-10-05 22:25:29 +00:00
|
|
|
generate_default_lists user: guest, board: board
|
2016-08-08 22:03:41 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-08 22:03:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-06 02:50:35 +00:00
|
|
|
def generate_default_lists(user:, board:)
|
2016-08-08 22:03:41 +00:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-12-17 22:52:17 +00:00
|
|
|
post :generate, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
board_id: board.to_param
|
|
|
|
},
|
2016-08-08 19:49:09 +00:00
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
end
|
2016-08-01 19:23:16 +00:00
|
|
|
end
|