summaryrefslogtreecommitdiff
path: root/spec/workers/concerns/gitlab/github_import/notify_upon_death_spec.rb
blob: 200cdffd560ee49168797251e518c766af1e5d5f (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
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::GithubImport::NotifyUponDeath do
  let(:worker_class) do
    Class.new do
      include Sidekiq::Worker
      include Gitlab::GithubImport::NotifyUponDeath
    end
  end

  describe '.sidekiq_retries_exhausted' do
    it 'notifies the JobWaiter when 3 arguments are given and the last is a String' do
      job = { 'args' => [12, {}, '123abc'], 'jid' => '123' }

      expect(Gitlab::JobWaiter)
        .to receive(:notify)
        .with('123abc', '123')

      worker_class.sidekiq_retries_exhausted_block.call(job)
    end

    it 'does not notify the JobWaiter when only 2 arguments are given' do
      job = { 'args' => [12, {}], 'jid' => '123' }

      expect(Gitlab::JobWaiter)
        .not_to receive(:notify)

      worker_class.sidekiq_retries_exhausted_block.call(job)
    end

    it 'does not notify the JobWaiter when only 1 argument is given' do
      job = { 'args' => [12], 'jid' => '123' }

      expect(Gitlab::JobWaiter)
        .not_to receive(:notify)

      worker_class.sidekiq_retries_exhausted_block.call(job)
    end

    it 'does not notify the JobWaiter when the last argument is not a String' do
      job = { 'args' => [12, {}, 40], 'jid' => '123' }

      expect(Gitlab::JobWaiter)
        .not_to receive(:notify)

      worker_class.sidekiq_retries_exhausted_block.call(job)
    end
  end
end