debian-mirror-gitlab/spec/graphql/mutations/ci/runner/bulk_delete_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.5 KiB
Ruby
Raw Normal View History

2022-08-27 11:52:29 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::Ci::Runner::BulkDelete do
include GraphqlHelpers
let_it_be(:admin_user) { create(:user, :admin) }
let(:current_ctx) { { current_user: user } }
let(:mutation_params) do
{}
end
describe '#resolve' do
subject(:response) do
sync(resolve(described_class, args: mutation_params, ctx: current_ctx))
end
context 'when user can delete runners' do
2023-01-13 00:05:48 +05:30
let_it_be(:group) { create(:group) }
2022-08-27 11:52:29 +05:30
let(:user) { admin_user }
let!(:runners) do
2023-01-13 00:05:48 +05:30
create_list(:ci_runner, 2, :group, groups: [group])
2022-08-27 11:52:29 +05:30
end
2023-01-13 00:05:48 +05:30
context 'when runner IDs are missing' do
2022-08-27 11:52:29 +05:30
let(:mutation_params) { {} }
context 'when admin mode is enabled', :enable_admin_mode do
it 'does not return an error' do
is_expected.to match a_hash_including(errors: [])
end
end
end
context 'with runners specified by id' do
2023-01-13 00:05:48 +05:30
let!(:mutation_params) do
2022-08-27 11:52:29 +05:30
{ ids: runners.map(&:to_global_id) }
end
context 'when admin mode is enabled', :enable_admin_mode do
it 'deletes runners', :aggregate_failures do
expect { response }.to change { Ci::Runner.count }.by(-2)
expect(response[:errors]).to be_empty
end
2023-01-13 00:05:48 +05:30
end
2022-08-27 11:52:29 +05:30
2023-01-13 00:05:48 +05:30
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: []
}))
2022-08-27 11:52:29 +05:30
end
2023-01-13 00:05:48 +05:30
expect(response).not_to include(extra_key: 'extra_value')
2022-08-27 11:52:29 +05:30
end
2023-01-13 00:05:48 +05:30
end
end
2022-08-27 11:52:29 +05:30
2023-01-13 00:05:48 +05:30
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")
2022-08-27 11:52:29 +05:30
end
end
end
end
end