debian-mirror-gitlab/spec/requests/api/admin/sidekiq_spec.rb

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

65 lines
2 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe API::Admin::Sidekiq, :clean_gitlab_redis_queues, feature_category: :shared do
2020-04-08 14:13:33 +05:30
let_it_be(:admin) { create(:admin) }
describe 'DELETE /admin/sidekiq/queues/:queue_name' do
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, args)
Sidekiq::Client.push(
'class' => 'AuthorizedProjectsWorker',
'queue' => 'authorized_projects',
'args' => args,
'meta.user' => user.username
)
end
context 'valid request' do
2023-05-27 22:25:52 +05:30
before do
2020-04-08 14:13:33 +05:30
add_job(admin, [1])
add_job(admin, [2])
add_job(create(:user), [3])
2023-05-27 22:25:52 +05:30
end
let_it_be(:path) { "/admin/sidekiq/queues/authorized_projects?user=#{admin.username}&worker_class=AuthorizedProjectsWorker" }
2020-04-08 14:13:33 +05:30
2023-06-20 00:43:36 +05:30
it_behaves_like 'DELETE request permissions for admin mode' do
let(:success_status_code) { :ok }
end
2023-05-27 22:25:52 +05:30
it 'returns info about the deleted jobs' do
delete api(path, admin, admin_mode: true)
2020-04-08 14:13:33 +05:30
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
2023-05-27 22:25:52 +05:30
delete api("/admin/sidekiq/queues/authorized_projects?user_2=#{admin.username}", admin, admin_mode: true)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
end
end
context 'when the queue does not exist' do
it 'returns a 404' do
2023-05-27 22:25:52 +05:30
delete api("/admin/sidekiq/queues/authorized_projects_2?user=#{admin.username}", admin, admin_mode: true)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
end
end