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 ...@@ -198,7 +198,8 @@ module Vulnerabilities
end end
def issue_feedback 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 end
def merge_request_feedback def merge_request_feedback
......
...@@ -521,7 +521,7 @@ RSpec.describe Vulnerabilities::Finding do ...@@ -521,7 +521,7 @@ RSpec.describe Vulnerabilities::Finding do
describe 'feedback' do describe 'feedback' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:finding) do let_it_be(:finding) do
create( create(
:vulnerabilities_finding, :vulnerabilities_finding,
report_type: :dependency_scanning, report_type: :dependency_scanning,
...@@ -530,8 +530,8 @@ RSpec.describe Vulnerabilities::Finding do ...@@ -530,8 +530,8 @@ RSpec.describe Vulnerabilities::Finding do
end end
describe '#issue_feedback' do describe '#issue_feedback' do
let(:issue) { create(:issue, project: project) } let_it_be(:issue) { create(:issue, project: project) }
let!(:issue_feedback) do let_it_be(:issue_feedback) do
create( create(
:vulnerability_feedback, :vulnerability_feedback,
:dependency_scanning, :dependency_scanning,
...@@ -543,35 +543,35 @@ RSpec.describe Vulnerabilities::Finding do ...@@ -543,35 +543,35 @@ RSpec.describe Vulnerabilities::Finding do
end end
let(:vulnerability) { create(:vulnerability, findings: [finding]) } let(:vulnerability) { create(:vulnerability, findings: [finding]) }
let!(:issue_link) { create(:vulnerabilities_issue_link, vulnerability: vulnerability, issue: issue)}
it 'returns associated feedback' do context 'when there is issue link present' do
feedback = finding.issue_feedback let!(:issue_link) { create(:vulnerabilities_issue_link, vulnerability: vulnerability, issue: issue)}
expect(feedback).to be_present it 'returns associated feedback' do
expect(feedback[:project_id]).to eq project.id expect(finding.issue_feedback).to eq(issue_feedback)
expect(feedback[:feedback_type]).to eq 'issue' end
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 'does not return unassociated feedback' do context 'when there is no feedback for the vulnerability' do
feedback = finding_no_feedback.issue_feedback 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
end
context 'when there is no vulnerability associated with the finding' do context 'when there is no vulnerability associated with the finding' do
let!(:finding_no_vulnerability) { create(:vulnerabilities_finding, :dependency_scanning, project: project) } let!(:finding_no_vulnerability) { create(:vulnerabilities_finding, :dependency_scanning, project: project) }
it 'does not return feedback' do it 'does not return feedback' do
feedback = finding_no_vulnerability.issue_feedback 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 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