diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 18:09:32 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 18:09:32 +0000 |
commit | ed5add1c2f001c9bd54e664b32f212de172eca6a (patch) | |
tree | f9449cbecde36706f25a62f426b5398566ae5cca /spec/requests/api/graphql | |
parent | de2fb5b82c92c90f90ed67ced45143c04e934fb8 (diff) | |
download | gitlab-ce-ed5add1c2f001c9bd54e664b32f212de172eca6a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api/graphql')
-rw-r--r-- | spec/requests/api/graphql/metrics/dashboard_query_spec.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/metrics/dashboard_query_spec.rb b/spec/requests/api/graphql/metrics/dashboard_query_spec.rb new file mode 100644 index 00000000000..8b0965a815b --- /dev/null +++ b/spec/requests/api/graphql/metrics/dashboard_query_spec.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Getting Metrics Dashboard' do + include GraphqlHelpers + + let_it_be(:current_user) { create(:user) } + let(:project) { create(:project) } + let!(:environment) { create(:environment, project: project) } + + let(:fields) do + <<~QUERY + #{all_graphql_fields_for('MetricsDashboard'.classify)} + QUERY + end + + let(:query) do + %( + query { + project(fullPath:"#{project.full_path}") { + environments(name: "#{environment.name}") { + nodes { + metricsDashboard(path: "#{path}"){ + #{fields} + } + } + } + } + } + ) + end + + context 'for anonymous user' do + before do + post_graphql(query, current_user: current_user) + end + + context 'requested dashboard is available' do + let(:path) { 'config/prometheus/common_metrics.yml' } + + it_behaves_like 'a working graphql query' + + it 'returns nil' do + dashboard = graphql_data.dig('project', 'environments', 'nodes') + + expect(dashboard).to be_nil + end + end + end + + context 'for user with developer access' do + before do + project.add_developer(current_user) + post_graphql(query, current_user: current_user) + end + + context 'requested dashboard is available' do + let(:path) { 'config/prometheus/common_metrics.yml' } + + it_behaves_like 'a working graphql query' + + it 'returns metrics dashboard' do + dashboard = graphql_data.dig('project', 'environments', 'nodes')[0]['metricsDashboard'] + + expect(dashboard).to eql("path" => path) + end + end + + context 'requested dashboard can not be found' do + let(:path) { 'config/prometheus/i_am_not_here.yml' } + + it_behaves_like 'a working graphql query' + + it 'return snil' do + dashboard = graphql_data.dig('project', 'environments', 'nodes')[0]['metricsDashboard'] + + expect(dashboard).to be_nil + end + end + end +end |