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

handle_assignees_change_worker_spec.rb « merge_requests « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4b45f3562d661b9c80a0aab565d63c5bdf584ec0 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe MergeRequests::HandleAssigneesChangeWorker do
  include AfterNextHelpers

  let_it_be(:merge_request) { create(:merge_request) }
  let_it_be(:user) { create(:user) }
  let_it_be(:old_assignees) { create_list(:user, 3) }

  let(:user_ids) { old_assignees.map(&:id).to_a }
  let(:options) { {} }
  let(:worker) { described_class.new }

  it_behaves_like 'an idempotent worker' do
    let(:job_args) { [merge_request.id, user.id, user_ids, options] }
  end

  describe '#perform' do
    it 'calls MergeRequests::HandleAssigneesChangeService#execute to handle the changes' do
      expect_next(::MergeRequests::HandleAssigneesChangeService)
        .to receive(:execute).with(merge_request, match_array(old_assignees), options)

      worker.perform(merge_request.id, user.id, user_ids, options)
    end

    context 'when there are no changes' do
      it 'still calls MergeRequests::HandleAssigneesChangeService#execute' do
        expect_next(::MergeRequests::HandleAssigneesChangeService)
          .to receive(:execute).with(merge_request, [], options)

        worker.perform(merge_request.id, user.id, merge_request.assignee_ids, options)
      end
    end

    context 'when the old assignees cannot be found' do
      it 'still calls MergeRequests::HandleAssigneesChangeService#execute' do
        expect_next(::MergeRequests::HandleAssigneesChangeService)
          .to receive(:execute).with(merge_request, [], options)

        worker.perform(merge_request.id, user.id, [non_existing_record_id], options)
      end
    end

    context 'with a non-existing merge request' do
      it 'does nothing' do
        expect(::MergeRequests::HandleAssigneesChangeService).not_to receive(:new)

        worker.perform(non_existing_record_id, user.id, user_ids, options)
      end
    end

    context 'with a non-existing user' do
      it 'does nothing' do
        expect(::MergeRequests::HandleAssigneesChangeService).not_to receive(:new)

        worker.perform(merge_request.id, non_existing_record_id, user_ids, options)
      end
    end
  end
end