diff options
Diffstat (limited to 'spec/requests/api/users_spec.rb')
-rw-r--r-- | spec/requests/api/users_spec.rb | 165 |
1 files changed, 0 insertions, 165 deletions
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 3737c91adbc..2bbcf6b3f38 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -4851,169 +4851,4 @@ RSpec.describe API::Users, :aggregate_failures, feature_category: :user_profile let(:attributable) { user } let(:other_attributable) { admin } end - - describe 'POST /user/runners', feature_category: :runner_fleet do - subject(:request) { post api(path, current_user, **post_args), params: runner_attrs } - - let_it_be(:group_owner) { create(:user) } - let_it_be(:group) { create(:group) } - let_it_be(:project) { create(:project, namespace: group) } - - let(:post_args) { { admin_mode: true } } - let(:runner_attrs) { { runner_type: 'instance_type' } } - let(:path) { '/user/runners' } - - before do - group.add_owner(group_owner) - end - - shared_context 'returns forbidden when user does not have sufficient permissions' do - let(:current_user) { admin } - let(:post_args) { { admin_mode: false } } - - it 'does not create a runner' do - expect do - request - - expect(response).to have_gitlab_http_status(:forbidden) - end.not_to change { Ci::Runner.count } - end - end - - shared_examples 'creates a runner' do - it 'creates a runner' do - expect do - request - - expect(response).to have_gitlab_http_status(:created) - end.to change { Ci::Runner.count }.by(1) - end - end - - shared_examples 'fails to create runner with :bad_request' do - it 'does not create runner' do - expect do - request - - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['message']).to include(expected_error) - end.not_to change { Ci::Runner.count } - end - end - - context 'when runner_type is :instance_type' do - let(:runner_attrs) { { runner_type: 'instance_type' } } - - context 'when user has sufficient permissions' do - let(:current_user) { admin } - - it_behaves_like 'creates a runner' - end - - it_behaves_like 'returns forbidden when user does not have sufficient permissions' - - context 'when model validation fails' do - let(:runner_attrs) { { runner_type: 'instance_type', run_untagged: false, tag_list: [] } } - let(:current_user) { admin } - - it_behaves_like 'fails to create runner with :bad_request' do - let(:expected_error) { 'Tags list can not be empty' } - end - end - end - - context 'when runner_type is :group_type' do - let(:post_args) { {} } - - context 'when group_id is specified' do - let(:runner_attrs) { { runner_type: 'group_type', group_id: group.id } } - - context 'when user has sufficient permissions' do - let(:current_user) { group_owner } - - it_behaves_like 'creates a runner' - end - - it_behaves_like 'returns forbidden when user does not have sufficient permissions' - end - - context 'when group_id is not specified' do - let(:runner_attrs) { { runner_type: 'group_type' } } - let(:current_user) { group_owner } - - it 'fails to create runner with :bad_request' do - expect do - request - - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['error']).to include('group_id is missing') - end.not_to change { Ci::Runner.count } - end - end - end - - context 'when runner_type is :project_type' do - let(:post_args) { {} } - - context 'when project_id is specified' do - let(:runner_attrs) { { runner_type: 'project_type', project_id: project.id } } - - context 'when user has sufficient permissions' do - let(:current_user) { group_owner } - - it_behaves_like 'creates a runner' - end - - it_behaves_like 'returns forbidden when user does not have sufficient permissions' - end - - context 'when project_id is not specified' do - let(:runner_attrs) { { runner_type: 'project_type' } } - let(:current_user) { group_owner } - - it 'fails to create runner with :bad_request' do - expect do - request - - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['error']).to include('project_id is missing') - end.not_to change { Ci::Runner.count } - end - end - end - - context 'with missing runner_type' do - let(:runner_attrs) { {} } - let(:current_user) { admin } - - it 'fails to create runner with :bad_request' do - expect do - request - - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['error']).to eq('runner_type is missing, runner_type does not have a valid value') - end.not_to change { Ci::Runner.count } - end - end - - context 'with unknown runner_type' do - let(:runner_attrs) { { runner_type: 'unknown' } } - let(:current_user) { admin } - - it 'fails to create runner with :bad_request' do - expect do - request - - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['error']).to eq('runner_type does not have a valid value') - end.not_to change { Ci::Runner.count } - end - end - - it 'returns a 401 error if unauthorized' do - post api(path), params: runner_attrs - - expect(response).to have_gitlab_http_status(:unauthorized) - end - end end |