Commit dc2fcfe6 authored by Matija Čupić's avatar Matija Čupić

Add upstream/downstream pipeline specs

parent 4f37462f
......@@ -46,6 +46,10 @@ class DashboardOperationsProjectEntity < Grape::Entity
)
end
def last_pipeline
dashboard_project.project.commit&.last_pipeline
end
def upstream_pipeline
last_pipeline&.source_pipeline&.source_pipeline
end
......@@ -54,10 +58,6 @@ class DashboardOperationsProjectEntity < Grape::Entity
last_pipeline&.sourced_pipelines&.map(&:source_pipeline)
end
def last_pipeline
dashboard_project.project.commit&.last_pipeline
end
def last_deployment?
dashboard_project.last_deployment
end
......
......@@ -14,4 +14,70 @@ describe DashboardOperationsProjectEntity do
expect(subject).to include(:remove_path, :alert_count)
expect(subject.first).to include(:id)
end
it 'does not have optional fields' do
expect(subject).not_to include(:last_pipeline, :upstream_pipeline, :downstream_pipelines)
end
context 'when there is a pipeline' do
let!(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit.sha) }
it 'has the last pipeline field' do
expect(subject).to include(:last_pipeline)
end
context 'when there is an upstream status' do
let(:bridge) { create(:ci_bridge, status: :pending) }
before do
create(:ci_sources_pipeline, pipeline: pipeline, source_job: bridge)
end
it 'has the upstream pipeline field' do
expect(subject).to include(:upstream_pipeline)
end
end
context 'when there is a downstream status' do
let(:build) { create(:ci_build, pipeline: pipeline) }
before do
create(:ci_sources_pipeline, source_job: build)
end
it 'has the downstream pipeline field' do
expect(subject).to include(:downstream_pipelines)
end
context 'when there are multiple downstream statuses' do
before do
create_list(:ci_sources_pipeline, 5, source_job: build)
end
it 'has the downstream pipeline field' do
expect(subject).to include(:downstream_pipelines)
expect(subject[:downstream_pipelines].count).to eq(6)
end
end
end
context 'when there are both an upstream and downstream pipelines' do
let(:build) { create(:ci_build, pipeline: pipeline) }
let(:bridge) { create(:ci_bridge, status: :pending) }
before do
create(:ci_sources_pipeline, pipeline: pipeline, source_job: bridge)
create_list(:ci_sources_pipeline, 5, source_job: build)
end
it 'has the upstream pipeline field' do
expect(subject).to include(:upstream_pipeline)
end
it 'has the downstream pipeline field' do
expect(subject).to include(:downstream_pipelines)
expect(subject[:downstream_pipelines].count).to eq(5)
end
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