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 ...@@ -43,7 +43,10 @@ module EE
return OpenStruct.new(build: build, path: file_name) return OpenStruct.new(build: build, path: file_name)
end end
end.last end
# In case there is no artifact return nil
nil
end end
def performance_artifact def performance_artifact
......
...@@ -8,10 +8,10 @@ module EE ...@@ -8,10 +8,10 @@ module EE
def downloadable_url_for_report_type(file_type) def downloadable_url_for_report_type(file_type)
if (job_artifact = artifact_for_file_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( return download_project_build_artifacts_url(
job_artifact.project, job_artifact.project,
job_artifact.build, job_artifact.job,
file_type: file_type) file_type: file_type)
end end
......
...@@ -16,13 +16,13 @@ module EE ...@@ -16,13 +16,13 @@ module EE
end end
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| 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 end
expose :base_path do |merge_request| 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
end end
...@@ -167,5 +167,15 @@ module EE ...@@ -167,5 +167,15 @@ module EE
presenter(merge_request).approvals_path presenter(merge_request).approvals_path
end end
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
end end
...@@ -170,6 +170,7 @@ describe Ci::Pipeline do ...@@ -170,6 +170,7 @@ describe Ci::Pipeline do
let(:file_type) { :codequality } let(:file_type) { :codequality }
let!(:build) { create(:ci_build, pipeline: pipeline) } let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:artifact) { create(:ci_job_artifact, :codequality, job: build) } let!(:artifact) { create(:ci_job_artifact, :codequality, job: build) }
subject { pipeline.artifact_for_file_type(file_type) } subject { pipeline.artifact_for_file_type(file_type) }
it 'returns the artifact' do it 'returns the artifact' do
......
...@@ -26,15 +26,32 @@ describe MergeRequestWidgetEntity do ...@@ -26,15 +26,32 @@ describe MergeRequestWidgetEntity do
expect(subject.as_json[:blob_path]).to include(:head_path) expect(subject.as_json[:blob_path]).to include(:head_path)
end end
it 'has codeclimate data' do describe 'codeclimate' do
before do
allow(merge_request).to receive_messages( allow(merge_request).to receive_messages(
base_pipeline: pipeline, base_pipeline: pipeline,
head_pipeline: pipeline head_pipeline: pipeline
) )
allow_any_instance_of(EE::Ci::PipelinePresenter).to receive(:downloadable_url_for_report_type).and_return("dummy/url") 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
it 'has codeclimate data entry' do
expect(subject.as_json).to include(:codeclimate) expect(subject.as_json).to include(:codeclimate)
end 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 it 'sets approvals_before_merge to 0 if nil' do
expect(subject.as_json[:approvals_before_merge]).to eq(0) expect(subject.as_json[:approvals_before_merge]).to eq(0)
......
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