2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-01 15:23:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe Boards::ListsController do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-10-06 16:14:39 -04:00
|
|
|
let(:board) { create(:board, project: project) }
|
2016-08-01 15:23:16 -04:00
|
|
|
let(:user) { create(:user) }
|
2016-08-08 18:03:41 -04:00
|
|
|
let(:guest) { create(:user) }
|
2016-08-01 15:23:16 -04:00
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_guest(guest)
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|
2016-08-15 18:50:23 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'GET index' do
|
2019-09-27 14:06:20 -04:00
|
|
|
before do
|
|
|
|
create(:list, board: board)
|
|
|
|
end
|
|
|
|
|
2016-08-15 18:50:23 -04:00
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
read_board_list user: user, board: board
|
2016-08-15 18:50:23 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-08-15 18:50:23 -04:00
|
|
|
expect(response.content_type).to eq 'application/json'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a list of board lists' do
|
2016-10-05 18:25:29 -04:00
|
|
|
read_board_list user: user, board: board
|
2016-08-15 18:50:23 -04:00
|
|
|
|
2016-08-16 10:13:21 -04:00
|
|
|
expect(response).to match_response_schema('lists')
|
2019-07-16 04:03:49 -04:00
|
|
|
expect(json_response.length).to eq 3
|
2016-08-15 18:50:23 -04:00
|
|
|
end
|
|
|
|
|
2019-09-27 14:06:20 -04:00
|
|
|
context 'when another user has list preferences' do
|
|
|
|
before do
|
|
|
|
board.lists.first.update_preferences_for(guest, collapsed: true)
|
|
|
|
end
|
2019-08-28 16:18:40 -04:00
|
|
|
|
2019-09-27 14:06:20 -04:00
|
|
|
it 'returns the complete list of board lists' do
|
|
|
|
read_board_list user: user, board: board
|
2019-08-28 16:18:40 -04:00
|
|
|
|
2019-09-27 14:06:20 -04:00
|
|
|
expect(json_response.length).to eq 3
|
|
|
|
end
|
2019-08-28 16:18:40 -04:00
|
|
|
end
|
|
|
|
|
2016-08-17 11:15:51 -04:00
|
|
|
context 'with unauthorized user' do
|
2019-01-17 12:40:37 -05:00
|
|
|
let(:unauth_user) { create(:user) }
|
2016-08-15 18:50:23 -04:00
|
|
|
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns a forbidden 403 response' do
|
2019-01-17 12:40:37 -05:00
|
|
|
read_board_list user: unauth_user, board: board
|
2016-08-15 18:50:23 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-08-17 11:15:51 -04:00
|
|
|
end
|
2016-08-15 18:50:23 -04:00
|
|
|
end
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
def read_board_list(user:, board:)
|
2016-08-15 18:50:23 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
board_id: board.to_param
|
|
|
|
},
|
2016-08-15 18:50:23 -04:00
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'POST create' do
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with valid params' do
|
2016-08-22 10:50:41 -04:00
|
|
|
let(:label) { create(:label, project: project, name: 'Development') }
|
|
|
|
|
2016-08-01 15:23:16 -04:00
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: user, board: board, label_id: label.id
|
2016-08-01 15:23:16 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the created list' do
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: user, board: board, label_id: label.id
|
2016-08-01 15:23:16 -04:00
|
|
|
|
|
|
|
expect(response).to match_response_schema('list')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid params' do
|
2016-08-22 10:50:41 -04:00
|
|
|
context 'when label is nil' do
|
|
|
|
it 'returns a not found 404 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: user, board: board, label_id: nil
|
2016-08-22 10:50:41 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-08-22 10:50:41 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
|
2016-08-22 10:50:41 -04: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 15:23:16 -04:00
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: user, board: board, label_id: label.id
|
2016-08-22 10:50:41 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-08-22 10:50:41 -04:00
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-02 22:01:45 -04:00
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns a forbidden 403 response' do
|
|
|
|
label = create(:label, project: project, name: 'Development')
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: guest, board: board, label_id: label.id
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
def create_board_list(user:, board:, label_id:)
|
2016-08-08 18:03:41 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-12-17 17:52:17 -05: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-02 22:01:45 -04:00
|
|
|
format: :json
|
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'PATCH update' do
|
2016-08-03 11:09:03 -04:00
|
|
|
let!(:planning) { create(:list, board: board, position: 0) }
|
|
|
|
let!(:development) { create(:list, board: board, position: 1) }
|
2016-08-01 16:11:56 -04:00
|
|
|
|
|
|
|
context 'with valid position' do
|
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
move user: user, board: board, list: planning, position: 1
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'moves the list to the desired position' do
|
2016-10-05 18:25:29 -04:00
|
|
|
move user: user, board: board, list: planning, position: 1
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2016-08-03 11:09:03 -04:00
|
|
|
expect(planning.reload.position).to eq 1
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid position' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns an unprocessable entity 422 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
move user: user, board: board, list: planning, position: 6
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid list id' do
|
|
|
|
it 'returns a not found 404 response' do
|
2020-04-01 11:07:45 -04:00
|
|
|
move user: user, board: board, list: non_existing_record_id, position: 1
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-02 22:01:45 -04:00
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with unauthorized user' do
|
2019-09-23 17:06:29 -04:00
|
|
|
it 'returns a 422 unprocessable entity response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
move user: guest, board: board, list: planning, position: 6
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-28 16:18:40 -04:00
|
|
|
context 'with collapsed preference' do
|
|
|
|
it 'saves collapsed preference for user' do
|
|
|
|
save_setting user: user, board: board, list: planning, setting: { collapsed: true }
|
|
|
|
|
|
|
|
expect(planning.preferences_for(user).collapsed).to eq(true)
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-08-28 16:18:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves not collapsed preference for user' do
|
|
|
|
save_setting user: user, board: board, list: planning, setting: { collapsed: false }
|
|
|
|
|
|
|
|
expect(planning.preferences_for(user).collapsed).to eq(false)
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-08-28 16:18:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-18 10:02:45 -04:00
|
|
|
context 'with a list_type other than :label' do
|
|
|
|
let!(:closed) { create(:closed_list, board: board, position: 2) }
|
|
|
|
|
|
|
|
it 'saves collapsed preference for user' do
|
|
|
|
save_setting user: user, board: board, list: closed, setting: { collapsed: true }
|
|
|
|
|
|
|
|
expect(closed.preferences_for(user).collapsed).to eq(true)
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-18 10:02:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves not collapsed preference for user' do
|
|
|
|
save_setting user: user, board: board, list: closed, setting: { collapsed: false }
|
|
|
|
|
|
|
|
expect(closed.preferences_for(user).collapsed).to eq(false)
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-18 10:02:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
def move(user:, board:, list:, position:)
|
2016-08-08 18:03:41 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-06-09 16:58:28 -04: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 04:06:56 -05:00
|
|
|
patch :update, params: params, as: :json
|
2016-08-02 22:01:45 -04:00
|
|
|
end
|
2019-08-28 16:18:40 -04:00
|
|
|
|
|
|
|
def save_setting(user:, board:, list:, setting: {})
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
params = { namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
board_id: board.to_param,
|
|
|
|
id: list.to_param,
|
|
|
|
list: setting,
|
|
|
|
format: :json }
|
|
|
|
|
|
|
|
patch :update, params: params, as: :json
|
|
|
|
end
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
2016-08-01 17:44:33 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'DELETE destroy' do
|
2016-08-08 18:03:41 -04:00
|
|
|
let!(:planning) { create(:list, board: board, position: 0) }
|
2016-08-01 17:44:33 -04:00
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with valid list id' do
|
2016-08-01 17:44:33 -04:00
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
remove_board_list user: user, board: board, list: planning
|
2016-08-01 17:44:33 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-08-01 17:44:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes list from board' do
|
2016-10-05 18:25:29 -04:00
|
|
|
expect { remove_board_list user: user, board: board, list: planning }.to change(board.lists, :size).by(-1)
|
2016-08-01 17:44:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid list id' do
|
|
|
|
it 'returns a not found 404 response' do
|
2020-04-01 11:07:45 -04:00
|
|
|
remove_board_list user: user, board: board, list: non_existing_record_id
|
2016-08-01 17:44:33 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-08-01 17:44:33 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-02 22:01:45 -04:00
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns a forbidden 403 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
remove_board_list user: guest, board: board, list: planning
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-24 08:09:37 -04:00
|
|
|
context 'with an error service response' do
|
|
|
|
it 'returns an unprocessable entity response' do
|
|
|
|
allow(Boards::Lists::DestroyService).to receive(:new)
|
|
|
|
.and_return(double(execute: ServiceResponse.error(message: 'error')))
|
|
|
|
|
|
|
|
remove_board_list user: user, board: board, list: planning
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
def remove_board_list(user:, board:, list:)
|
2016-08-08 18:03:41 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :destroy, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
board_id: board.to_param,
|
|
|
|
id: list.to_param
|
|
|
|
},
|
2016-08-02 22:01:45 -04:00
|
|
|
format: :json
|
|
|
|
end
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
2016-08-08 15:49:09 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'POST generate' do
|
2016-08-08 15:49:09 -04:00
|
|
|
context 'when board lists is empty' do
|
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
generate_default_lists user: user, board: board
|
2016-08-08 15:49:09 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-08-08 15:49:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the defaults lists' do
|
2016-10-05 18:25:29 -04:00
|
|
|
generate_default_lists user: user, board: board
|
2016-08-08 15:49:09 -04:00
|
|
|
|
2016-08-16 10:13:21 -04:00
|
|
|
expect(response).to match_response_schema('lists')
|
2016-08-08 15:49:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when board lists is not empty' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns an unprocessable entity 422 response' do
|
2016-08-08 15:49:09 -04:00
|
|
|
create(:list, board: board)
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
generate_default_lists user: user, board: board
|
2016-08-08 15:49:09 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
2016-08-08 15:49:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns a forbidden 403 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
generate_default_lists user: guest, board: board
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 22:50:35 -04:00
|
|
|
def generate_default_lists(user:, board:)
|
2016-08-08 18:03:41 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :generate, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
board_id: board.to_param
|
|
|
|
},
|
2016-08-08 15:49:09 -04:00
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|