Commit 182d1677 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'mo-add-compare-accessibility-report-to-mr' into 'master'

Add compare_accessibility_report to MergeRequest

See merge request gitlab-org/gitlab!31369
parents b7b44c14 6dfda3de
......@@ -1317,6 +1317,14 @@ class MergeRequest < ApplicationRecord
actual_head_pipeline&.has_reports?(Ci::JobArtifact.terraform_reports)
end
def compare_accessibility_reports
unless has_accessibility_reports?
return { status: :error, status_reason: _('This merge request does not have accessibility reports') }
end
compare_reports(Ci::CompareAccessibilityReportsService)
end
# TODO: this method and compare_test_reports use the same
# result type, which is handled by the controller's #reports_response.
# we should minimize mistakes by isolating the common parts.
......
......@@ -21641,6 +21641,9 @@ msgstr ""
msgid "This means you can not push code until you create an empty repository or import existing one."
msgstr ""
msgid "This merge request does not have accessibility reports"
msgstr ""
msgid "This merge request is locked."
msgstr ""
......
......@@ -1889,6 +1889,62 @@ describe MergeRequest do
end
end
describe '#compare_accessibility_reports' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:merge_request, reload: true) { create(:merge_request, :with_accessibility_reports, source_project: project) }
let_it_be(:pipeline) { merge_request.head_pipeline }
subject { merge_request.compare_accessibility_reports }
context 'when head pipeline has accessibility reports' do
let(:job) do
create(:ci_build, options: { artifacts: { reports: { pa11y: ['accessibility.json'] } } }, pipeline: pipeline)
end
let(:artifacts_metadata) { create(:ci_job_artifact, :metadata, job: job) }
context 'when reactive cache worker is parsing results asynchronously' do
it 'returns parsing status' do
expect(subject[:status]).to eq(:parsing)
end
end
context 'when reactive cache worker is inline' do
before do
synchronous_reactive_cache(merge_request)
end
it 'returns parsed status' do
expect(subject[:status]).to eq(:parsed)
expect(subject[:data]).to be_present
end
context 'when an error occurrs' do
before do
merge_request.update!(head_pipeline: nil)
end
it 'returns an error status' do
expect(subject[:status]).to eq(:error)
expect(subject[:status_reason]).to eq("This merge request does not have accessibility reports")
end
end
context 'when cached result is not latest' do
before do
allow_next_instance_of(Ci::CompareAccessibilityReportsService) do |service|
allow(service).to receive(:latest?).and_return(false)
end
end
it 'raises an InvalidateReactiveCache error' do
expect { subject }.to raise_error(ReactiveCaching::InvalidateReactiveCache)
end
end
end
end
end
describe '#all_commit_shas' do
context 'when merge request is persisted' do
let(:all_commit_shas) 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