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

dashboard_query_spec.rb « metrics « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b0965a815be81d2236fe4ba57dfc78bde4d4a87 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
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