2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe MergeRequestWidgetEntity do
|
2018-08-31 13:16:34 -04:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2020-04-07 11:09:30 -04:00
|
|
|
let(:project) { create :project, :repository }
|
2017-05-09 00:15:34 -04:00
|
|
|
let(:resource) { create(:merge_request, source_project: project, target_project: project) }
|
2020-07-17 02:09:11 -04:00
|
|
|
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
|
2020-04-07 11:09:30 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2017-12-01 08:26:51 -05:00
|
|
|
let(:request) { double('request', current_user: user, project: project) }
|
2017-05-09 00:15:34 -04:00
|
|
|
|
|
|
|
subject do
|
|
|
|
described_class.new(resource, request: request).as_json
|
|
|
|
end
|
|
|
|
|
2018-07-10 05:35:16 -04:00
|
|
|
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-07-22 11:09:28 -04:00
|
|
|
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-06-20 18:18:51 -04:00
|
|
|
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)
|
|
|
|
expect(data[:issues_links]).to include(:assign_to_closing, :closing, :mentioned_but_not_closing)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'omits issue links by default' do
|
|
|
|
expect(subject).not_to include(:issues_links)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
it 'has email_patches_path' do
|
|
|
|
expect(subject[:email_patches_path])
|
2020-01-20 19:08:46 -05:00
|
|
|
.to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.patch")
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has plain_diff_path' do
|
|
|
|
expect(subject[:plain_diff_path])
|
2020-01-20 19:08:46 -05:00
|
|
|
.to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.diff")
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
2020-07-17 02:09:11 -04:00
|
|
|
it 'has blob path data' do
|
|
|
|
allow(resource).to receive_messages(
|
|
|
|
base_pipeline: pipeline,
|
|
|
|
head_pipeline: pipeline
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(subject).to include(:blob_path)
|
|
|
|
expect(subject[:blob_path]).to include(:base_path)
|
|
|
|
expect(subject[:blob_path]).to include(:head_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'codequality report artifacts', :request_store do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
allow(resource).to receive_messages(
|
|
|
|
base_pipeline: pipeline,
|
|
|
|
head_pipeline: pipeline
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with report artifacts" do
|
|
|
|
let(:pipeline) { create(:ci_pipeline, :with_codequality_report, project: project) }
|
|
|
|
|
|
|
|
it "has data entry" do
|
|
|
|
expect(subject).to include(:codeclimate)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "without artifacts" do
|
|
|
|
it "does not have data entry" do
|
|
|
|
expect(subject).not_to include(:codeclimate)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-04 16:08:55 -05:00
|
|
|
describe 'merge_request_add_ci_config_path' do
|
2020-04-07 11:09:30 -04:00
|
|
|
let!(:project_auto_devops) { create(:project_auto_devops, :disabled, project: project) }
|
|
|
|
|
2020-02-04 16:08:55 -05:00
|
|
|
before do
|
|
|
|
project.add_role(user, role)
|
|
|
|
end
|
|
|
|
|
2020-04-07 11:09:30 -04:00
|
|
|
context 'when there is a standard ci config file in the source project' do
|
2020-02-04 16:08:55 -05:00
|
|
|
let(:role) { :developer }
|
|
|
|
|
|
|
|
before do
|
2020-04-07 11:09:30 -04:00
|
|
|
project.repository.create_file(user, Gitlab::FileDetector::PATTERNS[:gitlab_ci], 'CONTENT', message: 'Add .gitlab-ci.yml', branch_name: 'master')
|
2020-02-04 16:08:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'no ci config path' do
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-07 11:09:30 -04:00
|
|
|
context 'when there is no standard ci config file in the source project' do
|
2020-02-04 16:08:55 -05:00
|
|
|
context 'when user has permissions' do
|
|
|
|
let(:role) { :developer }
|
|
|
|
|
|
|
|
it 'has add ci config path' do
|
2020-02-24 16:09:08 -05:00
|
|
|
expected_path = "/#{resource.project.full_path}/-/new/#{resource.source_branch}?commit_message=Add+.gitlab-ci.yml&file_name=.gitlab-ci.yml&suggest_gitlab_ci_yml=true"
|
|
|
|
|
|
|
|
expect(subject[:merge_request_add_ci_config_path]).to eq(expected_path)
|
2020-02-04 16:08:55 -05:00
|
|
|
end
|
|
|
|
|
2020-04-07 11:09:30 -04:00
|
|
|
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-02-04 16:08:55 -05:00
|
|
|
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-02-27 10:09:24 -05:00
|
|
|
|
|
|
|
context 'when build feature is disabled' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update(builds_access_level: ProjectFeature::DISABLED)
|
|
|
|
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-06-17 17:08:24 -04:00
|
|
|
|
|
|
|
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-02-04 16:08:55 -05:00
|
|
|
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-08-04 05:09:45 -04:00
|
|
|
describe 'user callouts' do
|
|
|
|
context 'when suggest pipeline feature is enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(suggest_pipeline: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'provides a valid path value for user callout path' do
|
|
|
|
expect(subject[:user_callouts_path]).to eq '/-/user_callouts'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'provides a valid value for suggest pipeline feature id' do
|
|
|
|
expect(subject[:suggest_pipeline_feature_id]).to eq described_class::SUGGEST_PIPELINE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'provides a valid value for if it is dismissed' do
|
|
|
|
expect(subject[:is_dismissed_suggest_pipeline]).to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the suggest pipeline has been dismissed' do
|
|
|
|
before do
|
|
|
|
create(:user_callout, user: user, feature_name: described_class::SUGGEST_PIPELINE)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'indicates suggest pipeline has been dismissed' do
|
|
|
|
expect(subject[:is_dismissed_suggest_pipeline]).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not logged in' do
|
|
|
|
let(:request) { double('request', current_user: nil, project: project) }
|
|
|
|
|
|
|
|
it 'returns a blank is dismissed value' do
|
|
|
|
expect(subject[:is_dismissed_suggest_pipeline]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when suggest pipeline feature is not enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(suggest_pipeline: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'provides no valid value for user callout path' do
|
|
|
|
expect(subject[:user_callouts_path]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'provides no valid value for suggest pipeline feature id' do
|
|
|
|
expect(subject[:suggest_pipeline_feature_id]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'provides no valid value for if it is dismissed' do
|
|
|
|
expect(subject[:is_dismissed_suggest_pipeline]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-04 16:08:55 -05:00
|
|
|
it 'has human access' do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
|
|
|
|
expect(subject[:human_access])
|
|
|
|
.to eq('Maintainer')
|
|
|
|
end
|
|
|
|
|
2020-03-04 01:08:23 -05:00
|
|
|
it 'has new pipeline path for project' do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
|
|
|
|
expect(subject[:new_project_pipeline_path])
|
2020-06-02 02:08:01 -04:00
|
|
|
.to eq("/#{resource.project.full_path}/-/pipelines/new")
|
2020-03-04 01:08:23 -05:00
|
|
|
end
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
describe 'when source project is deleted' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
2018-08-31 13:16:34 -04:00
|
|
|
let(:forked_project) { fork_project(project) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
|
2017-12-20 04:01:21 -05:00
|
|
|
|
|
|
|
it 'returns a blank rebase_path' do
|
|
|
|
allow(merge_request).to receive(:should_be_rebased?).and_return(true)
|
2018-08-31 13:16:34 -04:00
|
|
|
forked_project.destroy
|
2017-12-20 04:01:21 -05:00
|
|
|
merge_request.reload
|
|
|
|
|
|
|
|
entity = described_class.new(merge_request, request: request).as_json
|
|
|
|
|
|
|
|
expect(entity[:rebase_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|