Commit b178dceb authored by syasonik's avatar syasonik Committed by Jan Provaznik

Swap metrics_dashboard to use metric_id and env_id

parent 1a623a92
......@@ -14,7 +14,7 @@ module Projects
prepend_before_action :repository, :project_without_auth, only: [:notify]
before_action :authorize_read_prometheus_alerts!, except: [:notify]
before_action :alert, only: [:update, :show, :destroy]
before_action :alert, only: [:update, :show, :destroy, :metrics_dashboard]
def index
render json: serialize_as_json(alerts)
......@@ -140,7 +140,7 @@ module Projects
def metrics_dashboard_params
{
embedded: true,
prometheus_alert_id: params[:id].to_i
prometheus_alert_id: alert.id
}
end
end
......
......@@ -364,19 +364,33 @@ describe Projects::Prometheus::AlertsController do
end
it 'returns a json object with the correct keys' do
get :metrics_dashboard, params: request_params(id: alert.id), format: :json
get :metrics_dashboard, params: request_params(id: metric.id, environment_id: alert.environment.id), format: :json
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.keys).to contain_exactly('dashboard', 'status')
end
it 'is the correct embed' do
get :metrics_dashboard, params: request_params(id: alert.id), format: :json
get :metrics_dashboard, params: request_params(id: metric.id, environment_id: alert.environment.id), format: :json
title = json_response['dashboard']['panel_groups'][0]['panels'][0]['title']
expect(title).to eq(metric.title)
end
it 'finds the first alert embed without environment_id' do
get :metrics_dashboard, params: request_params(id: metric.id), format: :json
title = json_response['dashboard']['panel_groups'][0]['panels'][0]['title']
expect(title).to eq(metric.title)
end
it 'returns 404 for non-existant alerts' do
get :metrics_dashboard, params: request_params(id: 0), format: :json
expect(response).to have_gitlab_http_status(:not_found)
end
end
def project_params(opts = {})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment