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

update_service_spec.rb « plan_limits « admin « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e57c234780c2cd4c69f6eb0ec2e18bd412a4ac36 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Admin::PlanLimits::UpdateService, feature_category: :shared do
  let_it_be(:user) { create(:admin) }
  let_it_be(:plan) { create(:plan, name: 'free') }
  let_it_be(:limits) { plan.actual_limits }
  let_it_be(:params) do
    {
      ci_pipeline_size: 101,
      ci_active_jobs: 102,
      ci_project_subscriptions: 104,
      ci_pipeline_schedules: 105,
      ci_needs_size_limit: 106,
      ci_registered_group_runners: 107,
      ci_registered_project_runners: 108,
      conan_max_file_size: 10,
      enforcement_limit: 100,
      generic_packages_max_file_size: 20,
      helm_max_file_size: 25,
      notification_limit: 95,
      maven_max_file_size: 40,
      npm_max_file_size: 60,
      nuget_max_file_size: 60,
      pypi_max_file_size: 70,
      terraform_module_max_file_size: 80,
      storage_size_limit: 90,
      pipeline_hierarchy_size: 250
    }
  end

  subject(:update_plan_limits) { described_class.new(params, current_user: user, plan: plan).execute }

  context 'when current_user is an admin', :enable_admin_mode do
    context 'when the update is successful', :freeze_time do
      let(:current_timestamp) { Time.current.utc.to_i }

      it 'updates all attributes' do
        update_plan_limits

        params.each do |key, value|
          expect(limits.send(key)).to eq value
        end
      end

      it 'logs the allowed attributes only' do
        update_plan_limits

        expect(limits.limits_history).to eq(
          { "enforcement_limit" =>
                                [{ "user_id" => user.id, "username" => user.username,
                                   "timestamp" => current_timestamp, "value" => 100 }],
            "notification_limit" =>
                                [{ "user_id" => user.id, "username" => user.username,
                                   "timestamp" => current_timestamp, "value" => 95 }],
            "storage_size_limit" =>
                                [{ "user_id" => user.id, "username" => user.username,
                                   "timestamp" => current_timestamp, "value" => 90 }] }
        )
      end

      it 'returns success' do
        response = update_plan_limits

        expect(response[:status]).to eq :success
      end
    end

    context 'when the update is unsuccessful' do
      context 'when notification_limit is less than storage_size_limit' do
        let(:params) { { notification_limit: 2 } }

        before do
          limits.update!(
            storage_size_limit: 5,
            enforcement_limit: 10
          )
        end

        it 'returns an error' do
          response = update_plan_limits

          expect(response[:status]).to eq :error
          expect(response[:message]).to eq ["Notification limit must be greater than or equal to " \
                                            "storage_size_limit (Dashboard limit): 5 " \
                                            "and less than or equal to enforcement_limit: 10"]
        end
      end

      context 'when notification_limit is greater than enforcement_limit' do
        let(:params) { { notification_limit: 11 } }

        before do
          limits.update!(
            storage_size_limit: 5,
            enforcement_limit: 10
          )
        end

        it 'returns an error' do
          response = update_plan_limits

          expect(response[:status]).to eq :error
          expect(response[:message]).to eq ["Notification limit must be greater than or equal to " \
                                            "storage_size_limit (Dashboard limit): 5 " \
                                            "and less than or equal to enforcement_limit: 10"]
        end
      end

      context 'when enforcement_limit is less than storage_size_limit' do
        let(:params) { { enforcement_limit: 9 } }

        before do
          limits.update!(
            storage_size_limit: 12,
            notification_limit: 12
          )
        end

        it 'returns an error' do
          response = update_plan_limits

          expect(response[:status]).to eq :error
          expect(response[:message]).to eq ["Enforcement limit must be greater than " \
                                            "or equal to storage_size_limit (Dashboard limit): " \
                                            "12 and greater than or equal to notification_limit: 12"]
        end
      end

      context 'when enforcement_limit is less than notification_limit' do
        let(:params) { { enforcement_limit: 9 } }

        before do
          limits.update!(
            storage_size_limit: 10,
            notification_limit: 10
          )
        end

        it 'returns an error' do
          response = update_plan_limits

          expect(response[:status]).to eq :error
          expect(response[:message]).to eq ["Enforcement limit must be greater than or equal to " \
                                            "storage_size_limit (Dashboard limit): " \
                                            "10 and greater than or equal to notification_limit: 10"]
        end
      end

      context 'when storage_size_limit is greater than notification_limit' do
        let(:params) { { storage_size_limit: 11 } }

        before do
          limits.update!(
            enforcement_limit: 12,
            notification_limit: 10
          )
        end

        it 'returns an error' do
          response = update_plan_limits

          expect(response[:status]).to eq :error
          expect(response[:message]).to eq ["Storage size limit (Dashboard limit) must be less than or " \
                                            "equal to enforcement_limit: 12 and notification_limit: 10"]
        end
      end

      context 'when storage_size_limit is greater than enforcement_limit' do
        let(:params) { { storage_size_limit: 11 } }

        before do
          limits.update!(
            enforcement_limit: 10,
            notification_limit: 11
          )
        end

        it 'returns an error' do
          response = update_plan_limits

          expect(response[:status]).to eq :error
          expect(response[:message]).to eq ["Storage size limit (Dashboard limit) must be less than or " \
                                            "equal to enforcement_limit: 10 and notification_limit: 11"]
        end
      end
    end
  end

  context 'when the user is not an admin' do
    let(:user) { create(:user) }

    it 'returns an error' do
      response = update_plan_limits

      expect(response[:status]).to eq :error
      expect(response[:message]).to eq 'Access denied'
    end
  end
end