diff options
Diffstat (limited to 'spec/support/shared_examples/graphql/mutations/http_integrations_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/graphql/mutations/http_integrations_shared_examples.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/support/shared_examples/graphql/mutations/http_integrations_shared_examples.rb b/spec/support/shared_examples/graphql/mutations/http_integrations_shared_examples.rb index 0338eb43f8d..4468af1a603 100644 --- a/spec/support/shared_examples/graphql/mutations/http_integrations_shared_examples.rb +++ b/spec/support/shared_examples/graphql/mutations/http_integrations_shared_examples.rb @@ -17,3 +17,78 @@ RSpec.shared_examples 'creating a new HTTP integration' do expect(integration_response['apiUrl']).to eq(nil) end end + +RSpec.shared_examples 'updating an existing HTTP integration' do + it 'updates the integration' do + post_graphql_mutation(mutation, current_user: current_user) + + integration_response = mutation_response['integration'] + + expect(response).to have_gitlab_http_status(:success) + expect(integration_response['id']).to eq(GitlabSchema.id_from_object(integration).to_s) + expect(integration_response['name']).to eq('Modified Name') + expect(integration_response['active']).to be_falsey + expect(integration_response['url']).to include('modified-name') + end +end + +RSpec.shared_examples 'validating the payload_example' do + context 'with invalid payloadExample attribute' do + let(:payload_example) { 'not a JSON' } + + it 'responds with errors' do + post_graphql_mutation(mutation, current_user: current_user) + + expect_graphql_errors_to_include(/was provided invalid value for payloadExample \(Invalid JSON string/) + end + end + + it 'validates the payload_example size' do + allow(::Gitlab::Utils::DeepSize) + .to receive(:new) + .with(Gitlab::Json.parse(payload_example)) + .and_return(double(valid?: false)) + + post_graphql_mutation(mutation, current_user: current_user) + + expect_graphql_errors_to_include(/payloadExample JSON is too big/) + end +end + +RSpec.shared_examples 'validating the payload_attribute_mappings' do + context 'with invalid payloadAttributeMapping attribute does not contain fieldName' do + let(:payload_attribute_mappings) do + [{ path: %w[alert name], type: 'STRING' }] + end + + it 'responds with errors' do + post_graphql_mutation(mutation, current_user: current_user) + + expect_graphql_errors_to_include(/was provided invalid value for payloadAttributeMappings\.0\.fieldName \(Expected value to not be null/) + end + end + + context 'with invalid payloadAttributeMapping attribute does not contain path' do + let(:payload_attribute_mappings) do + [{ fieldName: 'TITLE', type: 'STRING' }] + end + + it 'responds with errors' do + post_graphql_mutation(mutation, current_user: current_user) + + expect_graphql_errors_to_include(/was provided invalid value for payloadAttributeMappings\.0\.path \(Expected value to not be null/) + end + end + + context 'with invalid payloadAttributeMapping attribute does not contain type' do + let(:payload_attribute_mappings) do + [{ fieldName: 'TITLE', path: %w[alert name] }] + end + + it 'responds with errors' do + post_graphql_mutation(mutation, current_user: current_user) + + expect_graphql_errors_to_include(/was provided invalid value for payloadAttributeMappings\.0\.type \(Expected value to not be null/) + end + end +end |