2020-01-08 04:07:53 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe 'Self-Monitoring project requests' do
|
2020-01-08 04:07:53 -05:00
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
|
|
|
describe 'POST #create_self_monitoring_project' do
|
|
|
|
let(:worker_class) { SelfMonitoringProjectCreateWorker }
|
|
|
|
|
|
|
|
subject { post create_self_monitoring_project_admin_application_settings_path }
|
|
|
|
|
|
|
|
it_behaves_like 'not accessible to non-admin users'
|
|
|
|
|
2020-12-07 07:10:00 -05:00
|
|
|
context 'with admin user', :enable_admin_mode do
|
2020-01-08 04:07:53 -05:00
|
|
|
before do
|
|
|
|
login_as(admin)
|
|
|
|
end
|
|
|
|
|
2020-02-14 10:09:08 -05:00
|
|
|
context 'when the self monitoring project is created' do
|
2020-01-10 16:07:33 -05:00
|
|
|
let(:status_api) { status_create_self_monitoring_project_admin_application_settings_path }
|
2020-01-08 04:07:53 -05:00
|
|
|
|
2020-01-10 16:07:33 -05:00
|
|
|
it_behaves_like 'triggers async worker, returns sidekiq job_id with response accepted'
|
2020-01-08 04:07:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #status_create_self_monitoring_project' do
|
|
|
|
let(:worker_class) { SelfMonitoringProjectCreateWorker }
|
|
|
|
let(:job_id) { 'job_id' }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
get status_create_self_monitoring_project_admin_application_settings_path,
|
|
|
|
params: { job_id: job_id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'not accessible to non-admin users'
|
|
|
|
|
2020-12-07 07:10:00 -05:00
|
|
|
context 'with admin user', :enable_admin_mode do
|
2020-01-08 04:07:53 -05:00
|
|
|
before do
|
|
|
|
login_as(admin)
|
|
|
|
end
|
|
|
|
|
2020-02-14 10:09:08 -05:00
|
|
|
context 'when the self monitoring project is being created' do
|
2020-01-10 16:07:33 -05:00
|
|
|
it_behaves_like 'handles invalid job_id'
|
|
|
|
|
|
|
|
context 'when job is in progress' do
|
|
|
|
before do
|
|
|
|
allow(worker_class).to receive(:in_progress?)
|
|
|
|
.with(job_id)
|
|
|
|
.and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'sets polling header and returns accepted' do
|
2020-01-13 10:07:53 -05:00
|
|
|
let(:in_progress_message) { 'Job to create self-monitoring project is in progress' }
|
2020-01-10 16:07:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when self-monitoring project and job do not exist' do
|
|
|
|
let(:job_id) { nil }
|
|
|
|
|
|
|
|
it 'returns bad_request' do
|
2020-01-29 07:09:08 -05:00
|
|
|
create(:application_setting)
|
|
|
|
|
2020-01-10 16:07:33 -05:00
|
|
|
subject
|
2020-01-08 04:07:53 -05:00
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2020-01-10 16:07:33 -05:00
|
|
|
expect(json_response).to eq(
|
|
|
|
'message' => 'Self-monitoring project does not exist. Please check logs ' \
|
|
|
|
'for any error messages'
|
|
|
|
)
|
2020-01-08 04:07:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when self-monitoring project exists' do
|
2020-01-29 07:09:08 -05:00
|
|
|
let(:project) { create(:project) }
|
2020-01-08 04:07:53 -05:00
|
|
|
|
|
|
|
before do
|
2020-01-29 07:09:08 -05:00
|
|
|
create(:application_setting, self_monitoring_project_id: project.id)
|
2020-01-08 04:07:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not need job_id' do
|
|
|
|
get status_create_self_monitoring_project_admin_application_settings_path
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
expect(json_response).to eq(
|
2020-01-29 07:09:08 -05:00
|
|
|
'project_id' => project.id,
|
2020-01-08 04:07:53 -05:00
|
|
|
'project_full_path' => project.full_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-10 16:07:33 -05:00
|
|
|
it 'returns success with job_id' do
|
2020-01-08 04:07:53 -05:00
|
|
|
subject
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
expect(json_response).to eq(
|
2020-01-29 07:09:08 -05:00
|
|
|
'project_id' => project.id,
|
2020-01-08 04:07:53 -05:00
|
|
|
'project_full_path' => project.full_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-13 10:07:53 -05:00
|
|
|
|
|
|
|
describe 'DELETE #delete_self_monitoring_project' do
|
|
|
|
let(:worker_class) { SelfMonitoringProjectDeleteWorker }
|
|
|
|
|
|
|
|
subject { delete delete_self_monitoring_project_admin_application_settings_path }
|
|
|
|
|
|
|
|
it_behaves_like 'not accessible to non-admin users'
|
|
|
|
|
2020-12-07 07:10:00 -05:00
|
|
|
context 'with admin user', :enable_admin_mode do
|
2020-01-13 10:07:53 -05:00
|
|
|
before do
|
|
|
|
login_as(admin)
|
|
|
|
end
|
|
|
|
|
2020-02-14 10:09:08 -05:00
|
|
|
context 'when the self monitoring project is deleted' do
|
2020-01-13 10:07:53 -05:00
|
|
|
let(:status_api) { status_delete_self_monitoring_project_admin_application_settings_path }
|
|
|
|
|
|
|
|
it_behaves_like 'triggers async worker, returns sidekiq job_id with response accepted'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #status_delete_self_monitoring_project' do
|
|
|
|
let(:worker_class) { SelfMonitoringProjectDeleteWorker }
|
|
|
|
let(:job_id) { 'job_id' }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
get status_delete_self_monitoring_project_admin_application_settings_path,
|
|
|
|
params: { job_id: job_id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'not accessible to non-admin users'
|
|
|
|
|
2020-12-07 07:10:00 -05:00
|
|
|
context 'with admin user', :enable_admin_mode do
|
2020-01-13 10:07:53 -05:00
|
|
|
before do
|
|
|
|
login_as(admin)
|
|
|
|
end
|
|
|
|
|
2020-02-14 10:09:08 -05:00
|
|
|
context 'when the self monitoring project is being deleted' do
|
2020-01-13 10:07:53 -05:00
|
|
|
it_behaves_like 'handles invalid job_id'
|
|
|
|
|
|
|
|
context 'when job is in progress' do
|
|
|
|
before do
|
|
|
|
allow(worker_class).to receive(:in_progress?)
|
|
|
|
.with(job_id)
|
|
|
|
.and_return(true)
|
|
|
|
|
2020-01-28 10:08:36 -05:00
|
|
|
stub_application_setting(self_monitoring_project_id: 1)
|
2020-01-13 10:07:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'sets polling header and returns accepted' do
|
|
|
|
let(:in_progress_message) { 'Job to delete self-monitoring project is in progress' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when self-monitoring project exists and job does not exist' do
|
|
|
|
before do
|
2020-01-29 07:09:08 -05:00
|
|
|
create(:application_setting, self_monitoring_project_id: create(:project).id)
|
2020-01-13 10:07:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns bad_request' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
expect(json_response).to eq(
|
|
|
|
'message' => 'Self-monitoring project was not deleted. Please check logs ' \
|
|
|
|
'for any error messages'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when self-monitoring project does not exist' do
|
2020-01-29 07:09:08 -05:00
|
|
|
before do
|
|
|
|
create(:application_setting)
|
|
|
|
end
|
|
|
|
|
2020-01-13 10:07:53 -05:00
|
|
|
it 'does not need job_id' do
|
|
|
|
get status_delete_self_monitoring_project_admin_application_settings_path
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
expect(json_response).to eq(
|
|
|
|
'message' => 'Self-monitoring project has been successfully deleted'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns success with job_id' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
expect(json_response).to eq(
|
|
|
|
'message' => 'Self-monitoring project has been successfully deleted'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-08 04:07:53 -05:00
|
|
|
end
|