Commit b01efeae authored by Peter Leitzen's avatar Peter Leitzen

Test that alert's environment is verified

Check that creating an alert for an project non-specific environment
is not possible and return 204.
parent 745eebda
......@@ -30,7 +30,7 @@ module Projects
def create
@alert = project.prometheus_alerts.create(alerts_params)
if @alert
if @alert.persisted?
schedule_prometheus_update!
render json: serialize_as_json(@alert)
......
---
title: Return proper status code when creation of an alert fails
merge_request: 7360
author: Peter Leitzen
type: fixed
......@@ -146,6 +146,21 @@ describe Projects::Prometheus::AlertsController do
expect(response).to have_gitlab_http_status(200)
expect(JSON.parse(response.body)).to include(alert_params)
end
context 'with a project non-specific environment' do
let(:environment) { create(:environment) }
it 'returns 204 status' do
post :create, project_params(
operator: ">",
threshold: "1",
environment_id: environment.id,
prometheus_metric_id: metric.id
)
expect(response).to have_gitlab_http_status(:no_content)
end
end
end
describe 'POST #update' do
......
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