Commit 25e5861f authored by Rémy Coutable's avatar Rémy Coutable

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

Add accessibility_reports endpoint to MergeRequest

See merge request gitlab-org/gitlab!31391
parents f06c83ba 91fa166b
...@@ -14,7 +14,13 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo ...@@ -14,7 +14,13 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
skip_before_action :merge_request, only: [:index, :bulk_update] skip_before_action :merge_request, only: [:index, :bulk_update]
before_action :whitelist_query_limiting, only: [:assign_related_issues, :update] before_action :whitelist_query_limiting, only: [:assign_related_issues, :update]
before_action :authorize_update_issuable!, only: [:close, :edit, :update, :remove_wip, :sort] before_action :authorize_update_issuable!, only: [:close, :edit, :update, :remove_wip, :sort]
before_action :authorize_read_actual_head_pipeline!, only: [:test_reports, :exposed_artifacts, :coverage_reports, :terraform_reports] before_action :authorize_read_actual_head_pipeline!, only: [
:test_reports,
:exposed_artifacts,
:coverage_reports,
:terraform_reports,
:accessibility_reports
]
before_action :set_issuables_index, only: [:index] before_action :set_issuables_index, only: [:index]
before_action :authenticate_user!, only: [:assign_related_issues] before_action :authenticate_user!, only: [:assign_related_issues]
before_action :check_user_can_push_to_source_branch!, only: [:rebase] before_action :check_user_can_push_to_source_branch!, only: [:rebase]
...@@ -136,6 +142,14 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo ...@@ -136,6 +142,14 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
reports_response(@merge_request.compare_test_reports) reports_response(@merge_request.compare_test_reports)
end end
def accessibility_reports
if @merge_request.has_accessibility_reports?
reports_response(@merge_request.compare_accessibility_reports)
else
head :no_content
end
end
def coverage_reports def coverage_reports
if @merge_request.has_coverage_reports? if @merge_request.has_coverage_reports?
reports_response(@merge_request.find_coverage_reports) reports_response(@merge_request.find_coverage_reports)
......
...@@ -14,6 +14,7 @@ resources :merge_requests, concerns: :awardable, except: [:new, :create, :show], ...@@ -14,6 +14,7 @@ resources :merge_requests, concerns: :awardable, except: [:new, :create, :show],
post :rebase post :rebase
get :test_reports get :test_reports
get :exposed_artifacts get :exposed_artifacts
get :accessibility_reports
get :coverage_reports get :coverage_reports
get :terraform_reports get :terraform_reports
......
...@@ -1341,6 +1341,141 @@ describe Projects::MergeRequestsController do ...@@ -1341,6 +1341,141 @@ describe Projects::MergeRequestsController do
end end
end end
describe 'GET accessibility_reports' do
let(:merge_request) do
create(:merge_request,
:with_diffs,
:with_merge_request_pipeline,
target_project: project,
source_project: project
)
end
let(:pipeline) do
create(:ci_pipeline,
:success,
project: merge_request.source_project,
ref: merge_request.source_branch,
sha: merge_request.diff_head_sha)
end
before do
allow_any_instance_of(MergeRequest)
.to receive(:compare_accessibility_reports)
.and_return(accessibility_comparison)
allow_any_instance_of(MergeRequest)
.to receive(:actual_head_pipeline)
.and_return(pipeline)
end
subject do
get :accessibility_reports, params: {
namespace_id: project.namespace.to_param,
project_id: project,
id: merge_request.iid
},
format: :json
end
context 'permissions on a public project with private CI/CD' do
let(:project) { create(:project, :repository, :public, :builds_private) }
let(:accessibility_comparison) { { status: :parsed, data: { summary: 1 } } }
context 'while signed out' do
before do
sign_out(user)
end
it 'responds with a 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
expect(response.body).to be_blank
end
end
context 'while signed in as an unrelated user' do
before do
sign_in(create(:user))
end
it 'responds with a 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
expect(response.body).to be_blank
end
end
end
context 'when feature flag is disabled' do
let(:accessibility_comparison) { { status: :parsed, data: { summary: 1 } } }
before do
stub_feature_flags(accessibility_report_view: false)
end
it 'returns 204 HTTP status' do
subject
expect(response).to have_gitlab_http_status(:no_content)
end
end
context 'when pipeline has jobs with accessibility reports' do
before do
allow_any_instance_of(MergeRequest)
.to receive(:has_accessibility_reports?)
.and_return(true)
end
context 'when processing accessibility reports is in progress' do
let(:accessibility_comparison) { { status: :parsing } }
it 'sends polling interval' do
expect(Gitlab::PollingInterval).to receive(:set_header)
subject
end
it 'returns 204 HTTP status' do
subject
expect(response).to have_gitlab_http_status(:no_content)
end
end
context 'when processing accessibility reports is completed' do
let(:accessibility_comparison) { { status: :parsed, data: { summary: 1 } } }
it 'returns accessibility reports' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq({ 'summary' => 1 })
end
end
context 'when user created corrupted accessibility reports' do
let(:accessibility_comparison) { { status: :error, status_reason: 'This merge request does not have accessibility reports' } }
it 'does not send polling interval' do
expect(Gitlab::PollingInterval).not_to receive(:set_header)
subject
end
it 'returns 400 HTTP status' do
subject
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to eq({ 'status_reason' => 'This merge request does not have accessibility reports' })
end
end
end
end
describe 'POST remove_wip' do describe 'POST remove_wip' do
before do before do
merge_request.title = merge_request.wip_title merge_request.title = merge_request.wip_title
......
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