debian-mirror-gitlab/spec/requests/projects/metrics_dashboard_spec.rb

136 lines
4.1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-11-24 15:15:51 +05:30
RSpec.describe 'Projects::MetricsDashboardController' do
2020-07-28 23:09:34 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:environment) { create(:environment, project: project) }
let_it_be(:environment2) { create(:environment, project: project) }
let_it_be(:user) { project.owner }
before do
project.add_developer(user)
login_as(user)
end
describe 'GET /:namespace/:project/-/metrics' do
2020-11-24 15:15:51 +05:30
it "redirects to default environment's metrics dashboard" do
2020-07-28 23:09:34 +05:30
send_request
2020-11-24 15:15:51 +05:30
expect(response).to redirect_to(dashboard_route(environment: environment))
2020-07-28 23:09:34 +05:30
end
2020-11-24 15:15:51 +05:30
it 'assigns default_environment' do
2020-07-28 23:09:34 +05:30
send_request
2020-11-24 15:15:51 +05:30
expect(assigns(:default_environment).id).to eq(environment.id)
end
it 'retains existing parameters when redirecting' do
params = {
dashboard_path: '.gitlab/dashboards/dashboard_path.yml',
page: 'panel/new',
group: 'System metrics (Kubernetes)',
title: 'Memory Usage (Pod average)',
y_label: 'Memory Used per Pod (MB)'
}
send_request(params)
expect(response).to redirect_to(dashboard_route(params.merge(environment: environment.id)))
2020-07-28 23:09:34 +05:30
end
2020-10-24 23:57:45 +05:30
context 'with anonymous user and public dashboard visibility' do
let(:anonymous_user) { create(:user) }
let(:project) do
create(:project, :public, :metrics_dashboard_enabled)
end
before do
2020-11-24 15:15:51 +05:30
project.update!(metrics_dashboard_access_level: 'enabled')
2020-10-24 23:57:45 +05:30
login_as(anonymous_user)
end
it 'returns 200' do
send_request
2020-11-24 15:15:51 +05:30
2020-10-24 23:57:45 +05:30
expect(response).to have_gitlab_http_status(:ok)
end
end
2020-07-28 23:09:34 +05:30
end
describe 'GET /:namespace/:project/-/metrics?environment=:environment.id' do
it 'returns 200' do
send_request(environment: environment2.id)
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns query param environment' do
send_request(environment: environment2.id)
expect(assigns(:environment).id).to eq(environment2.id)
end
context 'when query param environment does not exist' do
it 'responds with 404' do
send_request(environment: 99)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe 'GET /:namespace/:project/-/metrics/:dashboard_path' do
let(:dashboard_path) { '.gitlab/dashboards/dashboard_path.yml' }
it 'returns 200' do
2020-11-24 15:15:51 +05:30
send_request(dashboard_path: dashboard_path, environment: environment.id)
2020-07-28 23:09:34 +05:30
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns environment' do
2020-11-24 15:15:51 +05:30
send_request(dashboard_path: dashboard_path, environment: environment.id)
2020-07-28 23:09:34 +05:30
expect(assigns(:environment).id).to eq(environment.id)
end
end
describe 'GET :/namespace/:project/-/metrics/:dashboard_path?environment=:environment.id' do
let(:dashboard_path) { '.gitlab/dashboards/dashboard_path.yml' }
it 'returns 200' do
send_request(dahboard_path: dashboard_path, environment: environment.id)
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns query param environment' do
send_request(dashboard_path: dashboard_path, environment: environment2.id)
expect(assigns(:environment).id).to eq(environment2.id)
end
context 'when query param environment does not exist' do
it 'responds with 404' do
send_request(dashboard_path: dashboard_path, environment: 99)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
2020-10-24 23:57:45 +05:30
describe 'GET :/namespace/:project/-/metrics/:page' do
it 'returns 200 with path param page' do
2020-11-24 15:15:51 +05:30
send_request(page: 'panel/new', environment: environment.id)
2020-10-24 23:57:45 +05:30
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns 200 with dashboard and path param page' do
2020-11-24 15:15:51 +05:30
send_request(dashboard_path: 'dashboard.yml', page: 'panel/new', environment: environment.id)
2020-10-24 23:57:45 +05:30
expect(response).to have_gitlab_http_status(:ok)
end
end
2020-07-28 23:09:34 +05:30
def send_request(params = {})
2020-10-24 23:57:45 +05:30
get dashboard_route(params)
end
def dashboard_route(params = {})
namespace_project_metrics_dashboard_path(namespace_id: project.namespace, project_id: project, **params)
2020-07-28 23:09:34 +05:30
end
end