summaryrefslogtreecommitdiff
path: root/spec/graphql/mutations/base_mutation_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/graphql/mutations/base_mutation_spec.rb
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
downloadgitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/graphql/mutations/base_mutation_spec.rb')
-rw-r--r--spec/graphql/mutations/base_mutation_spec.rb56
1 files changed, 56 insertions, 0 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