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

issues_notes_importer_spec.rb « importers « bitbucket_import « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 043cd7f17b93d06800405989292221787f259e09 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BitbucketImport::Importers::IssuesNotesImporter, feature_category: :importers do
  let_it_be(:project) { create(:project, :import_started) }
  # let_it_be(:merge_request_1) { create(:merge_request, source_project: project) }
  # let_it_be(:merge_request_2) { create(:merge_request, source_project: project, source_branch: 'other-branch') }
  let_it_be(:issue_1) { create(:issue, project: project) }
  let_it_be(:issue_2) { create(:issue, project: project) }

  subject(:importer) { described_class.new(project) }

  describe '#execute', :clean_gitlab_redis_cache do
    it 'imports the notes from each issue in parallel', :aggregate_failures do
      expect(Gitlab::BitbucketImport::ImportIssueNotesWorker).to receive(:perform_in).twice

      waiter = importer.execute

      expect(waiter).to be_an_instance_of(Gitlab::JobWaiter)
      expect(waiter.jobs_remaining).to eq(2)
      expect(Gitlab::Cache::Import::Caching.values_from_set(importer.already_enqueued_cache_key))
        .to match_array(%w[1 2])
    end

    context 'when an error is raised' do
      before do
        allow(importer).to receive(:mark_as_enqueued).and_raise(StandardError)
      end

      it 'tracks the failure and does not fail' do
        expect(Gitlab::Import::ImportFailureService).to receive(:track).once

        importer.execute
      end
    end

    context 'when issue was already enqueued' do
      before do
        Gitlab::Cache::Import::Caching.set_add(importer.already_enqueued_cache_key, 2)
      end

      it 'does not schedule job for enqueued issues', :aggregate_failures do
        expect(Gitlab::BitbucketImport::ImportIssueNotesWorker).to receive(:perform_in).once

        waiter = importer.execute

        expect(waiter).to be_an_instance_of(Gitlab::JobWaiter)
        expect(waiter.jobs_remaining).to eq(2)
      end
    end
  end
end