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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'getting Alert Management Integrations' do
include ::Gitlab::Routing
include GraphqlHelpers
let_it_be(:project) { create(:project, :repository) }
let_it_be(:current_user) { create(:user) }
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
let_it_be(:project_alerting_setting) { create(:project_alerting_setting, project: project) }
let_it_be(:active_http_integration) { create(:alert_management_http_integration, project: project) }
let_it_be(:inactive_http_integration) { create(:alert_management_http_integration, :inactive, project: project) }
let_it_be(:other_project_http_integration) { create(:alert_management_http_integration) }
let(:params) { {} }
let(:fields) do
<<~QUERY
nodes {
#{all_graphql_fields_for('AlertManagementIntegration')}
}
QUERY
end
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('alertManagementIntegrations', params, fields)
)
end
context 'with integrations' do
let(:integrations) { graphql_data.dig('project', 'alertManagementIntegrations', 'nodes') }
context 'without project permissions' do
let(:user) { create(:user) }
before do
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it { expect(integrations).to be_nil }
end
context 'with project permissions' do
before do
project.add_maintainer(current_user)
post_graphql(query, current_user: current_user)
end
context 'when no extra params given' do
it_behaves_like 'a working graphql query'
it 'returns the correct properties of the integrations' do
expect(integrations).to match [
a_graphql_entity_for(
active_http_integration,
:name, :active, :token, :url, type: 'HTTP', api_url: nil
),
a_graphql_entity_for(
prometheus_integration,
'type' => 'PROMETHEUS',
'name' => 'Prometheus',
'active' => prometheus_integration.manual_configuration?,
'token' => project_alerting_setting.token,
'url' => "http://localhost/#{project.full_path}/prometheus/alerts/notify.json",
'apiUrl' => prometheus_integration.api_url
)
]
end
end
context 'when HTTP Integration ID is given' do
let(:params) { { id: global_id_of(active_http_integration) } }
it_behaves_like 'a working graphql query'
it 'returns the correct properties of the HTTP integration' do
expect(integrations).to contain_exactly a_graphql_entity_for(
active_http_integration, :name, :active, :token, :url, type: 'HTTP', api_url: nil
)
end
end
context 'when Prometheus Integration ID is given' do
let(:params) { { id: global_id_of(prometheus_integration) } }
it_behaves_like 'a working graphql query'
it 'returns the correct properties of the Prometheus Integration' do
expect(integrations).to contain_exactly a_graphql_entity_for(
prometheus_integration,
'type' => 'PROMETHEUS',
'name' => 'Prometheus',
'active' => prometheus_integration.manual_configuration?,
'token' => project_alerting_setting.token,
'url' => "http://localhost/#{project.full_path}/prometheus/alerts/notify.json",
'apiUrl' => prometheus_integration.api_url
)
end
end
it_behaves_like 'GraphQL query with several integrations requested', graphql_query_name: 'alertManagementIntegrations'
end
end
end
|