diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/graphql/mutations/ci/runner/bulk_delete_spec.rb | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/graphql/mutations/ci/runner/bulk_delete_spec.rb')
-rw-r--r-- | spec/graphql/mutations/ci/runner/bulk_delete_spec.rb | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/spec/graphql/mutations/ci/runner/bulk_delete_spec.rb b/spec/graphql/mutations/ci/runner/bulk_delete_spec.rb index f47f1b9869e..2eccfd3409f 100644 --- a/spec/graphql/mutations/ci/runner/bulk_delete_spec.rb +++ b/spec/graphql/mutations/ci/runner/bulk_delete_spec.rb @@ -6,7 +6,6 @@ RSpec.describe Mutations::Ci::Runner::BulkDelete do include GraphqlHelpers let_it_be(:admin_user) { create(:user, :admin) } - let_it_be(:user) { create(:user) } let(:current_ctx) { { current_user: user } } @@ -19,24 +18,15 @@ RSpec.describe Mutations::Ci::Runner::BulkDelete do sync(resolve(described_class, args: mutation_params, ctx: current_ctx)) end - context 'when the user cannot admin the runner' do - let(:runner) { create(:ci_runner) } - let(:mutation_params) do - { ids: [runner.to_global_id] } - end - - it 'generates an error' do - expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) { response } - end - end - context 'when user can delete runners' do + let_it_be(:group) { create(:group) } + let(:user) { admin_user } let!(:runners) do - create_list(:ci_runner, 2, :instance) + create_list(:ci_runner, 2, :group, groups: [group]) end - context 'when required arguments are missing' do + context 'when runner IDs are missing' do let(:mutation_params) { {} } context 'when admin mode is enabled', :enable_admin_mode do @@ -47,43 +37,48 @@ RSpec.describe Mutations::Ci::Runner::BulkDelete do end context 'with runners specified by id' do - let(:mutation_params) do + let!(:mutation_params) do { ids: runners.map(&:to_global_id) } end context 'when admin mode is enabled', :enable_admin_mode do it 'deletes runners', :aggregate_failures do - expect_next_instance_of( - ::Ci::Runners::BulkDeleteRunnersService, { runners: runners } - ) do |service| - expect(service).to receive(:execute).once.and_call_original - end - expect { response }.to change { Ci::Runner.count }.by(-2) expect(response[:errors]).to be_empty end + end - context 'when runner list is is above limit' do - before do - stub_const('::Ci::Runners::BulkDeleteRunnersService::RUNNER_LIMIT', 1) - end - - it 'only deletes up to the defined limit', :aggregate_failures do - expect { response }.to change { Ci::Runner.count } - .by(-::Ci::Runners::BulkDeleteRunnersService::RUNNER_LIMIT) - expect(response[:errors]).to be_empty - end + it 'ignores unknown keys from service response payload', :aggregate_failures do + expect_next_instance_of( + ::Ci::Runners::BulkDeleteRunnersService, { runners: runners, current_user: user } + ) do |service| + expect(service).to receive(:execute).once.and_return( + ServiceResponse.success( + payload: { + extra_key: 'extra_value', + deleted_count: 10, + deleted_ids: (1..10).to_a, + errors: [] + })) end + + expect(response).not_to include(extra_key: 'extra_value') end + end + end - context 'when admin mode is disabled', :aggregate_failures do - it 'returns error', :aggregate_failures do - expect do - expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do - response - end - end.not_to change { Ci::Runner.count } - end + context 'when the user cannot delete the runner' do + let(:runner) { create(:ci_runner) } + let!(:mutation_params) do + { ids: [runner.to_global_id] } + end + + context 'when user is admin and admin mode is not enabled' do + let(:user) { admin_user } + + it 'returns error', :aggregate_failures do + expect { response }.not_to change { Ci::Runner.count } + expect(response[:errors]).to match_array("User does not have permission to delete any of the runners") end end end |