summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/api/1_manage/migration/gitlab_migration_issue_spec.rb
blob: 052e3d0e32d723f7a6eaca2415cbb862d450c293 (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
# frozen_string_literal: true

module QA
  RSpec.describe 'Manage' do
    describe 'Gitlab migration', product_group: :import do
      include_context 'with gitlab project migration'

      let!(:source_issue) do
        Resource::Issue.fabricate_via_api! do |issue|
          issue.api_client = source_admin_api_client
          issue.project = source_project
          issue.labels = %w[label_one label_two]
        end
      end

      let(:source_issue_comments) do
        source_issue.comments.map do |note|
          { **note.except(:id, :noteable_id), author: note[:author].except(:web_url) }
        end
      end

      let(:imported_issues) { imported_projects.first.issues }

      let(:imported_issue) do
        issue = imported_issues.first
        Resource::Issue.init do |resource|
          resource.api_client = api_client
          resource.project = imported_projects.first
          resource.iid = issue[:iid]
        end
      end

      let(:imported_issue_comments) do
        imported_issue.comments.map do |note|
          { **note.except(:id, :noteable_id), author: note[:author].except(:web_url) }
        end
      end

      context 'with project issues' do
        let!(:source_comment) { source_issue.add_comment(body: 'This is a test comment!') }

        let(:imported_comments) { imported_issue.comments }

        it(
          'successfully imports issue',
          testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347608'
        ) do
          expect_project_import_finished_successfully
          expect(imported_issues.count).to eq(1)
          expect(imported_issue).to eq(source_issue.reload!)
          expect(imported_issue_comments).to match_array(source_issue_comments)
        end
      end

      context 'with associated merge request' do
        let!(:source_mr) do
          Resource::MergeRequest.fabricate_via_api! do |mr|
            mr.project = source_project
            mr.api_client = source_admin_api_client
            mr.description = "Closes #{source_issue.web_url}"
          end
        end

        let(:imported_related_mrs) do
          imported_issue.related_merge_requests.pluck(:iid)
        end

        it(
          'preserves related merge request',
          testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/386305',
          quarantine: {
            type: :bug,
            issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/386308'
          }
        ) do
          expect_project_import_finished_successfully
          expect(imported_related_mrs).to eq([source_mr.iid])
        end
      end

      # we can't fabricate things in source instance via UI
      context "with designs", quarantine: {
        type: :broken,
        issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/366592'
      } do
        let!(:source_design) do
          Flow::Login.sign_in(as: user)

          Resource::Design.fabricate_via_browser_ui! do |design|
            design.api_client = api_client
            design.issue = source_issue
          end.reload!
        end

        let(:imported_design) do
          Resource::Design.init do |design|
            design.api_client = api_client
            design.issue = imported_issue.reload!
          end.reload!
        end

        it(
          'successfully imports design',
          testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/366449'
        ) do
          expect_project_import_finished_successfully
          expect(imported_issues.count).to eq(1)

          expect(imported_design.full_path).to eq(source_design.full_path)
        end
      end
    end
  end
end