summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-03 15:08:08 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-03 15:08:08 +0000
commit946771d0b016ae92b15a60bc3290a33b94191ffe (patch)
tree64862c2433989483f5fce45d5539242577a362eb /spec/requests
parentf1e2fca19a90a6992c2020cf8c2159cfb0b61bca (diff)
downloadgitlab-ce-946771d0b016ae92b15a60bc3290a33b94191ffe.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/admin/sidekiq_spec.rb65
-rw-r--r--spec/requests/api/graphql/mutations/admin/sidekiq_queues/delete_jobs_spec.rb71
2 files changed, 136 insertions, 0 deletions
diff --git a/spec/requests/api/admin/sidekiq_spec.rb b/spec/requests/api/admin/sidekiq_spec.rb
new file mode 100644
index 00000000000..0fb8199eec6
--- /dev/null
+++ b/spec/requests/api/admin/sidekiq_spec.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Admin::Sidekiq do
+ let_it_be(:admin) { create(:admin) }
+
+ describe 'DELETE /admin/sidekiq/queues/:queue_name' do
+ context 'when the user is not an admin' do
+ it 'returns a 403' do
+ delete api("/admin/sidekiq/queues/authorized_projects?user=#{admin.username}", create(:user))
+
+ expect(response).to have_gitlab_http_status(:forbidden)
+ end
+ end
+
+ context 'when the user is an admin' 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
+
+ context 'valid request' do
+ it 'returns info about the deleted jobs' do
+ add_job(admin)
+ add_job(admin)
+ add_job(create(:user))
+
+ delete api("/admin/sidekiq/queues/authorized_projects?user=#{admin.username}", admin)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response).to eq('completed' => true,
+ 'deleted_jobs' => 2,
+ 'queue_size' => 1)
+ end
+ end
+
+ context 'when no required params are provided' do
+ it 'returns a 400' do
+ delete api("/admin/sidekiq/queues/authorized_projects?user_2=#{admin.username}", admin)
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ end
+ end
+
+ context 'when the queue does not exist' do
+ it 'returns a 404' do
+ delete api("/admin/sidekiq/queues/authorized_projects_2?user=#{admin.username}", admin)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
+ end
+end
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