Commit a463cdfb authored by Marcos Rocha's avatar Marcos Rocha Committed by Luke Duncalfe

Add EE variant of Resolvers::ProjectPipelinesResolver

https://gitlab.com/gitlab-org/gitlab/-/issues/338645

Changelog: added
EE: true
parent 50001036
...@@ -26,3 +26,5 @@ module Resolvers ...@@ -26,3 +26,5 @@ module Resolvers
end end
end end
# rubocop: enable Graphql/ResolverType # rubocop: enable Graphql/ResolverType
Resolvers::ProjectPipelinesResolver.prepend_mod
# frozen_string_literal: true
module EE
module Resolvers
module ProjectPipelinesResolver
extend ::Gitlab::Utils::Override
override :preloads
def preloads
super.merge(dast_profile: [{ dast_profile: [{ dast_site_profile: [:dast_site, :secret_variables] },
:dast_scanner_profile, :dast_profile_schedule] }])
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Query.project(fullPath).pipelines.dastProfile' do
include GraphqlHelpers
let_it_be(:project) { create(:project, :repository) }
let_it_be(:dast_profile) { create(:dast_profile, project: project) }
let_it_be(:pipeline) { create(:ci_pipeline, :success, project: project, dast_profile: dast_profile) }
let_it_be(:current_user) { create(:user) }
let(:query) do
%(
query {
project(fullPath: "#{project.full_path}") {
pipelines {
edges {
node {
dastProfile {
#{all_graphql_fields_for('DastProfile')}
}
}
}
}
}
}
)
end
subject { post_graphql(query, current_user: current_user) }
let(:pipelines_data) { graphql_data_at(:project, :pipelines, :edges, :node) }
let(:dast_profile_data) { graphql_dig_at(pipelines_data, :dastProfile) }
context 'when feature is not licensed' do
it 'does not return dast profile data' do
subject
expect(dast_profile_data).to be_nil
end
end
context 'when feature is licensed' do
before do
stub_licensed_features(security_on_demand_scans: true)
end
context 'when user is not member of the project' do
it 'does not return dast profile data' do
subject
expect(dast_profile_data).to be_nil
end
end
context 'when user is member of the project' do
before do
project.add_developer(current_user)
end
it 'returns the dast profile data' do
subject
expect(dast_profile_data.first['name']).to eq(dast_profile.name)
end
it 'avoids N+1 queries', :aggregate_failures do
control = ActiveRecord::QueryRecorder.new do
post_graphql(query, current_user: current_user)
end
5.times do
dast_profile = create(:dast_profile, project: project)
create(:ci_pipeline, :success, project: project, dast_profile: dast_profile)
end
expect { subject }.not_to exceed_query_limit(control)
expect(dast_profile_data.size).to eq(6)
end
context 'when feature flag is not enabled' do
it 'does not return dast profile data' do
stub_feature_flags(dast_view_scans: false)
subject
expect(dast_profile_data).to be_empty
end
end
end
end
end
...@@ -11,15 +11,23 @@ RSpec.describe Resolvers::ProjectPipelinesResolver do ...@@ -11,15 +11,23 @@ RSpec.describe Resolvers::ProjectPipelinesResolver do
let(:current_user) { create(:user) } let(:current_user) { create(:user) }
before do context 'when the user does have access' do
project.add_developer(current_user) before do
project.add_developer(current_user)
end
it 'resolves only MRs for the passed merge request' do
expect(resolve_pipelines).to contain_exactly(pipeline)
end
end end
def resolve_pipelines context 'when the user does not have access' do
resolve(described_class, obj: project, ctx: { current_user: current_user }) it 'does not return pipeline data' do
expect(resolve_pipelines).to be_empty
end
end end
it 'resolves only MRs for the passed merge request' do def resolve_pipelines
expect(resolve_pipelines).to contain_exactly(pipeline) resolve(described_class, obj: project, ctx: { current_user: current_user })
end end
end end
...@@ -1338,3 +1338,4 @@ ...@@ -1338,3 +1338,4 @@
- "./spec/workers/repository_cleanup_worker_spec.rb" - "./spec/workers/repository_cleanup_worker_spec.rb"
- "./spec/workers/stage_update_worker_spec.rb" - "./spec/workers/stage_update_worker_spec.rb"
- "./spec/workers/stuck_merge_jobs_worker_spec.rb" - "./spec/workers/stuck_merge_jobs_worker_spec.rb"
- "./ee/spec/requests/api/graphql/project/pipelines/dast_profile_spec.rb"
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