Commit 2ac65b13 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix specs

parent ef6b8a8c
......@@ -28,8 +28,8 @@ module EE
dependency_scanning: %i[dependency_scanning],
container_scanning: %i[container_scanning sast_container],
dast: %i[dast],
performance: %i[:merge_request_performance_metrics],
license_management: nil
performance: %i[merge_request_performance_metrics],
license_management: %i[license_management]
}.freeze
# Deprecated, to be removed in 12.0
......
......@@ -6,9 +6,25 @@ FactoryBot.define do
failure_reason { Ci::Build.failure_reasons[:protected_environment_failure] }
end
trait :security_reports do
after(:build) do |build|
build.job_artifacts << create(:ee_ci_job_artifact, :sast, job: build)
%i[sast performance license_management].each do |report_type|
trait "legacy_#{report_type}".to_sym do
success
artifacts
name report_type
options do
{
artifacts: {
paths: [Ci::JobArtifact::DEFAULT_FILE_NAMES[report_type]]
}
}
end
end
trait report_type do
after(:build) do |build|
build.job_artifacts << build(:ee_ci_job_artifact, report_type, job: build)
end
end
end
end
......
require 'spec_helper'
describe MergeRequestWidgetEntity do
let(:user) { create(:user) }
let(:project) { create :project, :repository }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
set(:user) { create(:user) }
set(:project) { create :project, :repository }
set(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
set(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:request) { double('request', current_user: user) }
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
before do
project.add_developer(user)
......@@ -39,6 +39,8 @@ describe MergeRequestWidgetEntity do
:dependency_scanning | :dependency_scanning
:sast_container | :container_scanning
:dast | :dast
:license_management | :license_management
:performance | :performance
end
with_them do
......@@ -54,7 +56,7 @@ describe MergeRequestWidgetEntity do
allow(pipeline).to receive(:available_licensed_report_type?).and_return(true)
end
context "with data" do
context "with new report artifacts" do
before do
job = create(:ci_build, pipeline: pipeline)
create(:ci_job_artifact, file_type: artifact_type, file_format: Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS[artifact_type], job: job)
......@@ -65,7 +67,27 @@ describe MergeRequestWidgetEntity do
end
end
context "without data" do
context "with legacy report artifacts" do
before do
create(:ci_build,
:success,
:artifacts,
pipeline: pipeline,
name: artifact_type,
options: {
artifacts: {
paths: [Ci::JobArtifact::DEFAULT_FILE_NAMES[artifact_type]]
}
}
)
end
it "has data entry" do
expect(subject.as_json).to include(json_entry)
end
end
context "without artifacts" do
it "does not have data entry" do
expect(subject.as_json).not_to include(json_entry)
end
......@@ -76,34 +98,67 @@ describe MergeRequestWidgetEntity do
describe '#license_management' do
before do
build = create(:ci_build, pipeline: pipeline)
create(:ee_ci_job_artifact, :license_management, job: build)
allow(merge_request).to receive_messages(
head_pipeline: pipeline, target_project: project)
stub_licensed_features(license_management: true)
end
it 'should not be included, if license management features are off' do
allow(merge_request).to receive_messages(expose_license_management_data?: false)
it 'should not be included, if missing artifacts' do
expect(subject.as_json).not_to include(:license_management)
end
it 'should be included, if license manage management features are on' do
expect(subject.as_json).to include(:license_management)
expect(subject.as_json[:license_management]).to include(:head_path)
expect(subject.as_json[:license_management]).to include(:base_path)
expect(subject.as_json[:license_management]).to include(:managed_licenses_path)
expect(subject.as_json[:license_management]).to include(:can_manage_licenses)
expect(subject.as_json[:license_management]).to include(:license_management_full_report_path)
end
context 'when report artifact is defined' do
before do
create(:ee_ci_build, :license_management, pipeline: pipeline)
end
it 'should be included' do
expect(subject.as_json).to include(:license_management)
expect(subject.as_json[:license_management]).to include(:head_path)
expect(subject.as_json[:license_management]).to include(:base_path)
expect(subject.as_json[:license_management]).to include(:managed_licenses_path)
expect(subject.as_json[:license_management]).to include(:can_manage_licenses)
expect(subject.as_json[:license_management]).to include(:license_management_full_report_path)
end
context 'when feature is not licensed' do
before do
stub_licensed_features(license_management: false)
end
it 'should not be included' do
expect(subject.as_json).not_to include(:license_management)
end
end
it '#license_management_settings_path should not be included for developers' do
expect(subject.as_json[:license_management]).not_to include(:license_management_settings_path)
end
context 'when user is maintainer' do
before do
project.add_maintainer(user)
end
it '#license_management_settings_path should not be included for developers' do
expect(subject.as_json[:license_management]).not_to include(:license_management_settings_path)
it '#license_management_settings_path should be included for maintainers' do
expect(subject.as_json[:license_management]).to include(:license_management_settings_path)
end
end
end
it '#license_management_settings_path should be included for maintainers' do
stub_licensed_features(license_management: true)
project.add_maintainer(user)
context 'when legacy artifact is defined' do
before do
create(:ee_ci_build, :legacy_license_management, pipeline: pipeline)
end
expect(subject.as_json[:license_management]).to include(:license_management_settings_path)
it 'should be included, if license manage management features are on' do
expect(subject.as_json).to include(:license_management)
expect(subject.as_json[:license_management]).to include(:head_path)
expect(subject.as_json[:license_management]).to include(:base_path)
expect(subject.as_json[:license_management]).to include(:managed_licenses_path)
expect(subject.as_json[:license_management]).to include(:can_manage_licenses)
expect(subject.as_json[:license_management]).to include(:license_management_full_report_path)
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