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

pull_request_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: 4a30f225d66035349d4861ea07f5d1436f57669a (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BitbucketImport::Importers::PullRequestNotesImporter, feature_category: :importers do
  let_it_be(:project) do
    create(:project, :import_started,
      import_data_attributes: {
        credentials: { 'base_uri' => 'http://bitbucket.org/', 'user' => 'bitbucket', 'password' => 'password' }
      }
    )
  end

  let_it_be(:merge_request) { create(:merge_request, source_project: project) }

  let(:hash) { { iid: merge_request.iid } }
  let(:importer_helper) { Gitlab::BitbucketImport::Importer.new(project) }

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

  before do
    allow(Gitlab::BitbucketImport::Importer).to receive(:new).and_return(importer_helper)
  end

  describe '#execute' do
    it 'calls Importer.import_pull_request_comments' do
      expect(importer_helper).to receive(:import_pull_request_comments).once

      importer.execute
    end

    context 'when the merge request does not exist' do
      let(:hash) { { iid: 'nonexistent' } }

      it 'does not call Importer.import_pull_request_comments' do
        expect(importer_helper).not_to receive(:import_pull_request_comments)

        importer.execute
      end
    end

    context 'when the merge request exists but not for this project' do
      let_it_be(:another_project) { create(:project) }

      before do
        merge_request.update!(source_project: another_project, target_project: another_project)
      end

      it 'does not call Importer.import_pull_request_comments' do
        expect(importer_helper).not_to receive(:import_pull_request_comments)

        importer.execute
      end
    end

    context 'when an error is raised' do
      before do
        allow(importer_helper).to receive(:import_pull_request_comments).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
  end
end