debian-mirror-gitlab/spec/controllers/boards/lists_controller_spec.rb

321 lines
9.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Boards::ListsController do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2016-11-03 12:29:30 +05:30
let(:board) { create(:board, project: project) }
2016-09-13 17:45:13 +05:30
let(:user) { create(:user) }
let(:guest) { create(:user) }
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2018-03-17 18:26:18 +05:30
project.add_guest(guest)
2016-09-13 17:45:13 +05:30
end
describe 'GET index' do
2019-12-21 20:55:43 +05:30
before do
create(:list, board: board)
end
2016-09-13 17:45:13 +05:30
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
read_board_list user: user, board: board
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2016-09-13 17:45:13 +05:30
expect(response.content_type).to eq 'application/json'
end
it 'returns a list of board lists' do
2016-11-03 12:29:30 +05:30
read_board_list user: user, board: board
2016-09-13 17:45:13 +05:30
expect(response).to match_response_schema('lists')
2019-09-30 21:07:59 +05:30
expect(json_response.length).to eq 3
2016-09-13 17:45:13 +05:30
end
2019-12-21 20:55:43 +05:30
context 'when another user has list preferences' do
before do
board.lists.first.update_preferences_for(guest, collapsed: true)
end
2019-12-04 20:38:33 +05:30
2019-12-21 20:55:43 +05:30
it 'returns the complete list of board lists' do
read_board_list user: user, board: board
2019-12-04 20:38:33 +05:30
2019-12-21 20:55:43 +05:30
expect(json_response.length).to eq 3
end
2019-12-04 20:38:33 +05:30
end
2016-09-13 17:45:13 +05:30
context 'with unauthorized user' do
2019-03-02 22:35:43 +05:30
let(:unauth_user) { create(:user) }
2016-09-13 17:45:13 +05:30
2016-09-29 09:46:39 +05:30
it 'returns a forbidden 403 response' do
2019-03-02 22:35:43 +05:30
read_board_list user: unauth_user, board: board
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:forbidden)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def read_board_list(user:, board:)
2016-09-13 17:45:13 +05:30
sign_in(user)
2019-02-15 15:39:39 +05:30
get :index, params: {
namespace_id: project.namespace.to_param,
project_id: project,
board_id: board.to_param
},
2016-09-13 17:45:13 +05:30
format: :json
end
end
describe 'POST create' do
context 'with valid params' do
2016-09-29 09:46:39 +05:30
let(:label) { create(:label, project: project, name: 'Development') }
2016-09-13 17:45:13 +05:30
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
create_board_list user: user, board: board, label_id: label.id
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2016-09-13 17:45:13 +05:30
end
it 'returns the created list' do
2016-11-03 12:29:30 +05:30
create_board_list user: user, board: board, label_id: label.id
2016-09-13 17:45:13 +05:30
expect(response).to match_response_schema('list')
end
end
context 'with invalid params' do
2016-09-29 09:46:39 +05:30
context 'when label is nil' do
it 'returns a not found 404 response' do
2016-11-03 12:29:30 +05:30
create_board_list user: user, board: board, label_id: nil
2016-09-29 09:46:39 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-29 09:46:39 +05:30
end
end
2016-09-13 17:45:13 +05:30
2016-09-29 09:46:39 +05:30
context 'when label that does not belongs to project' do
it 'returns a not found 404 response' do
label = create(:label, name: 'Development')
2016-09-13 17:45:13 +05:30
2016-11-03 12:29:30 +05:30
create_board_list user: user, board: board, label_id: label.id
2016-09-29 09:46:39 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-29 09:46:39 +05:30
end
2016-09-13 17:45:13 +05:30
end
end
context 'with unauthorized user' do
2016-09-29 09:46:39 +05:30
it 'returns a forbidden 403 response' do
label = create(:label, project: project, name: 'Development')
2016-09-13 17:45:13 +05:30
2016-11-03 12:29:30 +05:30
create_board_list user: guest, board: board, label_id: label.id
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:forbidden)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def create_board_list(user:, board:, label_id:)
2016-09-13 17:45:13 +05:30
sign_in(user)
2019-02-15 15:39:39 +05:30
post :create, params: {
namespace_id: project.namespace.to_param,
project_id: project,
board_id: board.to_param,
list: { label_id: label_id }
},
2016-09-13 17:45:13 +05:30
format: :json
end
end
describe 'PATCH update' do
let!(:planning) { create(:list, board: board, position: 0) }
let!(:development) { create(:list, board: board, position: 1) }
context 'with valid position' do
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
move user: user, board: board, list: planning, position: 1
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2016-09-13 17:45:13 +05:30
end
it 'moves the list to the desired position' do
2016-11-03 12:29:30 +05:30
move user: user, board: board, list: planning, position: 1
2016-09-13 17:45:13 +05:30
expect(planning.reload.position).to eq 1
end
end
context 'with invalid position' do
2016-09-29 09:46:39 +05:30
it 'returns an unprocessable entity 422 response' do
2016-11-03 12:29:30 +05:30
move user: user, board: board, list: planning, position: 6
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:unprocessable_entity)
2016-09-13 17:45:13 +05:30
end
end
context 'with invalid list id' do
it 'returns a not found 404 response' do
2020-04-22 19:07:51 +05:30
move user: user, board: board, list: non_existing_record_id, position: 1
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-13 17:45:13 +05:30
end
end
context 'with unauthorized user' do
2019-12-04 20:38:33 +05:30
it 'returns a 422 unprocessable entity response' do
2016-11-03 12:29:30 +05:30
move user: guest, board: board, list: planning, position: 6
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:unprocessable_entity)
2019-12-04 20:38:33 +05:30
end
end
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-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-12-04 20:38:33 +05:30
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-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-12-04 20:38:33 +05:30
end
end
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-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-12-04 20:38:33 +05:30
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-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def move(user:, board:, list:, position:)
2016-09-13 17:45:13 +05:30
sign_in(user)
2018-11-08 19:23:39 +05:30
params = { namespace_id: project.namespace.to_param,
project_id: project,
board_id: board.to_param,
id: list.to_param,
list: { position: position },
format: :json }
2019-02-15 15:39:39 +05:30
patch :update, params: params, as: :json
2016-09-13 17:45:13 +05:30
end
2019-12-04 20:38:33 +05:30
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-09-13 17:45:13 +05:30
end
describe 'DELETE destroy' do
let!(:planning) { create(:list, board: board, position: 0) }
context 'with valid list id' do
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
remove_board_list user: user, board: board, list: planning
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2016-09-13 17:45:13 +05:30
end
it 'removes list from board' do
2016-11-03 12:29:30 +05:30
expect { remove_board_list user: user, board: board, list: planning }.to change(board.lists, :size).by(-1)
2016-09-13 17:45:13 +05:30
end
end
context 'with invalid list id' do
it 'returns a not found 404 response' do
2020-04-22 19:07:51 +05:30
remove_board_list user: user, board: board, list: non_existing_record_id
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-13 17:45:13 +05:30
end
end
context 'with unauthorized user' do
2016-09-29 09:46:39 +05:30
it 'returns a forbidden 403 response' do
2016-11-03 12:29:30 +05:30
remove_board_list user: guest, board: board, list: planning
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:forbidden)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def remove_board_list(user:, board:, list:)
2016-09-13 17:45:13 +05:30
sign_in(user)
2019-02-15 15:39:39 +05:30
delete :destroy, params: {
namespace_id: project.namespace.to_param,
project_id: project,
board_id: board.to_param,
id: list.to_param
},
2016-09-13 17:45:13 +05:30
format: :json
end
end
describe 'POST generate' do
context 'when board lists is empty' do
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
generate_default_lists user: user, board: board
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2016-09-13 17:45:13 +05:30
end
it 'returns the defaults lists' do
2016-11-03 12:29:30 +05:30
generate_default_lists user: user, board: board
2016-09-13 17:45:13 +05:30
expect(response).to match_response_schema('lists')
end
end
context 'when board lists is not empty' do
2016-09-29 09:46:39 +05:30
it 'returns an unprocessable entity 422 response' do
2016-09-13 17:45:13 +05:30
create(:list, board: board)
2016-11-03 12:29:30 +05:30
generate_default_lists user: user, board: board
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:unprocessable_entity)
2016-09-13 17:45:13 +05:30
end
end
context 'with unauthorized user' do
2016-09-29 09:46:39 +05:30
it 'returns a forbidden 403 response' do
2016-11-03 12:29:30 +05:30
generate_default_lists user: guest, board: board
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:forbidden)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def generate_default_lists(user:, board:)
2016-09-13 17:45:13 +05:30
sign_in(user)
2019-02-15 15:39:39 +05:30
post :generate, params: {
namespace_id: project.namespace.to_param,
project_id: project,
board_id: board.to_param
},
2016-09-13 17:45:13 +05:30
format: :json
end
end
end