Commit 43b3af73 authored by Nick Thomas's avatar Nick Thomas

Merge branch '13084-add-dependency-list-fixture' into 'master'

Add dependency factory

See merge request gitlab-org/gitlab-ee!15143
parents af59919b b3ad2f45
# frozen_string_literal: true
FactoryBot.define do
factory :dependency, class: Hash do
name 'nokogiri'
packager 'Ruby (Bundler)'
version '1.8.0'
location do
{
blob_path: '/some_project/path/Gemfile.lock',
path: 'Gemfile.lock'
}
end
trait :with_vulnerabilities do
vulnerabilities do
[{
name: 'DDoS',
severity: 'high'
},
{
name: 'XSS vulnerability',
severity: 'low'
}]
end
end
initialize_with { attributes }
end
end
...@@ -9,33 +9,7 @@ describe DependencyEntity do ...@@ -9,33 +9,7 @@ describe DependencyEntity do
set(:project) { create(:project, :repository, :private) } set(:project) { create(:project, :repository, :private) }
set(:user) { create(:user) } set(:user) { create(:user) }
let(:request) { double('request') } let(:request) { double('request') }
let(:dependency) { dependency_info.merge(vulnerabilities) } let(:dependency) { build(:dependency, :with_vulnerabilities) }
let(:dependency_info) do
{
name: 'nokogiri',
packager: 'Ruby (Bundler)',
version: '1.8.0',
location: {
blob_path: '/some_project/path/Gemfile.lock',
path: 'Gemfile.lock'
}
}
end
let(:vulnerabilities) do
{
vulnerabilities:
[{
name: 'DDoS',
severity: 'high'
},
{
name: 'XSS vulnerability',
severity: 'low'
}]
}
end
before do before do
stub_licensed_features(security_dashboard: true) stub_licensed_features(security_dashboard: true)
...@@ -54,6 +28,8 @@ describe DependencyEntity do ...@@ -54,6 +28,8 @@ describe DependencyEntity do
end end
context 'with reporter' do context 'with reporter' do
let(:dependency_info) { build(:dependency) }
before do before do
project.add_reporter(user) project.add_reporter(user)
end end
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
describe DependencyListEntity do describe DependencyListEntity do
describe '#as_json' do describe '#as_json' do
let(:entity) do let(:entity) do
described_class.represent(dependencies, build: build, request: request) described_class.represent(dependencies, build: ci_build, request: request)
end end
let(:request) { double('request') } let(:request) { double('request') }
...@@ -22,23 +22,13 @@ describe DependencyListEntity do ...@@ -22,23 +22,13 @@ describe DependencyListEntity do
context 'with success build' do context 'with success build' do
let(:user) { developer } let(:user) { developer }
let(:build) { create(:ee_ci_build, :success) } let(:ci_build) { create(:ee_ci_build, :success) }
context 'with provided dependencies' do context 'with provided dependencies' do
let(:dependencies) do let(:dependencies) { [build(:dependency)] }
[{
name: 'nokogiri',
packager: 'Ruby (Bundler)',
version: '1.8.0',
location: {
blob_path: '/some_project/path/Gemfile.lock',
path: 'Gemfile.lock'
}
}]
end
it 'has array of dependencies with status ok' do it 'has array of dependencies with status ok' do
job_path = "/#{project.full_path}/builds/#{build.id}" job_path = "/#{project.full_path}/builds/#{ci_build.id}"
expect(subject[:dependencies][0][:name]).to eq('nokogiri') expect(subject[:dependencies][0][:name]).to eq('nokogiri')
expect(subject[:report][:status]).to eq(:ok) expect(subject[:report][:status]).to eq(:ok)
...@@ -51,7 +41,7 @@ describe DependencyListEntity do ...@@ -51,7 +41,7 @@ describe DependencyListEntity do
let(:dependencies) { [] } let(:dependencies) { [] }
it 'has empty array of dependencies with status no_dependencies' do it 'has empty array of dependencies with status no_dependencies' do
job_path = "/#{project.full_path}/builds/#{build.id}" job_path = "/#{project.full_path}/builds/#{ci_build.id}"
expect(subject[:dependencies].length).to eq(0) expect(subject[:dependencies].length).to eq(0)
expect(subject[:report][:status]).to eq(:no_dependencies) expect(subject[:report][:status]).to eq(:no_dependencies)
...@@ -61,7 +51,7 @@ describe DependencyListEntity do ...@@ -61,7 +51,7 @@ describe DependencyListEntity do
end end
context 'with failed build' do context 'with failed build' do
let(:build) { create(:ee_ci_build, :failed) } let(:ci_build) { create(:ee_ci_build, :failed) }
let(:dependencies) { [] } let(:dependencies) { [] }
context 'with authorized user' do context 'with authorized user' do
...@@ -85,7 +75,7 @@ describe DependencyListEntity do ...@@ -85,7 +75,7 @@ describe DependencyListEntity do
context 'with no build' do context 'with no build' do
let(:user) { developer } let(:user) { developer }
let(:build) { nil } let(:ci_build) { nil }
let(:dependencies) { [] } let(:dependencies) { [] }
it 'has status job_not_set_up and no job_path' do it 'has status job_not_set_up and no job_path' do
......
...@@ -3,29 +3,13 @@ ...@@ -3,29 +3,13 @@
require 'spec_helper' require 'spec_helper'
describe DependencyListSerializer do describe DependencyListSerializer do
let(:build) { create(:ee_ci_build, :success) }
set(:project) { create(:project, :repository, :private) } set(:project) { create(:project, :repository, :private) }
set(:user) { create(:user) } set(:user) { create(:user) }
let(:ci_build) { create(:ee_ci_build, :success) }
let(:dependencies) { [build(:dependency, :with_vulnerabilities)] }
let(:serializer) do let(:serializer) do
described_class.new(project: project, user: user).represent(dependencies, build: build) described_class.new(project: project, user: user).represent(dependencies, build: ci_build)
end
let(:dependencies) do
[{
name: 'nokogiri',
packager: 'Ruby (Bundler)',
version: '1.8.0',
location: {
blob_path: '/some_project/path/Gemfile.lock',
path: 'Gemfile.lock'
},
vulnerabilities:
[{
name: 'XSS',
severity: 'low'
}]
}]
end end
before do before do
......
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