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

set_assignees_shared_examples.rb « mutations « graphql « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cfa12171b7e59337ec34e3eed2c203b7e7329680 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# frozen_string_literal: true

require 'spec_helper'

RSpec.shared_examples 'an assignable resource' do
  let_it_be(:user) { create(:user) }

  subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }

  describe '#resolve' do
    let_it_be(:assignee) { create(:user) }
    let_it_be(:assignee2) { create(:user) }
    let(:assignee_usernames) { [assignee.username] }
    let(:mutated_resource) { subject[resource.class.name.underscore.to_sym] }

    subject { mutation.resolve(project_path: resource.project.full_path, iid: resource.iid, assignee_usernames: assignee_usernames) }

    before do
      resource.project.add_developer(assignee)
      resource.project.add_developer(assignee2)
    end

    it 'raises an error if the resource is not accessible to the user' do
      expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end

    context 'when the user can update the resource' do
      before do
        resource.project.add_developer(user)
      end

      it 'replaces the assignee' do
        resource.assignees = [assignee2]
        resource.save!

        expect(mutated_resource).to eq(resource)
        expect(mutated_resource.assignees).to contain_exactly(assignee)
        expect(subject[:errors]).to be_empty
      end

      it 'returns errors when resource could not be updated' do
        allow(resource).to receive(:errors_on_object).and_return(['foo'])

        expect(subject[:errors]).not_to match_array(['foo'])
      end

      context 'when passing an empty assignee list' do
        let(:assignee_usernames) { [] }

        before do
          resource.assignees = [assignee]
          resource.save!
        end

        it 'removes all assignees' do
          expect(mutated_resource).to eq(resource)
          expect(mutated_resource.assignees).to eq([])
          expect(subject[:errors]).to be_empty
        end
      end

      context 'when passing "append" as true' do
        subject do
          mutation.resolve(
            project_path: resource.project.full_path,
            iid: resource.iid,
            assignee_usernames: assignee_usernames,
            operation_mode: Types::MutationOperationModeEnum.enum[:append]
          )
        end

        before do
          resource.assignees = [assignee2]
          resource.save!

          # In CE, APPEND is a NOOP as you can't have multiple assignees
          # We test multiple assignment in EE specs
          if resource.is_a?(MergeRequest)
            stub_licensed_features(multiple_merge_request_assignees: false)
          else
            stub_licensed_features(multiple_issue_assignees: false)
          end
        end

        it 'is a NO-OP in FOSS' do
          expect(mutated_resource).to eq(resource)
          expect(mutated_resource.assignees).to contain_exactly(assignee2)
          expect(subject[:errors]).to be_empty
        end
      end

      context 'when passing "remove" as true' do
        before do
          resource.assignees = [assignee]
          resource.save!
        end

        it 'removes named assignee' do
          mutated_resource = mutation.resolve(
            project_path: resource.project.full_path,
            iid: resource.iid,
            assignee_usernames: assignee_usernames,
            operation_mode: Types::MutationOperationModeEnum.enum[:remove]
          )[resource.class.name.underscore.to_sym]

          expect(mutated_resource).to eq(resource)
          expect(mutated_resource.assignees).to eq([])
          expect(subject[:errors]).to be_empty
        end

        it 'does not remove unnamed assignee' do
          mutated_resource = mutation.resolve(
            project_path: resource.project.full_path,
            iid: resource.iid,
            assignee_usernames: [assignee2.username],
            operation_mode: Types::MutationOperationModeEnum.enum[:remove]
          )[resource.class.name.underscore.to_sym]

          expect(mutated_resource).to eq(resource)
          expect(mutated_resource.assignees).to contain_exactly(assignee)
          expect(subject[:errors]).to be_empty
        end
      end
    end
  end
end