Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support_specs/helpers/graphql_helpers_spec.rb')
-rw-r--r--spec/support_specs/helpers/graphql_helpers_spec.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/support_specs/helpers/graphql_helpers_spec.rb b/spec/support_specs/helpers/graphql_helpers_spec.rb
new file mode 100644
index 00000000000..bfc71f519cf
--- /dev/null
+++ b/spec/support_specs/helpers/graphql_helpers_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe GraphqlHelpers do
+ include GraphqlHelpers
+
+ describe '.graphql_mutation' do
+ shared_examples 'correct mutation definition' do
+ it 'returns correct mutation definition' do
+ query = <<~MUTATION
+ mutation($updateAlertStatusInput: UpdateAlertStatusInput!) {
+ updateAlertStatus(input: $updateAlertStatusInput) {
+ clientMutationId
+ }
+ }
+ MUTATION
+ variables = %q({"updateAlertStatusInput":{"projectPath":"test/project"}})
+
+ is_expected.to eq(GraphqlHelpers::MutationDefinition.new(query, variables))
+ end
+ end
+
+ context 'when fields argument is passed' do
+ subject do
+ graphql_mutation(:update_alert_status, { project_path: 'test/project' }, 'clientMutationId')
+ end
+
+ it_behaves_like 'correct mutation definition'
+ end
+
+ context 'when block is passed' do
+ subject do
+ graphql_mutation(:update_alert_status, { project_path: 'test/project' }) do
+ 'clientMutationId'
+ end
+ end
+
+ it_behaves_like 'correct mutation definition'
+ end
+
+ context 'when both fields and a block are passed' do
+ subject do
+ graphql_mutation(:mutation_name, { variable_name: 'variable/value' }, 'fieldName') do
+ 'fieldName'
+ end
+ end
+
+ it 'raises an ArgumentError' do
+ expect { subject }.to raise_error(
+ ArgumentError,
+ 'Please pass either `fields` parameter or a block to `#graphql_mutation`, but not both.'
+ )
+ end
+ end
+ end
+end