diff options
Diffstat (limited to 'spec/controllers/projects/prometheus')
-rw-r--r-- | spec/controllers/projects/prometheus/alerts_controller_spec.rb | 131 |
1 files changed, 0 insertions, 131 deletions
diff --git a/spec/controllers/projects/prometheus/alerts_controller_spec.rb b/spec/controllers/projects/prometheus/alerts_controller_spec.rb index d66ad445c32..f42119e7811 100644 --- a/spec/controllers/projects/prometheus/alerts_controller_spec.rb +++ b/spec/controllers/projects/prometheus/alerts_controller_spec.rb @@ -226,137 +226,6 @@ RSpec.describe Projects::Prometheus::AlertsController do end end - describe 'POST #create' do - let(:schedule_update_service) { spy } - - let(:alert_params) do - { - 'title' => metric.title, - 'query' => metric.query, - 'operator' => '>', - 'threshold' => 1.0, - 'runbook_url' => 'https://sample.runbook.com' - } - end - - def make_request(opts = {}) - post :create, params: request_params( - opts, - operator: '>', - threshold: '1', - runbook_url: 'https://sample.runbook.com', - environment_id: environment, - prometheus_metric_id: metric - ) - end - - it 'creates a new prometheus alert' do - allow(::Clusters::Applications::ScheduleUpdateService) - .to receive(:new).and_return(schedule_update_service) - - make_request - - expect(schedule_update_service).to have_received(:execute) - expect(response).to have_gitlab_http_status(:ok) - expect(json_response).to include(alert_params) - end - - it 'returns bad_request for an invalid metric' do - make_request(prometheus_metric_id: 'invalid') - - expect(response).to have_gitlab_http_status(:bad_request) - end - - it_behaves_like 'unprivileged' - it_behaves_like 'project non-specific environment', :bad_request - end - - describe 'PUT #update' do - let(:schedule_update_service) { spy } - - let(:alert) do - create(:prometheus_alert, - project: project, - environment: environment, - prometheus_metric: metric) - end - - let(:alert_params) do - { - 'id' => alert.id, - 'title' => alert.title, - 'query' => alert.query, - 'operator' => '<', - 'threshold' => alert.threshold, - 'alert_path' => alert_path(alert) - } - end - - before do - allow(::Clusters::Applications::ScheduleUpdateService) - .to receive(:new).and_return(schedule_update_service) - end - - def make_request(opts = {}) - put :update, params: request_params( - opts, - id: alert.prometheus_metric_id, - operator: '<', - environment_id: alert.environment - ) - end - - it 'updates an already existing prometheus alert' do - expect { make_request(operator: '<') } - .to change { alert.reload.operator }.to('lt') - - expect(schedule_update_service).to have_received(:execute) - expect(response).to have_gitlab_http_status(:ok) - expect(json_response).to include(alert_params) - end - - it 'returns bad_request for an invalid alert data' do - make_request(runbook_url: 'bad-url') - - expect(response).to have_gitlab_http_status(:bad_request) - end - - it_behaves_like 'unprivileged' - it_behaves_like 'project non-specific environment', :not_found - it_behaves_like 'project non-specific metric', :not_found - end - - describe 'DELETE #destroy' do - let(:schedule_update_service) { spy } - - let!(:alert) do - create(:prometheus_alert, project: project, prometheus_metric: metric) - end - - before do - allow(::Clusters::Applications::ScheduleUpdateService) - .to receive(:new).and_return(schedule_update_service) - end - - def make_request(opts = {}) - delete :destroy, params: request_params( - opts, - id: alert.prometheus_metric_id, - environment_id: alert.environment - ) - end - - it 'destroys the specified prometheus alert' do - expect { make_request }.to change { PrometheusAlert.count }.by(-1) - - expect(schedule_update_service).to have_received(:execute) - end - - it_behaves_like 'unprivileged' - it_behaves_like 'project non-specific environment', :not_found - it_behaves_like 'project non-specific metric', :not_found - end - describe 'GET #metrics_dashboard' do let!(:alert) do create(:prometheus_alert, |