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

grafana_integration_spec.rb « project « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9b24698f40c27be7c7a4bd2d313a434fb331e046 (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
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe 'Getting Grafana Integration' do
  include GraphqlHelpers

  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:current_user) { project.owner }
  let_it_be(:grafana_integration) { create(:grafana_integration, project: project) }

  let(:fields) do
    <<~QUERY
      #{all_graphql_fields_for('GrafanaIntegration'.classify)}
    QUERY
  end

  let(:query) do
    graphql_query_for(
      'project',
      { 'fullPath' => project.full_path },
      query_graphql_field('grafanaIntegration', {}, fields)
    )
  end

  context 'with grafana integration data' do
    let(:integration_data) { graphql_data['project']['grafanaIntegration'] }

    context 'without project admin permissions' do
      let(:user) { create(:user) }

      before do
        project.add_developer(user)
        post_graphql(query, current_user: user)
      end

      it_behaves_like 'a working graphql query'

      specify { expect(integration_data).to be nil }
    end

    context 'with project admin permissions' do
      before do
        post_graphql(query, current_user: current_user)
      end

      it_behaves_like 'a working graphql query'

      specify { expect(integration_data['grafanaUrl']).to eql grafana_integration.grafana_url }

      specify do
        expect(
          integration_data['createdAt']
        ).to eql grafana_integration.created_at.strftime('%Y-%m-%dT%H:%M:%SZ')
      end

      specify do
        expect(
          integration_data['updatedAt']
        ).to eql grafana_integration.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ')
      end
    end
  end
end