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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-10-12 06:08:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-10-12 06:08:54 +0300
commit129d7ea3db19359600b5e03f0070b8be831b3fee (patch)
tree41740325254fef612157bc059474ab3ed2a5a548 /spec
parenta4dd029f243d6049cd8fa31408077d52a1c27e57 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/boards/sidebar_labels_in_namespaces_spec.rb2
-rw-r--r--spec/features/boards/sidebar_spec.rb2
-rw-r--r--spec/features/boards/user_visits_board_spec.rb2
-rw-r--r--spec/lib/bitbucket_server/representation/pull_request_spec.rb12
-rw-r--r--spec/lib/gitlab/bitbucket_server_import/importers/pull_requests_importer_spec.rb94
-rw-r--r--spec/services/notes/quick_actions_service_spec.rb40
-rw-r--r--spec/services/quick_actions/interpret_service_spec.rb49
7 files changed, 190 insertions, 11 deletions
diff --git a/spec/features/boards/sidebar_labels_in_namespaces_spec.rb b/spec/features/boards/sidebar_labels_in_namespaces_spec.rb
index ffed4a0854f..68c2b2587e7 100644
--- a/spec/features/boards/sidebar_labels_in_namespaces_spec.rb
+++ b/spec/features/boards/sidebar_labels_in_namespaces_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe 'Issue boards sidebar labels select', :js, feature_category: :tea
include_context 'labels from nested groups and projects'
- let(:card) { find('.board:nth-child(1)').first('[data-testid="board_card"]') }
+ let(:card) { find('.board:nth-child(1)').first('[data-testid="board-card"]') }
context 'group boards' do
context 'in the top-level group board' do
diff --git a/spec/features/boards/sidebar_spec.rb b/spec/features/boards/sidebar_spec.rb
index 358da1e1279..71cc9a28575 100644
--- a/spec/features/boards/sidebar_spec.rb
+++ b/spec/features/boards/sidebar_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe 'Project issue boards sidebar', :js, feature_category: :team_plan
it_behaves_like 'issue boards sidebar'
def first_card
- find('.board:nth-child(1)').first("[data-testid='board_card']")
+ find('.board:nth-child(1)').first("[data-testid='board-card']")
end
def click_first_issue_card
diff --git a/spec/features/boards/user_visits_board_spec.rb b/spec/features/boards/user_visits_board_spec.rb
index 5867ec17070..4741f58d883 100644
--- a/spec/features/boards/user_visits_board_spec.rb
+++ b/spec/features/boards/user_visits_board_spec.rb
@@ -53,7 +53,7 @@ RSpec.describe 'User visits issue boards', :js, feature_category: :team_planning
it 'displays all issues satisfiying filter params and correctly sets url params' do
expect(page).to have_current_path(board_path)
- page.assert_selector('[data-testid="board_card"]', count: expected_issues.length)
+ page.assert_selector('[data-testid="board-card"]', count: expected_issues.length)
expected_issues.each { |issue_title| expect(page).to have_link issue_title }
end
end
diff --git a/spec/lib/bitbucket_server/representation/pull_request_spec.rb b/spec/lib/bitbucket_server/representation/pull_request_spec.rb
index 4d8bb3a4407..2d67dd88b24 100644
--- a/spec/lib/bitbucket_server/representation/pull_request_spec.rb
+++ b/spec/lib/bitbucket_server/representation/pull_request_spec.rb
@@ -82,6 +82,18 @@ RSpec.describe BitbucketServer::Representation::PullRequest, feature_category: :
it { expect(subject.merged?).to be_truthy }
end
+ describe '#closed?' do
+ it { expect(subject.closed?).to be_falsey }
+
+ context 'for declined pull requests' do
+ before do
+ sample_data['state'] = 'DECLINED'
+ end
+
+ it { expect(subject.closed?).to be_truthy }
+ end
+ end
+
describe '#created_at' do
it { expect(subject.created_at.to_i).to eq(sample_data['createdDate'] / 1000) }
end
diff --git a/spec/lib/gitlab/bitbucket_server_import/importers/pull_requests_importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importers/pull_requests_importer_spec.rb
index b9a9c8dac29..af8a0202083 100644
--- a/spec/lib/gitlab/bitbucket_server_import/importers/pull_requests_importer_spec.rb
+++ b/spec/lib/gitlab/bitbucket_server_import/importers/pull_requests_importer_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestsImporter, feature_category: :importers do
let_it_be(:project) do
- create(:project, :import_started,
+ create(:project, :with_import_url, :import_started, :empty_repo,
import_data_attributes: {
data: { 'project_key' => 'key', 'repo_slug' => 'slug' },
credentials: { 'base_uri' => 'http://bitbucket.org/', 'user' => 'bitbucket', 'password' => 'password' }
@@ -19,8 +19,30 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestsImporter, f
allow_next_instance_of(BitbucketServer::Client) do |client|
allow(client).to receive(:pull_requests).and_return(
[
- BitbucketServer::Representation::PullRequest.new({ 'id' => 1 }),
- BitbucketServer::Representation::PullRequest.new({ 'id' => 2 })
+ BitbucketServer::Representation::PullRequest.new(
+ {
+ 'id' => 1,
+ 'state' => 'MERGED',
+ 'fromRef' => { 'latestCommit' => 'aaaa1' },
+ 'toRef' => { 'latestCommit' => 'aaaa2' }
+ }
+ ),
+ BitbucketServer::Representation::PullRequest.new(
+ {
+ 'id' => 2,
+ 'state' => 'DECLINED',
+ 'fromRef' => { 'latestCommit' => 'bbbb1' },
+ 'toRef' => { 'latestCommit' => 'bbbb2' }
+ }
+ ),
+ BitbucketServer::Representation::PullRequest.new(
+ {
+ 'id' => 3,
+ 'state' => 'OPEN',
+ 'fromRef' => { 'latestCommit' => 'cccc1' },
+ 'toRef' => { 'latestCommit' => 'cccc2' }
+ }
+ )
],
[]
)
@@ -28,14 +50,14 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestsImporter, f
end
it 'imports each pull request in parallel', :aggregate_failures do
- expect(Gitlab::BitbucketServerImport::ImportPullRequestWorker).to receive(:perform_in).twice
+ expect(Gitlab::BitbucketServerImport::ImportPullRequestWorker).to receive(:perform_in).thrice
waiter = importer.execute
expect(waiter).to be_an_instance_of(Gitlab::JobWaiter)
- expect(waiter.jobs_remaining).to eq(2)
+ expect(waiter.jobs_remaining).to eq(3)
expect(Gitlab::Cache::Import::Caching.values_from_set(importer.already_processed_cache_key))
- .to match_array(%w[1 2])
+ .to match_array(%w[1 2 3])
end
context 'when pull request was already processed' do
@@ -44,12 +66,68 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestsImporter, f
end
it 'does not schedule job for processed pull requests', :aggregate_failures do
- expect(Gitlab::BitbucketServerImport::ImportPullRequestWorker).to receive(:perform_in).once
+ expect(Gitlab::BitbucketServerImport::ImportPullRequestWorker).to receive(:perform_in).twice
waiter = importer.execute
expect(waiter).to be_an_instance_of(Gitlab::JobWaiter)
- expect(waiter.jobs_remaining).to eq(2)
+ expect(waiter.jobs_remaining).to eq(3)
+ end
+ end
+
+ context 'when pull requests are in merged or declined status' do
+ it 'fetches latest commits from the remote repository' do
+ expect(project.repository).to receive(:fetch_remote).with(
+ project.import_url,
+ refmap: %w[aaaa1 aaaa2 bbbb1 bbbb2],
+ prune: false
+ )
+
+ importer.execute
+ end
+
+ context 'when feature flag "fetch_commits_for_bitbucket_server" is disabled' do
+ before do
+ stub_feature_flags(fetch_commits_for_bitbucket_server: false)
+ end
+
+ it 'does not fetch anything' do
+ expect(project.repository).not_to receive(:fetch_remote)
+ importer.execute
+ end
+ end
+
+ context 'when there are no commits to process' do
+ before do
+ Gitlab::Cache::Import::Caching.set_add(importer.already_processed_cache_key, 1)
+ Gitlab::Cache::Import::Caching.set_add(importer.already_processed_cache_key, 2)
+ end
+
+ it 'does not fetch anything' do
+ expect(project.repository).not_to receive(:fetch_remote)
+
+ importer.execute
+ end
+ end
+
+ context 'when fetch process is failed' do
+ let(:exception) { ArgumentError.new('blank or empty URL') }
+
+ before do
+ allow(project.repository).to receive(:fetch_remote).and_raise(exception)
+ end
+
+ it 'rescues and logs the exception' do
+ expect(Gitlab::Import::ImportFailureService)
+ .to receive(:track)
+ .with(
+ project_id: project.id,
+ exception: exception,
+ error_source: described_class.name
+ ).and_call_original
+
+ importer.execute
+ end
end
end
end
diff --git a/spec/services/notes/quick_actions_service_spec.rb b/spec/services/notes/quick_actions_service_spec.rb
index cb9d82535fa..0a16037c976 100644
--- a/spec/services/notes/quick_actions_service_spec.rb
+++ b/spec/services/notes/quick_actions_service_spec.rb
@@ -334,6 +334,46 @@ RSpec.describe Notes::QuickActionsService, feature_category: :team_planning do
end
end
+ describe '/add_child' do
+ let_it_be_with_reload(:noteable) { create(:work_item, :objective, project: project) }
+ let_it_be_with_reload(:child) { create(:work_item, :objective, project: project) }
+ let_it_be_with_reload(:second_child) { create(:work_item, :objective, project: project) }
+ let_it_be(:note_text) { "/add_child #{child.to_reference}, #{second_child.to_reference}" }
+ let_it_be(:note) { create(:note, noteable: noteable, project: project, note: note_text) }
+ let_it_be(:children) { [child, second_child] }
+
+ shared_examples 'adds child work items' do
+ it 'leaves the note empty' do
+ expect(execute(note)).to be_empty
+ end
+
+ it 'adds child work items' do
+ execute(note)
+
+ expect(noteable.valid?).to be_truthy
+ expect(noteable.work_item_children).to eq(children)
+ end
+ end
+
+ context 'when using work item reference' do
+ let_it_be(:note_text) { "/add_child #{child.to_reference(full: true)},#{second_child.to_reference(full: true)}" }
+
+ it_behaves_like 'adds child work items'
+ end
+
+ context 'when using work item iid' do
+ it_behaves_like 'adds child work items'
+ end
+
+ context 'when using work item URL' do
+ let_it_be(:project_path) { "#{Gitlab.config.gitlab.url}/#{project.full_path}" }
+ let_it_be(:url) { "#{project_path}/work_items/#{child.iid},#{project_path}/work_items/#{second_child.iid}" }
+ let_it_be(:note_text) { "/add_child #{url}" }
+
+ it_behaves_like 'adds child work items'
+ end
+ end
+
describe '/set_parent' do
let_it_be_with_reload(:noteable) { create(:work_item, :objective, project: project) }
let_it_be_with_reload(:parent) { create(:work_item, :objective, project: project) }
diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb
index 57967fa0c3a..2c34d6a59be 100644
--- a/spec/services/quick_actions/interpret_service_spec.rb
+++ b/spec/services/quick_actions/interpret_service_spec.rb
@@ -3091,6 +3091,55 @@ RSpec.describe QuickActions::InterpretService, feature_category: :team_planning
it_behaves_like 'command is not available'
end
end
+
+ describe '/add_child command' do
+ let_it_be(:child) { create(:work_item, :issue, project: project) }
+ let_it_be(:work_item) { create(:work_item, :objective, project: project) }
+ let_it_be(:child_ref) { child.to_reference(project) }
+
+ let(:command) { "/add_child #{child_ref}" }
+
+ shared_examples 'command is available' do
+ it 'explanation contains correct message' do
+ _, explanations = service.explain(command, work_item)
+
+ expect(explanations)
+ .to contain_exactly("Add #{child_ref} to this work item as child(ren).")
+ end
+
+ it 'contains command' do
+ expect(service.available_commands(work_item)).to include(a_hash_including(name: :add_child))
+ end
+ end
+
+ shared_examples 'command is not available' do
+ it 'explanation is empty' do
+ _, explanations = service.explain(command, work_item)
+
+ expect(explanations).to eq([])
+ end
+
+ it 'does not contain command' do
+ expect(service.available_commands(work_item)).not_to include(a_hash_including(name: :add_child))
+ end
+ end
+
+ context 'when user can admin link' do
+ it_behaves_like 'command is available'
+
+ context 'when work item type does not support children' do
+ let_it_be(:work_item) { build(:work_item, :key_result, project: project) }
+
+ it_behaves_like 'command is not available'
+ end
+ end
+
+ context 'when user cannot admin link' do
+ subject(:service) { described_class.new(project, create(:user)) }
+
+ it_behaves_like 'command is not available'
+ end
+ end
end
describe '#available_commands' do