summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/controllers/metrics_dashboard_shared_examples.rb
blob: 5b63ef10c854b469735acda6d153619f5b4e891b (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
# frozen_string_literal: true

RSpec.shared_examples_for 'GET #metrics_dashboard correctly formatted response' do
  it 'returns a json object with the correct keys' do
    get :metrics_dashboard, params: metrics_dashboard_req_params, format: :json

    # Exclude `all_dashboards` to handle separately, at spec/controllers/projects/environments_controller_spec.rb:565
    # because `all_dashboards` key is not part of expected shared behavior
    found_keys = json_response.keys - ['all_dashboards']

    expect(response).to have_gitlab_http_status(status_code)
    expect(found_keys).to contain_exactly(*expected_keys)
  end
end

RSpec.shared_examples_for 'GET #metrics_dashboard for dashboard' do |dashboard_name|
  let(:expected_keys) { %w(dashboard status metrics_data) }
  let(:status_code) { :ok }

  before do
    stub_feature_flags(remove_monitor_metrics: false)
  end

  it_behaves_like 'GET #metrics_dashboard correctly formatted response'

  it 'returns correct dashboard' do
    get :metrics_dashboard, params: metrics_dashboard_req_params, format: :json

    expect(json_response['dashboard']['dashboard']).to eq(dashboard_name)
  end

  context 'when metrics dashboard feature is unavailable' do
    before do
      stub_feature_flags(remove_monitor_metrics: true)
    end

    it 'returns 404 not found' do
      get :metrics_dashboard, params: metrics_dashboard_req_params, format: :json

      expect(response).to have_gitlab_http_status(:not_found)
      expect(response.body).to be_empty
    end
  end
end