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

import_repository_worker_spec.rb « stage « github_import « gitlab « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f4a306eeb0ca7daf66d843a6bee31c2e7360e0ad (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker, feature_category: :importers do
  let_it_be(:project) { create(:project, :import_started) }

  let(:worker) { described_class.new }

  it_behaves_like Gitlab::GithubImport::StageMethods

  describe '#import' do
    before do
      expect(Gitlab::GithubImport::RefreshImportJidWorker)
        .to receive(:perform_in_the_future)
        .with(project.id, '123')

      expect(worker)
        .to receive(:jid)
        .and_return('123')
    end

    context 'when the import succeeds' do
      context 'with issues' do
        it 'schedules the importing of the base data' do
          client = double(:client)
          options = { state: 'all', sort: 'number', direction: 'desc', per_page: '1' }

          expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance|
            expect(instance).to receive(:execute).and_return(true)
          end

          expect(InternalId).to receive(:exists?).and_return(false)
          expect(client).to receive(:each_object).with(
            :issues, project.import_source, options
          ).and_return([{ number: 5 }].each)

          expect(Issue).to receive(:track_namespace_iid!).with(project.project_namespace, 5)

          expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker)
            .to receive(:perform_async)
            .with(project.id)

          worker.import(client, project)
        end
      end

      context 'without issues' do
        it 'schedules the importing of the base data' do
          client = double(:client)
          options = { state: 'all', sort: 'number', direction: 'desc', per_page: '1' }

          expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance|
            expect(instance).to receive(:execute).and_return(true)
          end

          expect(InternalId).to receive(:exists?).and_return(false)
          expect(client).to receive(:each_object).with(:issues, project.import_source, options).and_return([nil].each)
          expect(Issue).not_to receive(:track_namespace_iid!)

          expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker)
            .to receive(:perform_async)
            .with(project.id)

          worker.import(client, project)
        end
      end

      context 'when retrying' do
        it 'does not allocate internal ids' do
          client = double(:client)

          expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance|
            expect(instance).to receive(:execute).and_return(true)
          end

          expect(InternalId).to receive(:exists?).and_return(true)
          expect(client).not_to receive(:each_object)
          expect(Issue).not_to receive(:track_namespace_iid!)

          expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker)
            .to receive(:perform_async)
            .with(project.id)

          worker.import(client, project)
        end
      end
    end
  end
end