1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
# frozen_string_literal: true
RSpec.shared_examples 'creating a new HTTP integration' do
it 'creates a new integration' do
post_graphql_mutation(mutation, current_user: current_user)
new_integration = ::AlertManagement::HttpIntegration.last!
integration_response = mutation_response['integration']
expect(response).to have_gitlab_http_status(:success)
expect(integration_response['id']).to eq(GitlabSchema.id_from_object(new_integration).to_s)
expect(integration_response['type']).to eq('HTTP')
expect(integration_response['name']).to eq(new_integration.name)
expect(integration_response['active']).to eq(new_integration.active)
expect(integration_response['token']).to eq(new_integration.token)
expect(integration_response['url']).to eq(new_integration.url)
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
|