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

create_spec.rb « prometheus_integration « alert_management « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3dee7f50af374ae881ad6665c0fb587bf90063dc (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Creating a new Prometheus Integration', feature_category: :incident_management do
  include GraphqlHelpers

  let_it_be(:current_user) { create(:user) }
  let_it_be(:project) { create(:project) }

  let(:variables) do
    {
      project_path: project.full_path,
      active: false,
      api_url: 'https://prometheus-url.com'
    }
  end

  let(:mutation) do
    graphql_mutation(:prometheus_integration_create, variables) do
      <<~QL
         clientMutationId
         errors
         integration {
           id
           type
           name
           active
           token
           url
           apiUrl
         }
      QL
    end
  end

  let(:mutation_response) { graphql_mutation_response(:prometheus_integration_create) }

  before do
    project.add_maintainer(current_user)
  end

  it 'creates a new integration' do
    post_graphql_mutation(mutation, current_user: current_user)

    new_integration = ::Integrations::Prometheus.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('PROMETHEUS')
    expect(integration_response['name']).to eq(new_integration.title)
    expect(integration_response['active']).to eq(new_integration.manual_configuration?)
    expect(integration_response['token']).to eq(new_integration.project.alerting_setting.token)
    expect(integration_response['url']).to eq("http://localhost/#{project.full_path}/prometheus/alerts/notify.json")
    expect(integration_response['apiUrl']).to eq(new_integration.api_url)
  end

  [:project_path, :active, :api_url].each do |argument|
    context "without required argument #{argument}" do
      before do
        variables.delete(argument)
      end

      it_behaves_like 'an invalid argument to the mutation', argument_name: argument
    end
  end
end