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

import_issue_events_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: 932152c0764673c30fca8676aaeb0b8536c85610 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker do
  subject(:worker) { described_class.new }

  let(:project) { create(:project) }
  let!(:group) { create(:group, projects: [project]) }
  let(:feature_flag_state) { [group] }
  let(:single_endpoint_feature_flag_state) { [group] }

  describe '#import' do
    let(:importer) { instance_double('Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter') }
    let(:client) { instance_double('Gitlab::GithubImport::Client') }

    before do
      stub_feature_flags(github_importer_single_endpoint_issue_events_import: single_endpoint_feature_flag_state)
      stub_feature_flags(github_importer_issue_events_import: feature_flag_state)
    end

    context 'when single endpoint feature flag enabled' do
      it 'imports all the issue events' do
        waiter = Gitlab::JobWaiter.new(2, '123')

        expect(Gitlab::GithubImport::Importer::IssueEventsImporter).not_to receive(:new)
        expect(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter)
          .to receive(:new)
          .with(project, client)
          .and_return(importer)

        expect(importer).to receive(:execute).and_return(waiter)

        expect(Gitlab::GithubImport::AdvanceStageWorker)
          .to receive(:perform_async)
          .with(project.id, { '123' => 2 }, :notes)

        worker.import(client, project)
      end
    end

    context 'when import issue events feature flag enabled' do
      let(:single_endpoint_feature_flag_state) { false }

      it 'imports the issue events partly' do
        waiter = Gitlab::JobWaiter.new(2, '123')

        expect(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter).not_to receive(:new)
        expect(Gitlab::GithubImport::Importer::IssueEventsImporter)
          .to receive(:new)
          .with(project, client)
          .and_return(importer)

        expect(importer).to receive(:execute).and_return(waiter)

        expect(Gitlab::GithubImport::AdvanceStageWorker)
          .to receive(:perform_async)
          .with(project.id, { '123' => 2 }, :notes)

        worker.import(client, project)
      end
    end

    context 'when feature flags are disabled' do
      let(:feature_flag_state) { false }
      let(:single_endpoint_feature_flag_state) { false }

      it 'skips issue events import and calls next stage' do
        expect(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter).not_to receive(:new)
        expect(Gitlab::GithubImport::Importer::IssueEventsImporter).not_to receive(:new)
        expect(Gitlab::GithubImport::AdvanceStageWorker).to receive(:perform_async).with(project.id, {}, :notes)

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