summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb
blob: d4c4ec5611a35792b4f1897abbc0056723a698e4 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# frozen_string_literal: true

module QA
  RSpec.describe 'Manage', :requires_admin do
    describe 'Bulk group import' do
      let!(:admin_api_client) { Runtime::API::Client.as_admin }
      let!(:user) do
        Resource::User.fabricate_via_api! do |usr|
          usr.api_client = admin_api_client
          usr.hard_delete_on_api_removal = true
        end
      end

      let!(:api_client) { Runtime::API::Client.new(user: user) }
      let!(:personal_access_token) { api_client.personal_access_token }

      let!(:sandbox) do
        Resource::Sandbox.fabricate_via_api! do |group|
          group.api_client = admin_api_client
        end
      end

      let!(:source_group) do
        Resource::Sandbox.fabricate_via_api! do |group|
          group.api_client = api_client
          group.path = "source-group-for-import-#{SecureRandom.hex(4)}"
        end
      end

      let!(:subgroup) do
        Resource::Group.fabricate_via_api! do |group|
          group.api_client = api_client
          group.sandbox = source_group
          group.path = "subgroup-for-import-#{SecureRandom.hex(4)}"
        end
      end

      let(:imported_group) do
        Resource::Group.new.tap do |group|
          group.api_client = api_client
          group.sandbox = sandbox
          group.path = source_group.path
        end
      end

      let(:imported_subgroup) do
        Resource::Group.new.tap do |group|
          group.api_client = api_client
          group.sandbox = imported_group
          group.path = subgroup.path
        end
      end

      def staging?
        Runtime::Scenario.gitlab_address.include?('staging.gitlab.com')
      end

      before(:all) do
        Runtime::Feature.enable(:bulk_import) unless staging?
        Runtime::Feature.enable(:top_level_group_creation_enabled) if staging?
      end

      before do
        sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER)

        Flow::Login.sign_in(as: user)
        Page::Main::Menu.perform(&:go_to_create_group)
        Page::Group::New.perform do |group|
          group.switch_to_import_tab
          group.connect_gitlab_instance(Runtime::Scenario.gitlab_address, personal_access_token)
        end
      end

      # Non blocking issues:
      # https://gitlab.com/gitlab-org/gitlab/-/issues/331252
      it(
        'imports group with subgroups and labels',
        testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1785',
        quarantine: {
          only: { job: 'relative_url' },
          issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/330344',
          type: :bug
        }
      ) do
        Resource::GroupLabel.fabricate_via_api! do |label|
          label.api_client = api_client
          label.group = source_group
          label.title = "source-group-#{SecureRandom.hex(4)}"
        end
        Resource::GroupLabel.fabricate_via_api! do |label|
          label.api_client = api_client
          label.group = subgroup
          label.title = "subgroup-#{SecureRandom.hex(4)}"
        end

        Page::Group::BulkImport.perform do |import_page|
          import_page.import_group(source_group.path, sandbox.path)

          aggregate_failures do
            expect(import_page).to have_imported_group(source_group.path, wait: 180)

            expect { imported_group.reload! }.to eventually_eq(source_group).within(duration: 10)
            expect { imported_group.labels }.to eventually_include(*source_group.labels).within(duration: 10)

            # Do not validate subgroups until https://gitlab.com/gitlab-org/gitlab/-/issues/332818 is resolved
            # expect { imported_subgroup.reload! }.to eventually_eq(subgroup).within(duration: 30)
            # expect { imported_subgroup.labels }.to eventually_include(*subgroup.labels).within(duration: 30)
          end
        end
      end

      after do
        user.remove_via_api!
      end

      after(:all) do
        Runtime::Feature.disable(:bulk_import) unless staging?
        Runtime::Feature.disable(:top_level_group_creation_enabled) if staging?
      end
    end
  end
end