Commit 52284c1d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'refactor-compare-analyser-service-tests' into 'master'

Refactor compare analyser reports service tests

See merge request gitlab-org/gitlab!28207
parents 289b7806 76cb7e5f
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
describe Ci::CompareContainerScanningReportsService do describe Ci::CompareContainerScanningReportsService do
let(:current_user) { project.users.take } let(:current_user) { build(:user, :admin) }
let(:service) { described_class.new(project, current_user) } let(:service) { described_class.new(project, current_user) }
let(:project) { create(:project, :repository) } let(:project) { build(:project, :repository) }
before do before do
stub_licensed_features(container_scanning: true) stub_licensed_features(container_scanning: true)
...@@ -59,22 +59,5 @@ describe Ci::CompareContainerScanningReportsService do ...@@ -59,22 +59,5 @@ describe Ci::CompareContainerScanningReportsService do
expect(compare_keys - expected_keys).to eq([]) expect(compare_keys - expected_keys).to eq([])
end end
end end
context 'when head pipeline has corrupted container scanning vulnerability reports' do
let!(:base_pipeline) { create(:ee_ci_pipeline, :with_corrupted_container_scanning_report, project: project) }
let!(:head_pipeline) { create(:ee_ci_pipeline, :with_corrupted_container_scanning_report, project: project) }
it 'returns status and error message' do
expect(subject[:status]).to eq(:error)
expect(subject[:status_reason]).to include('JSON parsing failed')
end
it 'returns status and error message when pipeline is nil' do
result = service.execute(nil, head_pipeline)
expect(result[:status]).to eq(:error)
expect(result[:status_reason]).to include('JSON parsing failed')
end
end
end end
end end
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
describe Ci::CompareDastReportsService do describe Ci::CompareDastReportsService do
let(:current_user) { project.users.take } let(:current_user) { build(:user, :admin) }
let(:service) { described_class.new(project, current_user) } let(:service) { described_class.new(project, current_user) }
let(:project) { create(:project, :repository) } let(:project) { build(:project, :repository) }
before do before do
stub_licensed_features(container_scanning: true, dast: true) stub_licensed_features(container_scanning: true, dast: true)
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
describe Ci::CompareDependencyScanningReportsService do describe Ci::CompareDependencyScanningReportsService do
let(:current_user) { project.users.take } let(:current_user) { build(:user, :admin) }
let(:service) { described_class.new(project, current_user) } let(:service) { described_class.new(project, current_user) }
let(:project) { create(:project, :repository) } let(:project) { build(:project, :repository) }
before do before do
stub_licensed_features(dependency_scanning: true) stub_licensed_features(dependency_scanning: true)
...@@ -36,6 +36,7 @@ describe Ci::CompareDependencyScanningReportsService do ...@@ -36,6 +36,7 @@ describe Ci::CompareDependencyScanningReportsService do
it 'populates fields based on current_user' do it 'populates fields based on current_user' do
payload = subject[:data]['existing'].first payload = subject[:data]['existing'].first
expect(payload['create_vulnerability_feedback_issue_path']).not_to be_empty expect(payload['create_vulnerability_feedback_issue_path']).not_to be_empty
expect(payload['create_vulnerability_feedback_merge_request_path']).not_to be_empty expect(payload['create_vulnerability_feedback_merge_request_path']).not_to be_empty
expect(payload['create_vulnerability_feedback_dismissal_path']).not_to be_empty expect(payload['create_vulnerability_feedback_dismissal_path']).not_to be_empty
...@@ -61,8 +62,14 @@ describe Ci::CompareDependencyScanningReportsService do ...@@ -61,8 +62,14 @@ describe Ci::CompareDependencyScanningReportsService do
end end
context 'when head pipeline has corrupted dependency scanning vulnerability reports' do context 'when head pipeline has corrupted dependency scanning vulnerability reports' do
let!(:base_pipeline) { create(:ee_ci_pipeline, :with_corrupted_dependency_scanning_report, project: project) } let!(:base_pipeline) { build(:ee_ci_pipeline, :with_corrupted_dependency_scanning_report, project: project) }
let!(:head_pipeline) { create(:ee_ci_pipeline, :with_corrupted_dependency_scanning_report, project: project) } let!(:head_pipeline) { build(:ee_ci_pipeline, :with_corrupted_dependency_scanning_report, project: project) }
before do
error = Gitlab::Ci::Parsers::ParserError.new('Exception: JSON parsing failed')
allow(base_pipeline).to receive(:license_scanning_report).and_raise(error)
allow(head_pipeline).to receive(:license_scanning_report).and_raise(error)
end
it 'returns status and error message' do it 'returns status and error message' do
expect(subject[:status]).to eq(:error) expect(subject[:status]).to eq(:error)
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
describe Ci::CompareSastReportsService do describe Ci::CompareSastReportsService do
let(:current_user) { project.users.take } let(:current_user) { build(:user, :admin) }
let(:service) { described_class.new(project, current_user) } let(:service) { described_class.new(project, current_user) }
let(:project) { create(:project, :repository) } let(:project) { build(:project, :repository) }
before do before do
stub_licensed_features(container_scanning: true) stub_licensed_features(container_scanning: true)
...@@ -37,6 +37,7 @@ describe Ci::CompareSastReportsService do ...@@ -37,6 +37,7 @@ describe Ci::CompareSastReportsService do
it 'populates fields based on current_user' do it 'populates fields based on current_user' do
payload = subject[:data]['existing'].first payload = subject[:data]['existing'].first
expect(payload['create_vulnerability_feedback_issue_path']).not_to be_empty expect(payload['create_vulnerability_feedback_issue_path']).not_to be_empty
expect(payload['create_vulnerability_feedback_merge_request_path']).not_to be_empty expect(payload['create_vulnerability_feedback_merge_request_path']).not_to be_empty
expect(payload['create_vulnerability_feedback_dismissal_path']).not_to be_empty expect(payload['create_vulnerability_feedback_dismissal_path']).not_to be_empty
......
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