Commit 238356ad authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Utilize Vulnerabilities::Statistic model for stats on GraphQL API

parent dc6fa046
......@@ -26,11 +26,7 @@ module EE
field :vulnerability_severities_count, ::Types::VulnerabilitySeveritiesCountType, null: true,
description: 'Counts for each severity of vulnerability of the project',
resolve: -> (obj, _args, ctx) do
Hash.new(0).merge(
obj.vulnerabilities.with_states([:detected, :confirmed]).counts_by_severity
)
end
resolve: -> (obj, *) { obj.vulnerability_statistic || Hash.new(0) }
field :requirement, ::Types::RequirementsManagement::RequirementType, null: true,
description: 'Find a single requirement. Available only when feature flag `requirements_management` is enabled.',
......
......@@ -5,10 +5,7 @@ require 'spec_helper'
RSpec.describe 'Query.project(fullPath).vulnerabilitySeveritiesCount' do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:confirmed_vulnerability) { create(:vulnerability, :confirmed, :high, project: project) }
let_it_be(:detected_vulnerability) { create(:vulnerability, :detected, :high, project: project) }
let_it_be(:resolved_vulnerability) { create(:vulnerability, :resolved, :high, project: project) }
let_it_be(:dismissed_vulnerabilities) { create(:vulnerability, :dismissed, :high, project: project) }
let_it_be(:statistic) { create(:vulnerability_statistic, :d, project: project) }
let_it_be(:query) do
%(
......@@ -33,6 +30,6 @@ RSpec.describe 'Query.project(fullPath).vulnerabilitySeveritiesCount' do
it "returns counts for each severity of the project's detected or confirmed vulnerabilities" do
high_count = subject.dig('data', 'project', 'vulnerabilitySeveritiesCount', 'high')
expect(high_count).to be(2)
expect(high_count).to be(statistic.high)
end
end
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