summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/requests/api/graphql/read_only_instance_shared_examples.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 08:27:35 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 08:27:35 +0000
commit7e9c479f7de77702622631cff2628a9c8dcbc627 (patch)
treec8f718a08e110ad7e1894510980d2155a6549197 /spec/support/shared_examples/requests/api/graphql/read_only_instance_shared_examples.rb
parente852b0ae16db4052c1c567d9efa4facc81146e88 (diff)
downloadgitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/support/shared_examples/requests/api/graphql/read_only_instance_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/requests/api/graphql/read_only_instance_shared_examples.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/support/shared_examples/requests/api/graphql/read_only_instance_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/read_only_instance_shared_examples.rb
new file mode 100644
index 00000000000..be163d6aa0e
--- /dev/null
+++ b/spec/support/shared_examples/requests/api/graphql/read_only_instance_shared_examples.rb
@@ -0,0 +1,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