debian-mirror-gitlab/spec/services/boards/issues/move_service_spec.rb

143 lines
5.6 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'
2017-09-10 17:25:29 +05:30
describe Boards::Issues::MoveService do
2016-09-13 17:45:13 +05:30
describe '#execute' do
2018-03-27 19:54:05 +05:30
context 'when parent is a project' do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:board1) { create(:board, project: project) }
2016-11-03 12:29:30 +05:30
let(:board2) { create(:board, project: project) }
2018-03-27 19:54:05 +05:30
let(:bug) { create(:label, project: project, name: 'Bug') }
let(:development) { create(:label, project: project, name: 'Development') }
2019-03-02 22:35:43 +05:30
let(:testing) { create(:label, project: project, name: 'Testing') }
2016-11-03 12:29:30 +05:30
let(:regression) { create(:label, project: project, name: 'Regression') }
2018-03-27 19:54:05 +05:30
let!(:list1) { create(:list, board: board1, label: development, position: 0) }
let!(:list2) { create(:list, board: board1, label: testing, position: 1) }
let!(:closed) { create(:closed_list, board: board1) }
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
let(:parent) { project }
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
before do
parent.add_developer(user)
2016-09-13 17:45:13 +05:30
end
2018-03-27 19:54:05 +05:30
it_behaves_like 'issues move service'
2016-09-13 17:45:13 +05:30
end
2018-03-27 19:54:05 +05:30
context 'when parent is a group' do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
let(:board1) { create(:board, group: group) }
let(:board2) { create(:board, group: group) }
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
let(:bug) { create(:group_label, group: group, name: 'Bug') }
let(:development) { create(:group_label, group: group, name: 'Development') }
2019-03-02 22:35:43 +05:30
let(:testing) { create(:group_label, group: group, name: 'Testing') }
2018-03-27 19:54:05 +05:30
let(:regression) { create(:group_label, group: group, name: 'Regression') }
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
let!(:list1) { create(:list, board: board1, label: development, position: 0) }
let!(:list2) { create(:list, board: board1, label: testing, position: 1) }
let!(:closed) { create(:closed_list, board: board1) }
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
let(:parent) { group }
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
before do
parent.add_developer(user)
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
2018-05-01 15:08:00 +05:30
it_behaves_like 'issues move service', true
2016-09-13 17:45:13 +05:30
end
2019-09-30 21:07:59 +05:30
describe '#execute_multiple' do
2020-03-13 15:44:24 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, namespace: group) }
let_it_be(:board1) { create(:board, group: group) }
let_it_be(:development) { create(:group_label, group: group, name: 'Development') }
let_it_be(:testing) { create(:group_label, group: group, name: 'Testing') }
let_it_be(:list1) { create(:list, board: board1, label: development, position: 0) }
let_it_be(:list2) { create(:list, board: board1, label: testing, position: 1) }
2019-09-30 21:07:59 +05:30
let(:params) { { board_id: board1.id, from_list_id: list1.id, to_list_id: list2.id } }
before do
project.add_developer(user)
end
it 'returns the expected result if list of issues is empty' do
expect(described_class.new(group, user, params).execute_multiple([])).to eq({ count: 0, success: false, issues: [] })
end
context 'moving multiple issues' do
let(:issue1) { create(:labeled_issue, project: project, labels: [development]) }
let(:issue2) { create(:labeled_issue, project: project, labels: [development]) }
it 'moves multiple issues from one list to another' do
expect(described_class.new(group, user, params).execute_multiple([issue1, issue2])).to be_truthy
expect(issue1.labels).to eq([testing])
expect(issue2.labels).to eq([testing])
end
end
context 'moving a single issue' do
let(:issue1) { create(:labeled_issue, project: project, labels: [development]) }
it 'moves one issue' do
expect(described_class.new(group, user, params).execute_multiple([issue1])).to be_truthy
expect(issue1.labels).to eq([testing])
end
end
context 'moving issues visually after an existing issue' do
let(:existing_issue) { create(:labeled_issue, project: project, labels: [testing], relative_position: 10) }
let(:issue1) { create(:labeled_issue, project: project, labels: [development]) }
let(:issue2) { create(:labeled_issue, project: project, labels: [development]) }
let(:move_params) do
params.dup.tap do |hash|
hash[:move_before_id] = existing_issue.id
end
end
it 'moves one issue' do
expect(described_class.new(group, user, move_params).execute_multiple([issue1, issue2])).to be_truthy
expect(issue1.labels).to eq([testing])
expect(issue2.labels).to eq([testing])
expect(issue1.relative_position > existing_issue.relative_position).to eq(true)
expect(issue2.relative_position > issue1.relative_position).to eq(true)
end
end
context 'moving issues visually before an existing issue' do
let(:existing_issue) { create(:labeled_issue, project: project, labels: [testing], relative_position: 10) }
let(:issue1) { create(:labeled_issue, project: project, labels: [development]) }
let(:issue2) { create(:labeled_issue, project: project, labels: [development]) }
let(:move_params) do
params.dup.tap do |hash|
hash[:move_after_id] = existing_issue.id
end
end
it 'moves one issue' do
expect(described_class.new(group, user, move_params).execute_multiple([issue1, issue2])).to be_truthy
expect(issue1.labels).to eq([testing])
expect(issue2.labels).to eq([testing])
expect(issue2.relative_position < existing_issue.relative_position).to eq(true)
expect(issue1.relative_position < issue2.relative_position).to eq(true)
end
end
end
2016-09-13 17:45:13 +05:30
end
end