summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/requests/api/graphql/read_only_instance_shared_examples.rb
blob: be163d6aa0eddd6a17c2a8454e458e0d61ae800b (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
# frozen_string_literal: true

RSpec.shared_examples 'graphql on a read-only GitLab instance' do
  include GraphqlHelpers

  context 'mutations' do
    let(:current_user) { note.author }
    let!(:note) { create(:note) }

    let(:mutation) do
      variables = {
        id: GitlabSchema.id_from_object(note).to_s
      }

      graphql_mutation(:destroy_note, variables)
    end

    it 'disallows the query' do
      post_graphql_mutation(mutation, current_user: current_user)

      expect(json_response['errors'].first['message']).to eq(Mutations::BaseMutation::ERROR_MESSAGE)
    end

    it 'does not destroy the Note' do
      expect do
        post_graphql_mutation(mutation, current_user: current_user)
      end.not_to change { Note.count }
    end
  end

  context 'read-only queries' do
    let(:current_user) { create(:user) }
    let(:project) { create(:project, :repository) }

    before do
      project.add_developer(current_user)
    end

    it 'allows the query' do
      query = graphql_query_for('project', 'fullPath' => project.full_path)

      post_graphql(query, current_user: current_user)

      expect(graphql_data['project']).not_to be_nil
    end
  end
end