2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe MergeRequestWidgetEntity do
|
2018-12-13 13:39:08 +05:30
|
|
|
include ProjectForksHelper
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:project) { create :project, :repository }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:resource) { create(:merge_request, source_project: project, target_project: project) }
|
2020-07-28 23:09:34 +05:30
|
|
|
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:user) { create(:user) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
let(:request) { double('request', current_user: user, project: project) }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
described_class.new(resource, request: request).as_json
|
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
describe 'source_project_full_path' do
|
|
|
|
it 'includes the full path of the source project' do
|
|
|
|
expect(subject[:source_project_full_path]).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the source project is missing' do
|
|
|
|
it 'returns `nil` for the source project' do
|
|
|
|
resource.allow_broken = true
|
|
|
|
resource.update!(source_project: nil)
|
|
|
|
|
|
|
|
expect(subject[:source_project_full_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe 'can_create_pipeline_in_target_project' do
|
|
|
|
context 'when user has permission' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the correct permission info' do
|
|
|
|
expect(subject[:can_create_pipeline_in_target_project]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have permission' do
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the correct permission info' do
|
|
|
|
expect(subject[:can_create_pipeline_in_target_project]).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
describe 'issues links' do
|
|
|
|
it 'includes issues links when requested' do
|
|
|
|
data = described_class.new(resource, request: request, issues_links: true).as_json
|
|
|
|
|
|
|
|
expect(data).to include(:issues_links)
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(data[:issues_links]).to include(:assign_to_closing, :closing, :mentioned_but_not_closing, :closing_count, :mentioned_count)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'omits issue links by default' do
|
|
|
|
expect(subject).not_to include(:issues_links)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'has email_patches_path' do
|
|
|
|
expect(subject[:email_patches_path])
|
2020-03-13 15:44:24 +05:30
|
|
|
.to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.patch")
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has plain_diff_path' do
|
|
|
|
expect(subject[:plain_diff_path])
|
2020-03-13 15:44:24 +05:30
|
|
|
.to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.diff")
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe 'codequality report artifacts', :request_store do
|
2021-03-11 19:13:27 +05:30
|
|
|
let(:merge_base_pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
allow(resource).to receive_messages(
|
2021-01-03 14:25:43 +05:30
|
|
|
merge_base_pipeline: merge_base_pipeline,
|
2020-07-28 23:09:34 +05:30
|
|
|
base_pipeline: pipeline,
|
|
|
|
head_pipeline: pipeline
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'with report artifacts' do
|
2021-03-11 19:13:27 +05:30
|
|
|
let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) }
|
2021-01-03 14:25:43 +05:30
|
|
|
let(:generic_job_id) { pipeline.builds.first.id }
|
|
|
|
let(:merge_base_job_id) { merge_base_pipeline.builds.first.id }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it 'has head_path and base_path entries' do
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality")
|
|
|
|
expect(subject[:codeclimate][:base_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality")
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'on pipelines for merged results' do
|
2021-03-11 19:13:27 +05:30
|
|
|
let(:pipeline) { create(:ci_pipeline, :merged_result_pipeline, :with_codequality_reports, project: project) }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'returns URLs from the head_pipeline and merge_base_pipeline' do
|
|
|
|
expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality")
|
|
|
|
expect(subject[:codeclimate][:base_path]).to include("/jobs/#{merge_base_job_id}/artifacts/download?file_type=codequality")
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'without artifacts' do
|
|
|
|
it 'does not have data entry' do
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(subject).not_to include(:codeclimate)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe 'merge_request_add_ci_config_path' do
|
2020-04-22 19:07:51 +05:30
|
|
|
let!(:project_auto_devops) { create(:project_auto_devops, :disabled, project: project) }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
before do
|
|
|
|
project.add_role(user, role)
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context 'when there is a standard ci config file in the source project' do
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:role) { :developer }
|
|
|
|
|
|
|
|
before do
|
2020-04-22 19:07:51 +05:30
|
|
|
project.repository.create_file(user, Gitlab::FileDetector::PATTERNS[:gitlab_ci], 'CONTENT', message: 'Add .gitlab-ci.yml', branch_name: 'master')
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'no ci config path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context 'when there is no standard ci config file in the source project' do
|
2020-03-13 15:44:24 +05:30
|
|
|
context 'when user has permissions' do
|
|
|
|
let(:role) { :developer }
|
|
|
|
|
|
|
|
it 'has add ci config path' do
|
2020-11-24 15:15:51 +05:30
|
|
|
expected_path = "/#{resource.project.full_path}/-/new/#{resource.source_branch}"
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to include(expected_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected params' do
|
|
|
|
expected_params = {
|
|
|
|
commit_message: 'Add .gitlab-ci.yml',
|
|
|
|
file_name: '.gitlab-ci.yml',
|
|
|
|
suggest_gitlab_ci_yml: 'true',
|
|
|
|
mr_path: "/#{resource.project.full_path}/-/merge_requests/#{resource.iid}"
|
|
|
|
}.with_indifferent_access
|
|
|
|
|
|
|
|
uri = Addressable::URI.parse(subject[:merge_request_add_ci_config_path])
|
|
|
|
|
|
|
|
expect(uri.query_values).to match(expected_params)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context 'when auto devops is enabled' do
|
|
|
|
before do
|
|
|
|
project_auto_devops.enabled = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a blank ci config path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
context 'when source project is missing' do
|
|
|
|
before do
|
|
|
|
resource.source_project = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a blank ci config path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are no commits' do
|
|
|
|
before do
|
|
|
|
allow(resource).to receive(:commits_count).and_return(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a blank ci config path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ci_config_path is customized' do
|
|
|
|
it 'has no path if ci_config_path is not set to our default setting' do
|
|
|
|
project.ci_config_path = 'not_default'
|
|
|
|
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a path if ci_config_path unset' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a path if ci_config_path is an empty string' do
|
|
|
|
project.ci_config_path = ''
|
|
|
|
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a path if ci_config_path is set to our default file' do
|
|
|
|
project.ci_config_path = Gitlab::FileDetector::PATTERNS[:gitlab_ci]
|
|
|
|
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
context 'when build feature is disabled' do
|
|
|
|
before do
|
2020-11-24 15:15:51 +05:30
|
|
|
project.project_feature.update!(builds_access_level: ProjectFeature::DISABLED)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when creating the pipeline is not allowed' do
|
|
|
|
before do
|
|
|
|
user.state = 'blocked'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
context 'when merge request is merged' do
|
|
|
|
before do
|
|
|
|
resource.mark_as_merged!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a blank ci config path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when merge request is closed' do
|
|
|
|
before do
|
|
|
|
resource.close!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a blank ci config path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when source branch does not exist' do
|
|
|
|
before do
|
|
|
|
resource.source_project.repository.rm_branch(user, resource.source_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a blank ci config path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have permissions' do
|
|
|
|
let(:role) { :reporter }
|
|
|
|
|
|
|
|
it 'has add ci config path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe 'user callouts' do
|
2021-02-22 17:27:13 +05:30
|
|
|
subject { described_class.new(resource, request: request).as_json }
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'provides a valid path value for user callout path' do
|
|
|
|
expect(subject[:user_callouts_path]).to eq '/-/user_callouts'
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'provides a valid value for suggest pipeline feature id' do
|
|
|
|
expect(subject[:suggest_pipeline_feature_id]).to eq described_class::SUGGEST_PIPELINE
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'has human access' do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
|
|
|
|
expect(subject[:human_access])
|
|
|
|
.to eq('Maintainer')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it 'has new pipeline path for project' do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
|
|
|
|
expect(subject[:new_project_pipeline_path])
|
2020-06-23 00:09:42 +05:30
|
|
|
.to eq("/#{resource.project.full_path}/-/pipelines/new")
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'when source project is deleted' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
2018-12-13 13:39:08 +05:30
|
|
|
let(:forked_project) { fork_project(project) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'returns a blank rebase_path' do
|
|
|
|
allow(merge_request).to receive(:should_be_rebased?).and_return(true)
|
2020-11-24 15:15:51 +05:30
|
|
|
forked_project.destroy!
|
2018-03-17 18:26:18 +05:30
|
|
|
merge_request.reload
|
|
|
|
|
|
|
|
entity = described_class.new(merge_request, request: request).as_json
|
|
|
|
|
|
|
|
expect(entity[:rebase_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
it 'has security_reports_docs_path' do
|
|
|
|
expect(subject[:security_reports_docs_path]).not_to be_nil
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
describe 'has source_project_default_url' do
|
|
|
|
it 'returns the default url to the source project' do
|
|
|
|
expect(subject[:source_project_default_url]).to eq project.http_url_to_repo
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when source project is nil' do
|
|
|
|
it 'returns nil' do
|
|
|
|
allow(resource).to receive(:source_project).and_return(nil)
|
|
|
|
|
|
|
|
expect(subject[:source_project_default_url]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
describe 'when gitpod is disabled' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::CurrentSettings).to receive(:gitpod_enabled).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes gitpod attributes' do
|
|
|
|
expect(subject).to include(
|
|
|
|
show_gitpod_button: false,
|
|
|
|
gitpod_url: nil,
|
|
|
|
gitpod_enabled: false
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when gitpod is enabled' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::CurrentSettings).to receive(:gitpod_enabled).and_return(true)
|
|
|
|
allow(Gitlab::CurrentSettings).to receive(:gitpod_url).and_return("https://gitpod.example.com")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes gitpod attributes' do
|
|
|
|
mr_url = Gitlab::Routing.url_helpers.project_merge_request_url(resource.project, resource)
|
|
|
|
|
|
|
|
expect(subject).to include(
|
|
|
|
show_gitpod_button: true,
|
|
|
|
gitpod_url: "https://gitpod.example.com##{mr_url}",
|
|
|
|
gitpod_enabled: false
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when gitpod is enabled for user' do
|
|
|
|
before do
|
|
|
|
allow(user).to receive(:gitpod_enabled).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes gitpod_enabled as true' do
|
|
|
|
expect(subject[:gitpod_enabled]).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
describe 'is_dismissed_suggest_pipeline' do
|
|
|
|
context 'when user is logged in' do
|
|
|
|
context 'when the suggest pipeline feature is enabled' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::CurrentSettings).to receive(:suggest_pipeline_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is false' do
|
|
|
|
expect(subject[:is_dismissed_suggest_pipeline]).to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when suggest pipeline has been dismissed' do
|
|
|
|
before do
|
|
|
|
create(:user_callout, user: user, feature_name: described_class::SUGGEST_PIPELINE)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is true' do
|
|
|
|
expect(subject[:is_dismissed_suggest_pipeline]).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the suggest pipeline feature is disabled' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::CurrentSettings).to receive(:suggest_pipeline_enabled?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is true' do
|
|
|
|
expect(subject[:is_dismissed_suggest_pipeline]).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not logged in' do
|
|
|
|
let(:request) { double('request', current_user: nil, project: project) }
|
|
|
|
|
|
|
|
it 'is true' do
|
|
|
|
expect(subject[:is_dismissed_suggest_pipeline]).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|