Commit b3ad2f45 authored by Tetiana Chupryna's avatar Tetiana Chupryna Committed by Nick Thomas

Add dependency factory

Represent a dependency parsed from report
parent af59919b
# 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
set(:project) { create(:project, :repository, :private) }
set(:user) { create(:user) }
let(:request) { double('request') }
let(:dependency) { dependency_info.merge(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
let(:dependency) { build(:dependency, :with_vulnerabilities) }
before do
stub_licensed_features(security_dashboard: true)
......@@ -54,6 +28,8 @@ describe DependencyEntity do
end
context 'with reporter' do
let(:dependency_info) { build(:dependency) }
before do
project.add_reporter(user)
end
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
describe DependencyListEntity do
describe '#as_json' do
let(:entity) do
described_class.represent(dependencies, build: build, request: request)
described_class.represent(dependencies, build: ci_build, request: request)
end
let(:request) { double('request') }
......@@ -22,23 +22,13 @@ describe DependencyListEntity do
context 'with success build' do
let(:user) { developer }
let(:build) { create(:ee_ci_build, :success) }
let(:ci_build) { create(:ee_ci_build, :success) }
context 'with provided dependencies' do
let(:dependencies) do
[{
name: 'nokogiri',
packager: 'Ruby (Bundler)',
version: '1.8.0',
location: {
blob_path: '/some_project/path/Gemfile.lock',
path: 'Gemfile.lock'
}
}]
end
let(:dependencies) { [build(:dependency)] }
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[:report][:status]).to eq(:ok)
......@@ -51,7 +41,7 @@ describe DependencyListEntity do
let(:dependencies) { [] }
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[:report][:status]).to eq(:no_dependencies)
......@@ -61,7 +51,7 @@ describe DependencyListEntity do
end
context 'with failed build' do
let(:build) { create(:ee_ci_build, :failed) }
let(:ci_build) { create(:ee_ci_build, :failed) }
let(:dependencies) { [] }
context 'with authorized user' do
......@@ -85,7 +75,7 @@ describe DependencyListEntity do
context 'with no build' do
let(:user) { developer }
let(:build) { nil }
let(:ci_build) { nil }
let(:dependencies) { [] }
it 'has status job_not_set_up and no job_path' do
......
......@@ -3,29 +3,13 @@
require 'spec_helper'
describe DependencyListSerializer do
let(:build) { create(:ee_ci_build, :success) }
set(:project) { create(:project, :repository, :private) }
set(:user) { create(:user) }
let(:ci_build) { create(:ee_ci_build, :success) }
let(:dependencies) { [build(:dependency, :with_vulnerabilities)] }
let(:serializer) do
described_class.new(project: project, user: user).represent(dependencies, build: 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'
}]
}]
described_class.new(project: project, user: user).represent(dependencies, build: ci_build)
end
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