diff options
Diffstat (limited to 'spec/requests/api/admin/batched_background_migrations_spec.rb')
-rw-r--r-- | spec/requests/api/admin/batched_background_migrations_spec.rb | 93 |
1 files changed, 35 insertions, 58 deletions
diff --git a/spec/requests/api/admin/batched_background_migrations_spec.rb b/spec/requests/api/admin/batched_background_migrations_spec.rb index d946ac17f3f..e88fba3fbe7 100644 --- a/spec/requests/api/admin/batched_background_migrations_spec.rb +++ b/spec/requests/api/admin/batched_background_migrations_spec.rb @@ -4,22 +4,23 @@ require 'spec_helper' RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :database do let(:admin) { create(:admin) } - let(:unauthorized_user) { create(:user) } describe 'GET /admin/batched_background_migrations/:id' do let!(:migration) { create(:batched_background_migration, :paused) } let(:database) { :main } let(:params) { { database: database } } + let(:path) { "/admin/batched_background_migrations/#{migration.id}" } + + it_behaves_like "GET request permissions for admin mode" subject(:show_migration) do - get api("/admin/batched_background_migrations/#{migration.id}", admin), params: { database: database } + get api(path, admin, admin_mode: true), params: { database: database } end it 'fetches the batched background migration' do show_migration aggregate_failures "testing response" do - expect(response).to have_gitlab_http_status(:ok) expect(json_response['id']).to eq(migration.id) expect(json_response['status']).to eq('paused') expect(json_response['job_class_name']).to eq(migration.job_class_name) @@ -29,7 +30,8 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab context 'when the batched background migration does not exist' do it 'returns 404' do - get api("/admin/batched_background_migrations/#{non_existing_record_id}", admin), params: params + get api("/admin/batched_background_migrations/#{non_existing_record_id}", admin, admin_mode: true), + params: params expect(response).to have_gitlab_http_status(:not_found) end @@ -50,19 +52,11 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab end end - context 'when authenticated as a non-admin user' do - it 'returns 403' do - get api("/admin/batched_background_migrations/#{migration.id}", unauthorized_user) - - expect(response).to have_gitlab_http_status(:forbidden) - end - end - context 'when the database name does not exist' do let(:database) { :wrong_database } - it 'returns bad request' do - get api("/admin/batched_background_migrations/#{migration.id}", admin), params: params + it 'returns bad request', :aggregate_failures do + get api(path, admin, admin_mode: true), params: params expect(response).to have_gitlab_http_status(:bad_request) expect(response.body).to include('database does not have a valid value') @@ -72,13 +66,15 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab describe 'GET /admin/batched_background_migrations' do let!(:migration) { create(:batched_background_migration) } + let(:path) { '/admin/batched_background_migrations' } + + it_behaves_like "GET request permissions for admin mode" context 'when is an admin user' do it 'returns batched background migrations' do - get api('/admin/batched_background_migrations', admin) + get api(path, admin, admin_mode: true) aggregate_failures "testing response" do - expect(response).to have_gitlab_http_status(:ok) expect(json_response.count).to eq(1) expect(json_response.first['id']).to eq(migration.id) expect(json_response.first['job_class_name']).to eq(migration.job_class_name) @@ -105,14 +101,14 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab expect(Gitlab::Database::SharedModel).to receive(:using_connection).with(ci_model.connection).and_yield - get api('/admin/batched_background_migrations', admin), params: params + get api(path, admin, admin_mode: true), params: params end context 'when the database name does not exist' do let(:database) { :wrong_database } - it 'returns bad request' do - get api("/admin/batched_background_migrations", admin), params: params + it 'returns bad request', :aggregate_failures do + get api(path, admin, admin_mode: true), params: params expect(response).to have_gitlab_http_status(:bad_request) expect(response.body).to include('database does not have a valid value') @@ -127,10 +123,9 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab create(:batched_background_migration, :active, gitlab_schema: schema) end - get api('/admin/batched_background_migrations', admin), params: params + get api(path, admin, admin_mode: true), params: params aggregate_failures "testing response" do - expect(response).to have_gitlab_http_status(:ok) expect(json_response.count).to eq(1) expect(json_response.first['id']).to eq(ci_database_migration.id) expect(json_response.first['job_class_name']).to eq(ci_database_migration.job_class_name) @@ -142,30 +137,24 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab end end end - - context 'when authenticated as a non-admin user' do - it 'returns 403' do - get api('/admin/batched_background_migrations', unauthorized_user) - - expect(response).to have_gitlab_http_status(:forbidden) - end - end end describe 'PUT /admin/batched_background_migrations/:id/resume' do let!(:migration) { create(:batched_background_migration, :paused) } let(:database) { :main } let(:params) { { database: database } } + let(:path) { "/admin/batched_background_migrations/#{migration.id}/resume" } + + it_behaves_like "PUT request permissions for admin mode" subject(:resume) do - put api("/admin/batched_background_migrations/#{migration.id}/resume", admin), params: params + put api(path, admin, admin_mode: true), params: params end it 'pauses the batched background migration' do resume aggregate_failures "testing response" do - expect(response).to have_gitlab_http_status(:ok) expect(json_response['id']).to eq(migration.id) expect(json_response['status']).to eq('active') end @@ -173,7 +162,8 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab context 'when the batched background migration does not exist' do it 'returns 404' do - put api("/admin/batched_background_migrations/#{non_existing_record_id}/resume", admin), params: params + put api("/admin/batched_background_migrations/#{non_existing_record_id}/resume", admin, admin_mode: true), + params: params expect(response).to have_gitlab_http_status(:not_found) end @@ -183,7 +173,7 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab let!(:migration) { create(:batched_background_migration, :failed) } it 'returns 422' do - put api("/admin/batched_background_migrations/#{migration.id}/resume", admin), params: params + put api(path, admin, admin_mode: true), params: params expect(response).to have_gitlab_http_status(:unprocessable_entity) end @@ -206,34 +196,28 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab context 'when the database name does not exist' do let(:database) { :wrong_database } - it 'returns bad request' do - put api("/admin/batched_background_migrations/#{migration.id}/resume", admin), params: params + it 'returns bad request', :aggregate_failures do + put api(path, admin, admin_mode: true), params: params expect(response).to have_gitlab_http_status(:bad_request) expect(response.body).to include('database does not have a valid value') end end end - - context 'when authenticated as a non-admin user' do - it 'returns 403' do - put api("/admin/batched_background_migrations/#{migration.id}/resume", unauthorized_user) - - expect(response).to have_gitlab_http_status(:forbidden) - end - end end describe 'PUT /admin/batched_background_migrations/:id/pause' do let!(:migration) { create(:batched_background_migration, :active) } let(:database) { :main } let(:params) { { database: database } } + let(:path) { "/admin/batched_background_migrations/#{migration.id}/pause" } + + it_behaves_like "PUT request permissions for admin mode" it 'pauses the batched background migration' do - put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: params + put api(path, admin, admin_mode: true), params: params aggregate_failures "testing response" do - expect(response).to have_gitlab_http_status(:ok) expect(json_response['id']).to eq(migration.id) expect(json_response['status']).to eq('paused') end @@ -241,7 +225,8 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab context 'when the batched background migration does not exist' do it 'returns 404' do - put api("/admin/batched_background_migrations/#{non_existing_record_id}/pause", admin), params: params + put api("/admin/batched_background_migrations/#{non_existing_record_id}/pause", admin, admin_mode: true), + params: params expect(response).to have_gitlab_http_status(:not_found) end @@ -251,7 +236,7 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab let!(:migration) { create(:batched_background_migration, :failed) } it 'returns 422' do - put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: params + put api(path, admin, admin_mode: true), params: params expect(response).to have_gitlab_http_status(:unprocessable_entity) end @@ -268,27 +253,19 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations, feature_category: :datab it 'uses the correct connection' do expect(Gitlab::Database::SharedModel).to receive(:using_connection).with(ci_model.connection).and_yield - put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: params + put api(path, admin, admin_mode: true), params: params end context 'when the database name does not exist' do let(:database) { :wrong_database } - it 'returns bad request' do - put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: params + it 'returns bad request', :aggregate_failures do + put api(path, admin, admin_mode: true), params: params expect(response).to have_gitlab_http_status(:bad_request) expect(response.body).to include('database does not have a valid value') end end end - - context 'when authenticated as a non-admin user' do - it 'returns 403' do - put api("/admin/batched_background_migrations/#{non_existing_record_id}/pause", unauthorized_user) - - expect(response).to have_gitlab_http_status(:forbidden) - end - end end end |