diff options
Diffstat (limited to 'spec/support/shared_examples/services/boards')
-rw-r--r-- | spec/support/shared_examples/services/boards/boards_list_service_shared_examples.rb | 28 | ||||
-rw-r--r-- | spec/support/shared_examples/services/boards/lists_create_service_shared_examples.rb | 81 |
2 files changed, 83 insertions, 26 deletions
diff --git a/spec/support/shared_examples/services/boards/boards_list_service_shared_examples.rb b/spec/support/shared_examples/services/boards/boards_list_service_shared_examples.rb index 8f7c08ed625..0e2bddc19ab 100644 --- a/spec/support/shared_examples/services/boards/boards_list_service_shared_examples.rb +++ b/spec/support/shared_examples/services/boards/boards_list_service_shared_examples.rb @@ -1,32 +1,8 @@ # frozen_string_literal: true RSpec.shared_examples 'boards list service' do - context 'when parent does not have a board' do - it 'creates a new parent board' do - expect { service.execute }.to change(parent.boards, :count).by(1) - end - - it 'delegates the parent board creation to Boards::CreateService' do - expect_any_instance_of(Boards::CreateService).to receive(:execute).once - - service.execute - end - - context 'when create_default_board is false' do - it 'does not create a new parent board' do - expect { service.execute(create_default_board: false) }.not_to change(parent.boards, :count) - end - end - end - - context 'when parent has a board' do - before do - create(:board, resource_parent: parent) - end - - it 'does not create a new board' do - expect { service.execute }.not_to change(parent.boards, :count) - end + it 'does not create a new board' do + expect { service.execute }.not_to change(parent.boards, :count) end it 'returns parent boards' do diff --git a/spec/support/shared_examples/services/boards/lists_create_service_shared_examples.rb b/spec/support/shared_examples/services/boards/lists_create_service_shared_examples.rb new file mode 100644 index 00000000000..3be002c2126 --- /dev/null +++ b/spec/support/shared_examples/services/boards/lists_create_service_shared_examples.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'board lists create service' do + describe '#execute' do + let_it_be(:user) { create(:user) } + + before_all do + parent.add_developer(user) + end + + subject(:service) { described_class.new(parent, user, label_id: label.id) } + + context 'when board lists is empty' do + it 'creates a new list at beginning of the list' do + response = service.execute(board) + + expect(response.success?).to eq(true) + expect(response.payload[:list].position).to eq 0 + end + end + + context 'when board lists has the done list' do + it 'creates a new list at beginning of the list' do + response = service.execute(board) + + expect(response.success?).to eq(true) + expect(response.payload[:list].position).to eq 0 + end + end + + context 'when board lists has labels lists' do + it 'creates a new list at end of the lists' do + create_list(position: 0) + create_list(position: 1) + + response = service.execute(board) + + expect(response.success?).to eq(true) + expect(response.payload[:list].position).to eq 2 + end + end + + 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(position: 0) + + list2 = service.execute(board).payload[:list] + + expect(list1.reload.position).to eq 0 + expect(list2.reload.position).to eq 1 + end + end + + context 'when provided label does not belong to the parent' do + it 'returns an error' do + label = create(:label, name: 'in-development') + service = described_class.new(parent, user, label_id: label.id) + + response = service.execute(board) + + expect(response.success?).to eq(false) + expect(response.errors).to include('Label not found') + end + end + + context 'when backlog param is sent' do + it 'creates one and only one backlog list' do + service = described_class.new(parent, user, 'backlog' => true) + list = service.execute(board).payload[:list] + + expect(list.list_type).to eq('backlog') + expect(list.position).to be_nil + expect(list).to be_valid + + another_backlog = service.execute(board).payload[:list] + + expect(another_backlog).to eq list + end + end + end +end |