Commit 8e886c89 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'test_for_vulnerability_presenter' into 'master'

Increase test coverage for vulnerability_presenter

See merge request gitlab-org/gitlab!51019
parents 161f264a f52c68e4
......@@ -3,9 +3,14 @@
require 'spec_helper'
RSpec.describe VulnerabilityPresenter do
let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, :success, project: project) }
let(:finding) { create(:vulnerabilities_finding, :with_secret_detection, pipelines: [pipeline], project: project) }
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, :success, project: project) }
let_it_be(:sast_scan) do
{ type: 'sast', status: 'success', start_time: 'placeholder', end_time: 'placeholder' }
end
let_it_be(:finding) { create(:vulnerabilities_finding, :with_secret_detection, pipelines: [pipeline], project: project) }
let_it_be(:finding2) { create(:vulnerabilities_finding, :with_secret_detection, scan: sast_scan) }
subject { described_class.new(finding.vulnerability) }
......@@ -13,6 +18,24 @@ RSpec.describe VulnerabilityPresenter do
it 'returns the scanner for a finding' do
expect(subject.scanner).to eql(finding.scanner)
end
it 'returns empty hash if scanner is missing for a vulnerabilities_finding' do
finding2.scanner = nil
expect(described_class.new(finding2.vulnerability).scanner).to eql({})
end
end
describe '#scan' do
it 'returns the scan for a finding' do
expect(described_class.new(finding2.vulnerability).scan).to eql(finding2.scan)
end
it 'returns empty hash if scan is missing for a vulnerabilities_finding' do
finding2.scan = nil
expect(described_class.new(finding2.vulnerability).scan).to eql({})
end
end
describe '#remediations' do
......@@ -43,6 +66,38 @@ RSpec.describe VulnerabilityPresenter do
end
end
describe '#blob_path' do
it 'returns the path in blob format' do
path = subject.blob_path
expect(path).to include('blob')
expect(path).to include(finding.file)
expect(path).to include("#L#{finding.location['start_line']}")
end
it 'returns nil if file is missing in the finding' do
allow(subject).to receive(:file).and_return(nil)
expect(subject.blob_path).to be(nil)
end
end
describe '#raw_path' do
it 'returns the path in raw format' do
path = subject.raw_path
expect(path).to include('raw')
expect(path).to include(finding.file)
expect(path).to include("#L#{finding.location['start_line']}")
end
it 'returns nil if file is missing in the finding' do
allow(subject).to receive(:file).and_return(nil)
expect(subject.raw_path).to be(nil)
end
end
describe '#jira_issue_description' do
let(:expected_jira_issue_description) do
<<-JIRA.strip_heredoc
......
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