Welcome to mirror list, hosted at ThFree Co, Russian Federation.

reorder_service_spec.rb « issues « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 15668a3aa23029028a3188adf8dfc5861cc4a4a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Issues::ReorderService do
  let_it_be(:user)    { create_default(:user) }
  let_it_be(:group)   { create(:group) }
  let_it_be(:project, reload: true) { create(:project, namespace: group) }

  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
        params = { move_after_id: nil, move_before_id: non_existing_record_id }

        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

      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
    end
  end

  describe '#execute' do
    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) }

    context 'when ordering issues in a project' do
      before do
        project.add_developer(user)
      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
        let(:params) { { move_after_id: issue2.id, move_before_id: issue3.id, group_full_path: group.full_path } }

        subject { service(params) }

        it 'sends the board_group_id parameter' do
          match_params = { move_between_ids: [issue2.id, issue3.id], board_group_id: group.id }

          expect(Issues::UpdateService)
            .to receive(:new).with(project: project, current_user: user, params: match_params)
            .and_return(double(execute: build(:issue)))

          subject.execute(issue1)
        end

        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)
    described_class.new(project: project, current_user: user, params: params)
  end
end