Commit 173af671 authored by Michael Kozono's avatar Michael Kozono

Merge branch '294173-description-of-vulnerability-is-empty-in-graphql' into 'master'

Populate description of vulnerability from finding if needed

See merge request gitlab-org/gitlab!52619
parents 6b1ce745 330a1180
...@@ -130,6 +130,10 @@ module Types ...@@ -130,6 +130,10 @@ module Types
object.finding&.identifiers object.finding&.identifiers
end end
def description
object.description || object.finding_description
end
def project def project
Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find
end end
......
---
title: Properly populate description in an issue created from a vulnerability
merge_request: 52619
author:
type: fixed
...@@ -106,4 +106,44 @@ RSpec.describe GitlabSchema.types['Vulnerability'] do ...@@ -106,4 +106,44 @@ RSpec.describe GitlabSchema.types['Vulnerability'] do
end end
end end
end end
describe '#description' do
let_it_be(:vulnerability_with_finding) { create(:vulnerability, :with_findings, project: project) }
let(:query) do
%(
query {
project(fullPath: "#{project.full_path}") {
name
vulnerabilities {
nodes {
description
}
}
}
}
)
end
context 'when the vulnerability description field is populated' do
it 'returns the description for the vulnerability' do
vulnerabilities = subject.dig('data', 'project', 'vulnerabilities', 'nodes')
expect(vulnerabilities.first['description']).to eq(vulnerability_with_finding.description)
end
end
context 'when the vulnerability description field is empty' do
before do
vulnerability_with_finding.description = nil
vulnerability_with_finding.save!
end
it 'returns the description for the vulnerability finding' do
vulnerabilities = subject.dig('data', 'project', 'vulnerabilities', 'nodes')
expect(vulnerabilities.first['description']).to eq(vulnerability_with_finding.finding.description)
end
end
end
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