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

pipeline_schedules_create_or_update_shared_examples.rb « ci « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 399225c13b2df54cfb22c14eb30e1061971a3ab6 (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
# frozen_string_literal: true

RSpec.shared_examples 'pipeline schedules checking variables permission' do
  let(:params) do
    {
      description: 'desc',
      ref: 'patch-x',
      active: false,
      cron: '*/1 * * * *',
      cron_timezone: 'UTC',
      variables_attributes: variables_attributes
    }
  end

  shared_examples 'success response' do
    it 'saves values with passed params' do
      result = service.execute

      expect(result.status).to eq(:success)
      expect(result.payload).to have_attributes(
        description: 'desc',
        ref: 'patch-x',
        active: false,
        cron: '*/1 * * * *',
        cron_timezone: 'UTC'
      )
    end
  end

  shared_examples 'failure response' do
    it 'does not save' do
      result = service.execute

      expect(result.status).to eq(:error)
      expect(result.reason).to eq(:forbidden)
      expect(result.message).to match_array(
        ['The current user is not authorized to set pipeline schedule variables']
      )
    end
  end

  context 'when sending variables' do
    let(:variables_attributes) do
      [{ key: 'VAR2', secret_value: 'secret 2' }]
    end

    shared_examples 'success response with variables' do
      it_behaves_like 'success response'

      it 'saves variables' do
        result = service.execute

        variables = result.payload.variables.map { |v| [v.key, v.value] }

        expect(variables).to include(
          ['VAR2', 'secret 2']
        )
      end
    end

    context 'when user is maintainer' do
      it_behaves_like 'success response with variables'
    end

    context 'when user is developer' do
      before_all do
        project.add_developer(user)
      end

      it_behaves_like 'success response with variables'
    end

    context 'when restrict_user_defined_variables is true' do
      before_all do
        project.update!(restrict_user_defined_variables: true)
      end

      it_behaves_like 'success response with variables'

      context 'when user is developer' do
        before_all do
          project.add_developer(user)
        end

        it_behaves_like 'failure response'
      end
    end
  end

  context 'when not sending variables' do
    let(:variables_attributes) { [] }

    context 'when user is maintainer' do
      it_behaves_like 'success response'
    end

    context 'when user is developer' do
      before_all do
        project.add_developer(user)
      end

      it_behaves_like 'success response'
    end

    context 'when restrict_user_defined_variables is true' do
      before_all do
        project.update!(restrict_user_defined_variables: true)
      end

      it_behaves_like 'success response'

      context 'when user is developer' do
        before_all do
          project.add_developer(user)
        end

        it_behaves_like 'success response'
      end
    end
  end
end