File: update_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (117 lines) | stat: -rw-r--r-- 3,925 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Mutations::Groups::Update, feature_category: :api do
  include GraphqlHelpers
  using RSpec::Parameterized::TableSyntax

  let_it_be_with_reload(:group) { create(:group) }
  let_it_be(:user) { create(:user) }

  let(:params) { { full_path: group.full_path } }
  let(:query) { GraphQL::Query.new(empty_schema, document: nil, context: {}, variables: {}) }
  let(:context) { GraphQL::Query::Context.new(query: query, values: { current_user: user }) }

  specify { expect(described_class).to require_graphql_authorizations(:admin_group_or_admin_runner) }

  describe '#resolve' do
    subject { described_class.new(object: group, context: context, field: nil).resolve(**params) }

    shared_examples 'updating the group shared runners setting' do
      it 'updates the group shared runners setting' do
        expect { subject }
          .to change { group.reload.shared_runners_setting }.from('enabled').to(Namespace::SR_DISABLED_AND_UNOVERRIDABLE)
      end

      it 'returns no errors' do
        expect(subject).to eq(errors: [], group: group)
      end

      context 'with invalid params' do
        let_it_be(:params) { { full_path: group.full_path, shared_runners_setting: 'inexistent_setting' } }

        it 'doesn\'t update the shared_runners_setting' do
          expect { subject }
            .not_to change { group.reload.shared_runners_setting }
        end

        it 'returns an error' do
          expect(subject).to eq(
            group: nil,
            errors: ["Update shared runners state must be one of: #{::Namespace::SHARED_RUNNERS_SETTINGS.join(', ')}"]
          )
        end
      end
    end

    shared_examples 'updating the group math rendering settings' do
      it 'updates the settings' do
        expect { subject }
          .to change { group.reload.math_rendering_limits_enabled? }.to(false)
          .and change { group.reload.lock_math_rendering_limits_enabled? }.to(true)
      end

      it 'returns no errors' do
        expect(subject).to eq(errors: [], group: group)
      end
    end

    shared_examples 'denying access to group' do
      it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do
        expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
      end
    end

    context 'changing shared runners setting' do
      let_it_be(:params) do
        { full_path: group.full_path,
          shared_runners_setting: Namespace::SR_DISABLED_AND_UNOVERRIDABLE }
      end

      where(:user_role, :shared_examples_name) do
        :owner      | 'updating the group shared runners setting'
        :maintainer | 'denying access to group'
        :developer  | 'denying access to group'
        :reporter   | 'denying access to group'
        :guest      | 'denying access to group'
        :anonymous  | 'denying access to group'
      end

      with_them do
        before do
          group.send("add_#{user_role}", user) unless user_role == :anonymous
        end

        it_behaves_like params[:shared_examples_name]
      end
    end

    context 'changing math rendering settings' do
      let_it_be(:params) do
        {
          full_path: group.full_path,
          math_rendering_limits_enabled: false,
          lock_math_rendering_limits_enabled: true
        }
      end

      where(:user_role, :shared_examples_name) do
        :owner      | 'updating the group math rendering settings'
        :maintainer | 'denying access to group'
        :developer  | 'denying access to group'
        :reporter   | 'denying access to group'
        :guest      | 'denying access to group'
        :anonymous  | 'denying access to group'
      end

      with_them do
        before do
          group.send("add_#{user_role}", user) unless user_role == :anonymous
        end

        it_behaves_like params[:shared_examples_name]
      end
    end
  end
end