Welcome to mirror list, hosted at ThFree Co, Russian Federation.

delete_jobs_spec.rb « sidekiq_queues « admin « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 64ea6d32f5f4f7de1a38c5b8c0956bd08d6072e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Deleting Sidekiq jobs', :clean_gitlab_redis_queues, feature_category: :not_owned do
  include GraphqlHelpers

  let_it_be(:admin) { create(:admin) }

  let(:queue) { 'authorized_projects' }

  let(:variables) { { user: admin.username, worker_class: 'AuthorizedProjectsWorker', queue_name: queue } }
  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(queue).clear
        Sidekiq::Testing.disable!(&example)
        Sidekiq::Queue.new(queue).clear
      end

      def add_job(user, args)
        Sidekiq::Client.push(
          'class' => 'AuthorizedProjectsWorker',
          'queue' => queue,
          'args' => args,
          'meta.user' => user.username
        )
        raise 'Not enqueued!' if Sidekiq::Queue.new(queue).size.zero?
      end

      it 'returns info about the deleted jobs' do
        add_job(admin, [1])
        add_job(admin, [2])
        add_job(create(:user), [3])

        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: queue } }

      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