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

import_file_spec.rb « import_export « groups « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b69b8bf2c19a4ac86ac7a367e18594f14059fee6 (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
106
107
108
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Import/Export - Group Import', :js do
  let_it_be(:user) { create(:user) }
  let_it_be(:import_path) { "#{Dir.tmpdir}/group_import_spec" }

  before do
    allow_next_instance_of(Gitlab::ImportExport) do |import_export|
      allow(import_export).to receive(:storage_path).and_return(import_path)
    end

    stub_uploads_object_storage(FileUploader)

    gitlab_sign_in(user)
  end

  after do
    FileUtils.rm_rf(import_path, secure: true)
  end

  context 'when the user uploads a valid export file' do
    let(:file) { File.join(Rails.root, 'spec', %w[fixtures group_export.tar.gz]) }

    context 'when using the pre-filled path', :sidekiq_inline do
      it 'successfully imports the group' do
        group_name = 'Test Group Import'

        visit new_group_path
        click_link 'Import group'

        fill_in s_('Groups|Group name'), with: group_name

        expect(page).to have_content 'Import group from file'
        attach_file(file) do
          find('.js-filepicker-button').click
        end

        expect { click_on 'Import' }.to change { Group.count }.by 1

        group = Group.find_by(name: group_name)

        aggregate_failures do
          expect(group).not_to be_nil
          expect(group.description).to eq 'A voluptate non sequi temporibus quam at.'
          expect(group.path).to eq 'test-group-import'
          expect(group.import_state.status).to eq GroupImportState.state_machine.states[:finished].value
        end
      end
    end

    context 'when modifying the pre-filled path' do
      it 'successfully imports the group' do
        visit new_group_path
        click_link 'Import group'

        fill_in s_('Groups|Group name'), with: 'Test Group Import'

        fill_in s_('Groups|Group URL'), with: 'custom-path'
        attach_file(file) do
          find('.js-filepicker-button').click
        end

        expect { click_on 'Import' }.to change { Group.count }.by 1

        group = Group.find_by(name: 'Test Group Import')
        expect(group.path).to eq 'custom-path'
      end
    end

    context 'when the path is already taken' do
      before do
        create(:group, path: 'test-group-import')
      end

      it 'suggests a unique path' do
        visit new_group_path
        click_link 'Import group'

        fill_in s_('Groups|Group URL'), with: 'test-group-import'
        expect(page).to have_content s_(
          'Groups|Group path is unavailable. Path has been replaced with a suggested available path.'
        )
      end
    end
  end

  context 'when the user uploads an invalid export file' do
    let(:file) { File.join(Rails.root, 'spec', %w[fixtures big-image.png]) }

    it 'displays an error', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/343995' do
      visit new_group_path
      click_link 'Import group'

      fill_in s_('Groups|Group name'), with: 'Test Group Import'
      attach_file(file) do
        find('.js-filepicker-button').click
      end

      expect { click_on 'Import' }.not_to change { Group.count }

      page.within('.flash-container') do
        expect(page).to have_content('Unable to process group import file')
      end
    end
  end
end