debian-mirror-gitlab/spec/services/issues/reorder_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.7 KiB
Ruby
Raw Permalink Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Issues::ReorderService, feature_category: :team_planning do
2020-11-24 15:15:51 +05:30
let_it_be(:user) { create_default(:user) }
2020-03-13 15:44:24 +05:30
let_it_be(:group) { create(:group) }
2020-11-24 15:15:51 +05:30
let_it_be(:project, reload: true) { create(:project, namespace: group) }
2019-09-30 21:07:59 +05:30
shared_examples 'issues reorder service' do
context 'when reordering issues' do
it 'returns false with no params' do
expect(service({}).execute(issue1)).to be_falsey
end
it 'returns false with both invalid params' do
2020-11-24 15:15:51 +05:30
params = { move_after_id: nil, move_before_id: non_existing_record_id }
2019-09-30 21:07:59 +05:30
expect(service(params).execute(issue1)).to be_falsey
end
it 'sorts issues' do
params = { move_after_id: issue2.id, move_before_id: issue3.id }
service(params).execute(issue1)
expect(issue1.relative_position)
.to be_between(issue2.relative_position, issue3.relative_position)
end
2020-11-24 15:15:51 +05:30
it 'sorts issues if only given one neighbour, on the left' do
params = { move_before_id: issue3.id }
service(params).execute(issue1)
expect(issue1.relative_position).to be > issue3.relative_position
end
it 'sorts issues if only given one neighbour, on the right' do
params = { move_after_id: issue1.id }
service(params).execute(issue3)
expect(issue3.relative_position).to be < issue1.relative_position
end
2019-09-30 21:07:59 +05:30
end
end
describe '#execute' do
2020-11-24 15:15:51 +05:30
let_it_be(:issue1, reload: true) { create(:issue, project: project, relative_position: 10) }
let_it_be(:issue2) { create(:issue, project: project, relative_position: 20) }
let_it_be(:issue3, reload: true) { create(:issue, project: project, relative_position: 30) }
2019-09-30 21:07:59 +05:30
context 'when ordering issues in a project' do
before do
2020-11-24 15:15:51 +05:30
project.add_developer(user)
2019-09-30 21:07:59 +05:30
end
it_behaves_like 'issues reorder service'
end
context 'when ordering issues in a group' do
before do
group.add_developer(user)
end
it_behaves_like 'issues reorder service'
context 'when ordering in a group issue list' do
2022-04-04 11:22:00 +05:30
let(:params) { { move_after_id: issue2.id, move_before_id: issue3.id } }
2019-09-30 21:07:59 +05:30
subject { service(params) }
it 'sorts issues' do
project2 = create(:project, namespace: group)
issue4 = create(:issue, project: project2)
subject.execute(issue4)
expect(issue4.relative_position)
.to be_between(issue2.relative_position, issue3.relative_position)
end
end
end
end
def service(params)
2023-04-23 21:23:45 +05:30
described_class.new(container: project, current_user: user, params: params)
2019-09-30 21:07:59 +05:30
end
end