summaryrefslogtreecommitdiff
path: root/spec/graphql/mutations
diff options
context:
space:
mode:
Diffstat (limited to 'spec/graphql/mutations')
-rw-r--r--spec/graphql/mutations/base_mutation_spec.rb56
-rw-r--r--spec/graphql/mutations/ci/runner/delete_spec.rb2
-rw-r--r--spec/graphql/mutations/ci/runner/update_spec.rb2
-rw-r--r--spec/graphql/mutations/design_management/delete_spec.rb39
-rw-r--r--spec/graphql/mutations/groups/update_spec.rb74
-rw-r--r--spec/graphql/mutations/issues/update_spec.rb22
6 files changed, 174 insertions, 21 deletions
diff --git a/spec/graphql/mutations/base_mutation_spec.rb b/spec/graphql/mutations/base_mutation_spec.rb
new file mode 100644
index 00000000000..7939fadb37b
--- /dev/null
+++ b/spec/graphql/mutations/base_mutation_spec.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ::Mutations::BaseMutation do
+ include GraphqlHelpers
+
+ describe 'argument nullability' do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:context) { { current_user: user } }
+
+ subject(:mutation) { mutation_class.new(object: nil, context: context, field: nil) }
+
+ describe 'when using a mutation with correct argument declarations' do
+ context 'when argument is nullable and required' do
+ let(:mutation_class) do
+ Class.new(described_class) do
+ argument :foo, GraphQL::Types::String, required: :nullable
+ end
+ end
+
+ specify do
+ expect { subject.ready? }.to raise_error(ArgumentError, /must be provided: foo/)
+ end
+
+ specify do
+ expect { subject.ready?(foo: nil) }.not_to raise_error
+ end
+
+ specify do
+ expect { subject.ready?(foo: "bar") }.not_to raise_error
+ end
+ end
+
+ context 'when argument is required and NOT nullable' do
+ let(:mutation_class) do
+ Class.new(described_class) do
+ argument :foo, GraphQL::Types::String, required: true
+ end
+ end
+
+ specify do
+ expect { subject.ready? }.to raise_error(ArgumentError, /must be provided/)
+ end
+
+ specify do
+ expect { subject.ready?(foo: nil) }.to raise_error(ArgumentError, /must be provided/)
+ end
+
+ specify do
+ expect { subject.ready?(foo: "bar") }.not_to raise_error
+ end
+ end
+ end
+ end
+end
diff --git a/spec/graphql/mutations/ci/runner/delete_spec.rb b/spec/graphql/mutations/ci/runner/delete_spec.rb
index 82873c96c3e..27e8236d593 100644
--- a/spec/graphql/mutations/ci/runner/delete_spec.rb
+++ b/spec/graphql/mutations/ci/runner/delete_spec.rb
@@ -41,7 +41,7 @@ RSpec.describe Mutations::Ci::Runner::Delete do
let(:mutation_params) { {} }
it 'raises an error' do
- expect { subject }.to raise_error(ArgumentError, "missing keyword: :id")
+ expect { subject }.to raise_error(ArgumentError, "Arguments must be provided: id")
end
end
diff --git a/spec/graphql/mutations/ci/runner/update_spec.rb b/spec/graphql/mutations/ci/runner/update_spec.rb
index 3db0d552a05..83150c3d7f6 100644
--- a/spec/graphql/mutations/ci/runner/update_spec.rb
+++ b/spec/graphql/mutations/ci/runner/update_spec.rb
@@ -43,7 +43,7 @@ RSpec.describe Mutations::Ci::Runner::Update do
let(:mutation_params) { {} }
it 'raises an error' do
- expect { subject }.to raise_error(ArgumentError, "missing keyword: :id")
+ expect { subject }.to raise_error(ArgumentError, "Arguments must be provided: id")
end
end
diff --git a/spec/graphql/mutations/design_management/delete_spec.rb b/spec/graphql/mutations/design_management/delete_spec.rb
index 3efa865c64b..93fff5e5103 100644
--- a/spec/graphql/mutations/design_management/delete_spec.rb
+++ b/spec/graphql/mutations/design_management/delete_spec.rb
@@ -86,9 +86,9 @@ RSpec.describe Mutations::DesignManagement::Delete do
end
end
- it 'runs no more than 28 queries' do
+ it 'runs no more than 29 queries' do
filenames.each(&:present?) # ignore setup
- # Queries: as of 2019-08-28
+ # Queries: as of 2021-07-22
# -------------
# 01. routing query
# 02. find project by id
@@ -100,25 +100,26 @@ RSpec.describe Mutations::DesignManagement::Delete do
# 09. find namespace by id
# 10. find group namespace by id
# 11. project.authorizations for user (same query as 5)
- # 12. project.project_features (same query as 3)
- # 13. project.authorizations for user (same query as 5)
- # 14. current designs by filename and issue
- # 15, 16 project.authorizations for user (same query as 5)
- # 17. find route by id and source_type
+ # 12. find user by id
+ # 13. project.project_features (same query as 3)
+ # 14. project.authorizations for user (same query as 5)
+ # 15. current designs by filename and issue
+ # 16, 17 project.authorizations for user (same query as 5)
+ # 18. find route by id and source_type
# ------------- our queries are below:
- # 18. start transaction 1
- # 19. start transaction 2
- # 20. find version by sha and issue
- # 21. exists version with sha and issue?
- # 22. leave transaction 2
- # 23. create version with sha and issue
- # 24. create design-version links
- # 25. validate version.actions.present?
- # 26. validate version.issue.present?
- # 27. validate version.sha is unique
- # 28. leave transaction 1
+ # 19. start transaction 1
+ # 20. start transaction 2
+ # 21. find version by sha and issue
+ # 22. exists version with sha and issue?
+ # 23. leave transaction 2
+ # 24. create version with sha and issue
+ # 25. create design-version links
+ # 26. validate version.actions.present?
+ # 27. validate version.issue.present?
+ # 28. validate version.sha is unique
+ # 29. leave transaction 1
#
- expect { run_mutation }.not_to exceed_query_limit(28)
+ expect { run_mutation }.not_to exceed_query_limit(29)
end
end
diff --git a/spec/graphql/mutations/groups/update_spec.rb b/spec/graphql/mutations/groups/update_spec.rb
new file mode 100644
index 00000000000..2118134e8e6
--- /dev/null
+++ b/spec/graphql/mutations/groups/update_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::Groups::Update do
+ 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 } }
+
+ specify { expect(described_class).to require_graphql_authorizations(:admin_group) }
+
+ describe '#resolve' do
+ subject { described_class.new(object: group, context: { current_user: user }, field: nil).resolve(**params) }
+
+ RSpec.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('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
+
+ RSpec.shared_examples 'denying access to group shared runners setting' 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: 'disabled_and_unoverridable' }
+ end
+
+ where(:user_role, :shared_examples_name) do
+ :owner | 'updating the group shared runners setting'
+ :developer | 'denying access to group shared runners setting'
+ :reporter | 'denying access to group shared runners setting'
+ :guest | 'denying access to group shared runners setting'
+ :anonymous | 'denying access to group shared runners setting'
+ 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
diff --git a/spec/graphql/mutations/issues/update_spec.rb b/spec/graphql/mutations/issues/update_spec.rb
index 80f43338bb5..bb57ad4c404 100644
--- a/spec/graphql/mutations/issues/update_spec.rb
+++ b/spec/graphql/mutations/issues/update_spec.rb
@@ -131,6 +131,28 @@ RSpec.describe Mutations::Issues::Update do
expect(issue.reload.labels).to match_array([project_label, label_2])
end
+
+ context 'when setting labels with label_ids' do
+ it 'replaces existing labels with provided ones' do
+ expect(issue.reload.labels).to match_array([project_label])
+
+ mutation_params[:label_ids] = [label_1.id, label_2.id]
+
+ subject
+
+ expect(issue.reload.labels).to match_array([label_1, label_2])
+ end
+
+ it 'raises error when label_ids is combined with remove_label_ids' do
+ expect { mutation.ready?(label_ids: [label_1.id, label_2.id], remove_label_ids: [label_1.id]) }
+ .to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'labelIds is mutually exclusive with any of addLabelIds or removeLabelIds')
+ end
+
+ it 'raises error when label_ids is combined with add_label_ids' do
+ expect { mutation.ready?(label_ids: [label_1.id, label_2.id], add_label_ids: [label_2.id]) }
+ .to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'labelIds is mutually exclusive with any of addLabelIds or removeLabelIds')
+ end
+ end
end
context 'when changing type' do