2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Boards::Lists::CreateService do
|
2016-09-13 17:45:13 +05:30
|
|
|
describe '#execute' do
|
2018-03-27 19:54:05 +05:30
|
|
|
shared_examples 'creating board lists' do
|
2021-02-22 17:27:13 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
before_all do
|
2018-03-27 19:54:05 +05:30
|
|
|
parent.add_developer(user)
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
subject(:service) { described_class.new(parent, user, label_id: label.id) }
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when board lists is empty' do
|
|
|
|
it 'creates a new list at beginning of the list' do
|
2021-02-22 17:27:13 +05:30
|
|
|
response = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(response.success?).to eq(true)
|
|
|
|
expect(response.payload[:list].position).to eq 0
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when board lists has the done list' do
|
|
|
|
it 'creates a new list at beginning of the list' do
|
2021-02-22 17:27:13 +05:30
|
|
|
response = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(response.success?).to eq(true)
|
|
|
|
expect(response.payload[:list].position).to eq 0
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when board lists has labels lists' do
|
|
|
|
it 'creates a new list at end of the lists' do
|
|
|
|
create(:list, board: board, position: 0)
|
|
|
|
create(:list, board: board, position: 1)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
response = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(response.success?).to eq(true)
|
|
|
|
expect(response.payload[:list].position).to eq 2
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when board lists has label and done lists' do
|
|
|
|
it 'creates a new list at end of the label lists' do
|
|
|
|
list1 = create(:list, board: board, position: 0)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
list2 = service.execute(board).payload[:list]
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(list1.reload.position).to eq 0
|
|
|
|
expect(list2.reload.position).to eq 1
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
context 'when provided label does not belong to the parent' do
|
|
|
|
it 'returns an error' do
|
2018-03-27 19:54:05 +05:30
|
|
|
label = create(:label, name: 'in-development')
|
|
|
|
service = described_class.new(parent, user, label_id: label.id)
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
response = service.execute(board)
|
|
|
|
|
|
|
|
expect(response.success?).to eq(false)
|
|
|
|
expect(response.errors).to include('Label not found')
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
context 'when backlog param is sent' do
|
|
|
|
it 'creates one and only one backlog list' do
|
|
|
|
service = described_class.new(parent, user, 'backlog' => true)
|
2021-02-22 17:27:13 +05:30
|
|
|
list = service.execute(board).payload[:list]
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(list.list_type).to eq('backlog')
|
|
|
|
expect(list.position).to be_nil
|
|
|
|
expect(list).to be_valid
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
another_backlog = service.execute(board).payload[:list]
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(another_backlog).to eq list
|
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
context 'when board parent is a project' do
|
2021-02-22 17:27:13 +05:30
|
|
|
let_it_be(:parent) { create(:project) }
|
|
|
|
let_it_be(:board) { create(:board, project: parent) }
|
|
|
|
let_it_be(:label) { create(:label, project: parent, name: 'in-progress') }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
it_behaves_like 'creating board lists'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when board parent is a group' do
|
2021-02-22 17:27:13 +05:30
|
|
|
let_it_be(:parent) { create(:group) }
|
|
|
|
let_it_be(:board) { create(:board, group: parent) }
|
|
|
|
let_it_be(:label) { create(:group_label, group: parent, name: 'in-progress') }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
it_behaves_like 'creating board lists'
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|