Commit f52c68e4 authored by Saikat Sarkar's avatar Saikat Sarkar

Increase test coverage for vulnerability_presenter

parent d9252c0a
...@@ -3,9 +3,14 @@ ...@@ -3,9 +3,14 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe VulnerabilityPresenter do RSpec.describe VulnerabilityPresenter do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, :success, project: project) } let_it_be(:pipeline) { create(:ci_pipeline, :success, project: project) }
let(:finding) { create(:vulnerabilities_finding, :with_secret_detection, pipelines: [pipeline], 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) } subject { described_class.new(finding.vulnerability) }
...@@ -13,6 +18,24 @@ RSpec.describe VulnerabilityPresenter do ...@@ -13,6 +18,24 @@ RSpec.describe VulnerabilityPresenter do
it 'returns the scanner for a finding' do it 'returns the scanner for a finding' do
expect(subject.scanner).to eql(finding.scanner) expect(subject.scanner).to eql(finding.scanner)
end 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 end
describe '#remediations' do describe '#remediations' do
...@@ -43,6 +66,38 @@ RSpec.describe VulnerabilityPresenter do ...@@ -43,6 +66,38 @@ RSpec.describe VulnerabilityPresenter do
end end
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 describe '#jira_issue_description' do
let(:expected_jira_issue_description) do let(:expected_jira_issue_description) do
<<-JIRA.strip_heredoc <<-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