summaryrefslogtreecommitdiff
path: root/spec/services/bulk_imports/export_service_spec.rb
blob: 2414f7c5ca77512e97e8bd7ae873f010d2fe92f6 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BulkImports::ExportService do
  let_it_be(:group) { create(:group) }
  let_it_be(:user) { create(:user) }

  before do
    group.add_owner(user)
  end

  subject { described_class.new(portable: group, user: user) }

  describe '#execute' do
    it 'schedules RelationExportWorker for each top level relation' do
      expect(subject).to receive(:execute).and_return(ServiceResponse.success).and_call_original
      top_level_relations = BulkImports::FileTransfer.config_for(group).portable_relations

      top_level_relations.each do |relation|
        expect(BulkImports::RelationExportWorker)
          .to receive(:perform_async)
          .with(user.id, group.id, group.class.name, relation)
      end

      subject.execute
    end

    context 'when exception occurs' do
      it 'does not schedule RelationExportWorker' do
        service = described_class.new(portable: nil, user: user)

        expect(service)
          .to receive(:execute)
          .and_return(ServiceResponse.error(message: 'Gitlab::ImportExport::Error', http_status: :unprocessible_entity))
          .and_call_original
        expect(BulkImports::RelationExportWorker).not_to receive(:perform_async)

        service.execute
      end
    end
  end
end