Commit 4c95f25f authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '296098-created-issue-feedback' into 'master'

Bring back the ability to return issue feedback when there is no issue link associated to vulnerability

See merge request gitlab-org/gitlab!65191
parents ca94c201 b8f44623
......@@ -198,7 +198,8 @@ module Vulnerabilities
end
def issue_feedback
Vulnerabilities::Feedback.find_by(issue: vulnerability&.related_issues) if vulnerability
related_issues = vulnerability&.related_issues
related_issues.blank? ? feedback(feedback_type: 'issue') : Vulnerabilities::Feedback.find_by(issue: related_issues)
end
def merge_request_feedback
......
......@@ -521,7 +521,7 @@ RSpec.describe Vulnerabilities::Finding do
describe 'feedback' do
let_it_be(:project) { create(:project) }
let(:finding) do
let_it_be(:finding) do
create(
:vulnerabilities_finding,
report_type: :dependency_scanning,
......@@ -530,8 +530,8 @@ RSpec.describe Vulnerabilities::Finding do
end
describe '#issue_feedback' do
let(:issue) { create(:issue, project: project) }
let!(:issue_feedback) do
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:issue_feedback) do
create(
:vulnerability_feedback,
:dependency_scanning,
......@@ -543,35 +543,35 @@ RSpec.describe Vulnerabilities::Finding do
end
let(:vulnerability) { create(:vulnerability, findings: [finding]) }
let!(:issue_link) { create(:vulnerabilities_issue_link, vulnerability: vulnerability, issue: issue)}
it 'returns associated feedback' do
feedback = finding.issue_feedback
context 'when there is issue link present' do
let!(:issue_link) { create(:vulnerabilities_issue_link, vulnerability: vulnerability, issue: issue)}
expect(feedback).to be_present
expect(feedback[:project_id]).to eq project.id
expect(feedback[:feedback_type]).to eq 'issue'
expect(feedback[:issue_id]).to eq issue.id
end
context 'when there is no feedback for the vulnerability' do
let(:vulnerability_no_feedback) { create(:vulnerability, findings: [finding_no_feedback]) }
let!(:finding_no_feedback) { create(:vulnerabilities_finding, :dependency_scanning, project: project) }
it 'returns associated feedback' do
expect(finding.issue_feedback).to eq(issue_feedback)
end
it 'does not return unassociated feedback' do
feedback = finding_no_feedback.issue_feedback
context 'when there is no feedback for the vulnerability' do
let(:vulnerability_no_feedback) { create(:vulnerability, findings: [finding_no_feedback]) }
let!(:finding_no_feedback) { create(:vulnerabilities_finding, :dependency_scanning, project: project) }
expect(feedback).not_to be_present
it 'does not return unassociated feedback' do
expect(finding_no_feedback.issue_feedback).to be_nil
end
end
end
context 'when there is no vulnerability associated with the finding' do
let!(:finding_no_vulnerability) { create(:vulnerabilities_finding, :dependency_scanning, project: project) }
context 'when there is no vulnerability associated with the finding' do
let!(:finding_no_vulnerability) { create(:vulnerabilities_finding, :dependency_scanning, project: project) }
it 'does not return feedback' do
feedback = finding_no_vulnerability.issue_feedback
it 'does not return feedback' do
expect(finding_no_vulnerability.issue_feedback).to be_nil
end
end
end
expect(feedback).not_to be_present
context 'when there is no issue link present' do
it 'returns associated feedback' do
expect(finding.issue_feedback).to eq(issue_feedback)
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