diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-03 15:08:08 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-03 15:08:08 +0000 |
commit | 946771d0b016ae92b15a60bc3290a33b94191ffe (patch) | |
tree | 64862c2433989483f5fce45d5539242577a362eb /spec/requests/api/graphql | |
parent | f1e2fca19a90a6992c2020cf8c2159cfb0b61bca (diff) | |
download | gitlab-ce-946771d0b016ae92b15a60bc3290a33b94191ffe.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api/graphql')
-rw-r--r-- | spec/requests/api/graphql/mutations/admin/sidekiq_queues/delete_jobs_spec.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/mutations/admin/sidekiq_queues/delete_jobs_spec.rb b/spec/requests/api/graphql/mutations/admin/sidekiq_queues/delete_jobs_spec.rb new file mode 100644 index 00000000000..9451587fac3 --- /dev/null +++ b/spec/requests/api/graphql/mutations/admin/sidekiq_queues/delete_jobs_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Deleting Sidekiq jobs' do + include GraphqlHelpers + + let_it_be(:admin) { create(:admin) } + + let(:variables) { { user: admin.username, queue_name: 'authorized_projects' } } + let(:mutation) { graphql_mutation(:admin_sidekiq_queues_delete_jobs, variables) } + + def mutation_response + graphql_mutation_response(:admin_sidekiq_queues_delete_jobs) + end + + context 'when the user is not an admin' do + let(:current_user) { create(:user) } + + it_behaves_like 'a mutation that returns top-level errors', + errors: ['You must be an admin to use this mutation'] + end + + context 'when the user is an admin' do + let(:current_user) { admin } + + context 'valid request' do + around do |example| + Sidekiq::Queue.new('authorized_projects').clear + Sidekiq::Testing.disable!(&example) + Sidekiq::Queue.new('authorized_projects').clear + end + + def add_job(user) + Sidekiq::Client.push( + 'class' => 'AuthorizedProjectsWorker', + 'queue' => 'authorized_projects', + 'args' => [user.id], + 'meta.user' => user.username + ) + end + + it 'returns info about the deleted jobs' do + add_job(admin) + add_job(admin) + add_job(create(:user)) + + post_graphql_mutation(mutation, current_user: admin) + + expect(mutation_response['errors']).to be_empty + expect(mutation_response['result']).to eq('completed' => true, + 'deletedJobs' => 2, + 'queueSize' => 1) + end + end + + context 'when no required params are provided' do + let(:variables) { { queue_name: 'authorized_projects' } } + + it_behaves_like 'a mutation that returns errors in the response', + errors: ['No metadata provided'] + end + + context 'when the queue does not exist' do + let(:variables) { { user: admin.username, queue_name: 'authorized_projects_2' } } + + it_behaves_like 'a mutation that returns top-level errors', + errors: ['Queue authorized_projects_2 not found'] + end + end +end |