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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-07-31 15:23:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-31 15:23:51 +0300
commit920cbcb38960331cd5e9315e63b2d808fd1a1e48 (patch)
tree7a20d5c4d92257557c0042e3b1b516fb44b34989 /spec/lib
parent34a401c88dd94954363884f1325b92659159bdd7 (diff)
Add latest changes from gitlab-org/gitlab@16-2-stable-ee
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/bitbucket_server/representation/pull_request_spec.rb8
-rw-r--r--spec/lib/gitlab/bitbucket_server_import/importer_spec.rb3
-rw-r--r--spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb17
-rw-r--r--spec/lib/gitlab/import/merge_request_creator_spec.rb8
-rw-r--r--spec/lib/gitlab/import/merge_request_helpers_spec.rb22
5 files changed, 56 insertions, 2 deletions
diff --git a/spec/lib/bitbucket_server/representation/pull_request_spec.rb b/spec/lib/bitbucket_server/representation/pull_request_spec.rb
index c5d0ee8908d..4d8bb3a4407 100644
--- a/spec/lib/bitbucket_server/representation/pull_request_spec.rb
+++ b/spec/lib/bitbucket_server/representation/pull_request_spec.rb
@@ -46,6 +46,10 @@ RSpec.describe BitbucketServer::Representation::PullRequest, feature_category: :
it { expect(subject.description).to eq('Test') }
end
+ describe '#reviewers' do
+ it { expect(subject.reviewers.count).to eq(2) }
+ end
+
describe '#iid' do
it { expect(subject.iid).to eq(7) }
end
@@ -114,6 +118,10 @@ RSpec.describe BitbucketServer::Representation::PullRequest, feature_category: :
author_username: "username",
author: "root",
description: "Test",
+ reviewers: contain_exactly(
+ hash_including('user' => hash_including('emailAddress' => 'jane@doe.com', 'slug' => 'jane_doe')),
+ hash_including('user' => hash_including('emailAddress' => 'john@smith.com', 'slug' => 'john_smith'))
+ ),
source_branch_name: "refs/heads/root/CODE_OF_CONDUCTmd-1530600625006",
source_branch_sha: "074e2b4dddc5b99df1bf9d4a3f66cfc15481fdc8",
target_branch_name: "refs/heads/master",
diff --git a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
index 3cff2411054..4ff61bf329c 100644
--- a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
+++ b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
@@ -70,6 +70,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer, feature_category: :impor
target_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.target_branch,
title: 'This is a title',
description: 'This is a test pull request',
+ reviewers: [],
state: 'merged',
author: 'Test Author',
author_email: pull_request_author.email,
@@ -530,6 +531,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer, feature_category: :impor
target_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.target_branch,
title: 'This is a title',
description: 'This is a test pull request',
+ reviewers: sample.reviewers,
state: 'merged',
author: 'Test Author',
author_email: pull_request_author.email,
@@ -570,6 +572,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer, feature_category: :impor
target_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.target_branch,
title: 'This is a title',
description: 'This is a test pull request',
+ reviewers: [],
state: 'merged',
author: 'Test Author',
author_email: project.owner.email,
diff --git a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb
index 012cdcdd260..3c84d888c92 100644
--- a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb
+++ b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb
@@ -6,6 +6,8 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestImporter, fe
include AfterNextHelpers
let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:reviewer_1) { create(:user, username: 'john_smith', email: 'john@smith.com') }
+ let_it_be(:reviewer_2) { create(:user, username: 'jane_doe', email: 'jane@doe.com') }
let(:pull_request_data) { Gitlab::Json.parse(fixture_file('importers/bitbucket_server/pull_request.json')) }
let(:pull_request) { BitbucketServer::Representation::PullRequest.new(pull_request_data) }
@@ -25,12 +27,27 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestImporter, fe
title: pull_request.title,
source_branch: 'root/CODE_OF_CONDUCTmd-1530600625006',
target_branch: 'master',
+ reviewer_ids: match_array([reviewer_1.id, reviewer_2.id]),
state: pull_request.state,
author_id: project.creator_id,
description: "*Created by: #{pull_request.author}*\n\n#{pull_request.description}"
)
end
+ context 'when the `bitbucket_server_user_mapping_by_username` flag is disabled' do
+ before do
+ stub_feature_flags(bitbucket_server_user_mapping_by_username: false)
+ end
+
+ it 'imports reviewers correctly' do
+ importer.execute
+
+ merge_request = project.merge_requests.find_by_iid(pull_request.iid)
+
+ expect(merge_request.reviewer_ids).to match_array([reviewer_1.id, reviewer_2.id])
+ end
+ end
+
it 'logs its progress' do
expect(Gitlab::BitbucketServerImport::Logger)
.to receive(:info).with(include(message: 'starting', iid: pull_request.iid)).and_call_original
diff --git a/spec/lib/gitlab/import/merge_request_creator_spec.rb b/spec/lib/gitlab/import/merge_request_creator_spec.rb
index 8f502216294..95d7ba6d833 100644
--- a/spec/lib/gitlab/import/merge_request_creator_spec.rb
+++ b/spec/lib/gitlab/import/merge_request_creator_spec.rb
@@ -2,14 +2,17 @@
require 'spec_helper'
-RSpec.describe Gitlab::Import::MergeRequestCreator do
+RSpec.describe Gitlab::Import::MergeRequestCreator, feature_category: :importers do
let(:project) { create(:project, :repository) }
+ let_it_be(:reviewer_user) { create(:user) }
subject { described_class.new(project) }
describe '#execute' do
let(:attributes) do
- HashWithIndifferentAccess.new(merge_request.attributes.except('merge_params', 'suggested_reviewers'))
+ HashWithIndifferentAccess.new(
+ merge_request.attributes.except('merge_params', 'suggested_reviewers').merge(reviewer_ids: [reviewer_user.id])
+ )
end
context 'merge request already exists' do
@@ -26,6 +29,7 @@ RSpec.describe Gitlab::Import::MergeRequestCreator do
merge_request.reload
+ expect(merge_request.reviewer_ids).to contain_exactly(reviewer_user.id)
expect(merge_request.merge_request_diffs.count).to eq(1)
expect(merge_request.merge_request_diffs.first.commits.count).to eq(commits_count)
expect(merge_request.latest_merge_request_diff_id).to eq(merge_request.merge_request_diffs.first.id)
diff --git a/spec/lib/gitlab/import/merge_request_helpers_spec.rb b/spec/lib/gitlab/import/merge_request_helpers_spec.rb
index 9626b7b893f..35a88dacfd7 100644
--- a/spec/lib/gitlab/import/merge_request_helpers_spec.rb
+++ b/spec/lib/gitlab/import/merge_request_helpers_spec.rb
@@ -66,4 +66,26 @@ RSpec.describe Gitlab::Import::MergeRequestHelpers, type: :helper do
end
end
end
+
+ describe '.insert_merge_request_reviewers' do
+ let_it_be(:merge_request) { create(:merge_request) }
+
+ subject { helper.insert_merge_request_reviewers(merge_request, reviewers) }
+
+ context 'when reviewers are not present' do
+ let(:reviewers) { nil }
+
+ it 'does not insert reviewers' do
+ expect { subject }.not_to change { MergeRequestReviewer.count }
+ end
+ end
+
+ context 'when reviewers are present' do
+ let(:reviewers) { create_list(:user, 3).pluck(:id) }
+
+ it 'inserts reviewers' do
+ expect { subject }.to change { MergeRequestReviewer.count }.by(3)
+ end
+ end
+ end
end