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

notes_importer_spec.rb « attachments « importer « github_import « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: da0ee1ed0ddeddb3c6881955858037a8155322f2 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GithubImport::Importer::Attachments::NotesImporter, feature_category: :importers do
  subject(:importer) { described_class.new(project, client) }

  let_it_be(:project) { create(:project) }

  let(:client) { instance_double(Gitlab::GithubImport::Client) }

  describe '#sequential_import', :clean_gitlab_redis_cache do
    let_it_be(:note) { create(:note, project: project) }

    let_it_be(:note_with_attachment) do
      create(:note,
        project: project,
        note: "![image](https://user-images.githubusercontent.com/1/uuid-1.png)"
      )
    end

    let_it_be(:system_note_with_attachment) do
      create(:note,
        :system,
        project: project,
        note: "![image](https://user-images.githubusercontent.com/1/uuid-1.png)"
      )
    end

    it 'selects only user notes, and selects only properties it needs' do
      stubbed_collection = class_double(Note, each_batch: [])

      expect(project.notes).to receive(:id_not_in).with([]).and_return(stubbed_collection)
      expect(stubbed_collection).to receive(:user).and_return(stubbed_collection)
      expect(stubbed_collection)
        .to receive(:select).with(:id, :note, :system, :noteable_type)
        .and_return(stubbed_collection)

      importer.sequential_import
    end

    it 'executes importer only for the note with an attachment' do
      expect_next_instance_of(
        Gitlab::GithubImport::Importer::NoteAttachmentsImporter,
        have_attributes(record_db_id: note_with_attachment.id),
        project,
        client
      ) do |importer|
        expect(importer).to receive(:execute)
      end

      importer.sequential_import
    end

    context 'when flag is disabled' do
      before do
        stub_feature_flags(github_importer_attachments: false)
      end

      it 'executes importer for both user notes' do
        expect_next_instances_of(Gitlab::GithubImport::Importer::NoteAttachmentsImporter, 2) do |importer|
          expect(importer).to receive(:execute)
        end

        importer.sequential_import
      end
    end

    context 'when note has already been processed' do
      before do
        importer.mark_as_imported(note_with_attachment)
      end

      it 'does not select notes that were processed' do
        expect(project.notes).to receive(:id_not_in).with([note_with_attachment.id.to_s]).and_call_original

        importer.sequential_import
      end

      it 'does not execute importer for the note with an attachment' do
        expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).not_to receive(:new)

        importer.sequential_import
      end
    end
  end

  describe '#sidekiq_worker_class' do
    it { expect(importer.sidekiq_worker_class).to eq(Gitlab::GithubImport::Attachments::ImportNoteWorker) }
  end

  describe '#collection_method' do
    it { expect(importer.collection_method).to eq(:note_attachments) }
  end

  describe '#object_type' do
    it { expect(importer.object_type).to eq(:note_attachment) }
  end

  describe '#id_for_already_imported_cache' do
    let(:note) { build_stubbed(:note) }

    it { expect(importer.id_for_already_imported_cache(note)).to eq(note.id) }
  end
end