summaryrefslogtreecommitdiff
path: root/spec/requests/groups/observability_controller_spec.rb
blob: 46690d6053979a6fe5b42d7ae9c05909af25ca12 (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
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Groups::ObservabilityController, feature_category: :tracing do
  let_it_be(:group) { create(:group) }
  let_it_be(:user) { create(:user) }

  let(:observability_url) { Gitlab::Observability.observability_url }
  let(:path) { nil }
  let(:expected_observability_path) { nil }

  shared_examples 'observability route request' do
    subject do
      get path
      response
    end

    it_behaves_like 'observability csp policy' do
      let(:tested_path) { path }
    end

    context 'when user is not authenticated' do
      it 'returns 404' do
        expect(subject).to have_gitlab_http_status(:not_found)
      end
    end

    context 'when user is not a developer' do
      before do
        sign_in(user)
      end

      it 'returns 404' do
        expect(subject).to have_gitlab_http_status(:not_found)
      end
    end

    context 'when user is authenticated and a developer' do
      before do
        sign_in(user)
        group.add_developer(user)
      end

      context 'when observability url is missing' do
        before do
          allow(Gitlab::Observability).to receive(:observability_url).and_return("")
        end

        it 'returns 404' do
          expect(subject).to have_gitlab_http_status(:not_found)
        end
      end

      it 'returns 200' do
        expect(subject).to have_gitlab_http_status(:ok)
      end

      it 'renders the proper layout' do
        expect(subject).to render_template("layouts/group")
        expect(subject).to render_template("layouts/fullscreen")
        expect(subject).not_to render_template('layouts/nav/breadcrumbs')
        expect(subject).to render_template("nav/sidebar/_group")
        expect(subject).to render_template("groups/observability/observability")
      end

      it 'renders the js-observability-app element correctly' do
        element = Nokogiri::HTML.parse(subject.body).at_css('#js-observability-app')
        expect(element.attributes['data-observability-iframe-src'].value).to eq(expected_observability_path)
      end
    end
  end

  describe 'GET #dashboards' do
    let(:path) { group_observability_dashboards_path(group) }
    let(:expected_observability_path) { "#{observability_url}/-/#{group.id}/" }

    it_behaves_like 'observability route request'
  end

  describe 'GET #manage' do
    let(:path) { group_observability_manage_path(group) }
    let(:expected_observability_path) { "#{observability_url}/-/#{group.id}/dashboards" }

    it_behaves_like 'observability route request'
  end

  describe 'GET #explore' do
    let(:path) { group_observability_explore_path(group) }
    let(:expected_observability_path) { "#{observability_url}/-/#{group.id}/explore" }

    it_behaves_like 'observability route request'
  end
end