Commit e55b3da4 authored by Matija Čupić's avatar Matija Čupić

Refactor codequality job artifact presentation

This refactors the codequality MR widget specs to test with real data.
parent 530b3fda
......@@ -43,7 +43,10 @@ module EE
return OpenStruct.new(build: build, path: file_name)
end
end.last
end
# In case there is no artifact return nil
nil
end
def performance_artifact
......
......@@ -8,10 +8,10 @@ module EE
def downloadable_url_for_report_type(file_type)
if (job_artifact = artifact_for_file_type(file_type)) &&
can?(current_user, :read_build, job_artifact.build)
can?(current_user, :read_build, job_artifact.job)
return download_project_build_artifacts_url(
job_artifact.project,
job_artifact.build,
job_artifact.job,
file_type: file_type)
end
......
......@@ -16,13 +16,13 @@ module EE
end
end
expose :codeclimate, if: -> (mr, _) { mr.head_pipeline&.present&.downloadable_url_for_report_type(:codequality) } do
expose :codeclimate, if: -> (mr, _) { head_pipeline_downloadable_url_for_report_type(mr, :codequality) } do
expose :head_path do |merge_request|
merge_request.head_pipeline.present.downloadable_url_for_report_type(:codequality)
head_pipeline_downloadable_url_for_report_type(merge_request, :codequality)
end
expose :base_path do |merge_request|
merge_request.base_pipeline.present.downloadable_url_for_report_type(:codequality)
base_pipeline_downloadable_url_for_report_type(merge_request, :codequality)
end
end
......@@ -167,5 +167,15 @@ module EE
presenter(merge_request).approvals_path
end
end
private
def head_pipeline_downloadable_url_for_report_type(merge_request, file_type)
merge_request.head_pipeline&.present&.downloadable_url_for_report_type(file_type)
end
def base_pipeline_downloadable_url_for_report_type(merge_request, file_type)
merge_request.base_pipeline&.present&.downloadable_url_for_report_type(file_type)
end
end
end
......@@ -170,6 +170,7 @@ describe Ci::Pipeline do
let(:file_type) { :codequality }
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:artifact) { create(:ci_job_artifact, :codequality, job: build) }
subject { pipeline.artifact_for_file_type(file_type) }
it 'returns the artifact' do
......
......@@ -26,14 +26,31 @@ describe MergeRequestWidgetEntity do
expect(subject.as_json[:blob_path]).to include(:head_path)
end
it 'has codeclimate data' do
allow(merge_request).to receive_messages(
base_pipeline: pipeline,
head_pipeline: pipeline
)
allow_any_instance_of(EE::Ci::PipelinePresenter).to receive(:downloadable_url_for_report_type).and_return("dummy/url")
describe 'codeclimate' do
before do
allow(merge_request).to receive_messages(
base_pipeline: pipeline,
head_pipeline: pipeline
)
allow_any_instance_of(Ci::PipelinePresenter).to receive(:current_user).and_return(user)
end
context 'with codeclimate data' do
before do
job = create(:ci_build, pipeline: pipeline)
create(:ci_job_artifact, :codequality, job: job)
end
expect(subject.as_json).to include(:codeclimate)
it 'has codeclimate data entry' do
expect(subject.as_json).to include(:codeclimate)
end
end
context 'without codeclimate data' do
it 'does not have codeclimate data entry' do
expect(subject.as_json).not_to include(:codeclimate)
end
end
end
it 'sets approvals_before_merge to 0 if nil' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment