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

group_config_spec.rb « file_transfer « bulk_imports « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e1e7cf6d6ed26fd9fdc142f6d894772f2d24abf (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BulkImports::FileTransfer::GroupConfig, feature_category: :importers do
  let_it_be(:exportable) { create(:group) }
  let_it_be(:hex) { '123' }

  before do
    allow(SecureRandom).to receive(:hex).and_return(hex)
  end

  subject { described_class.new(exportable) }

  describe '#portable_tree' do
    it 'returns portable tree' do
      expect_next_instance_of(::Gitlab::ImportExport::AttributesFinder) do |finder|
        expect(finder).to receive(:find_root).with(:group).and_call_original
      end

      expect(subject.portable_tree).not_to be_empty
    end
  end

  describe '#export_path' do
    it 'returns tmpdir location' do
      expect(subject.export_path).to include(File.join(Dir.tmpdir, 'bulk_imports'))
    end
  end

  describe '#portable_relations' do
    it 'returns a list of top level exportable relations' do
      expect(subject.portable_relations).to include('milestones', 'badges', 'boards', 'labels')
    end

    it 'does not include skipped relations' do
      expect(subject.portable_relations).not_to include('members')
    end
  end

  describe '#top_relation_tree' do
    it 'returns relation tree of a top level relation' do
      expect(subject.top_relation_tree('boards')).to include(
        'lists' => a_hash_including({
          'board' => anything,
          'label' => anything
        })
      )
    end
  end

  describe '#relation_excluded_keys' do
    it 'returns excluded keys for relation' do
      expect(subject.relation_excluded_keys('group')).to include('owner_id')
    end
  end

  describe '#batchable_relation?' do
    context 'when relation is batchable' do
      it 'returns true' do
        expect(subject.batchable_relation?('labels')).to eq(true)
      end
    end

    context 'when relation is not batchable' do
      it 'returns false' do
        expect(subject.batchable_relation?('namespace_settings')).to eq(false)
      end
    end

    context 'when relation is not listed as portable' do
      it 'returns false' do
        expect(subject.batchable_relation?('foo')).to eq(false)
      end
    end
  end

  describe '#batchable_relations' do
    it 'returns a list of collection associations for a group' do
      expect(subject.batchable_relations).to include('labels', 'boards', 'milestones')
      expect(subject.batchable_relations).not_to include('namespace_settings')
    end
  end

  describe '#export_service_for' do
    context 'when relation is a tree' do
      it 'returns TreeExportService' do
        expect(subject.export_service_for('labels')).to eq(BulkImports::TreeExportService)
      end
    end

    context 'when relation is a file' do
      it 'returns FileExportService' do
        expect(subject.export_service_for('uploads')).to eq(BulkImports::FileExportService)
      end
    end

    context 'when relation is unknown' do
      it 'raises' do
        expect { subject.export_service_for('foo') }.to raise_error(BulkImports::Error, 'Unsupported export relation')
      end
    end
  end
end