2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-26 04:31:42 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe PipelineDetailsEntity do
|
2020-02-24 22:08:49 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
2017-05-26 04:31:42 -04:00
|
|
|
let(:request) { double('request') }
|
|
|
|
|
2020-09-03 08:08:47 -04:00
|
|
|
let(:entity) do
|
|
|
|
described_class.represent(pipeline, request: request)
|
|
|
|
end
|
|
|
|
|
2017-05-26 04:31:42 -04:00
|
|
|
it 'inherrits from PipelineEntity' do
|
|
|
|
expect(described_class).to be < PipelineEntity
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2017-07-18 10:32:34 -04:00
|
|
|
stub_not_protect_default_branch
|
|
|
|
|
2017-05-26 04:31:42 -04:00
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#as_json' do
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
context 'when pipeline is empty' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline) }
|
|
|
|
|
|
|
|
it 'contains details' do
|
|
|
|
expect(subject).to include :details
|
|
|
|
expect(subject[:details])
|
|
|
|
.to include :duration, :finished_at
|
|
|
|
expect(subject[:details])
|
2018-10-03 02:18:44 -04:00
|
|
|
.to include :stages, :artifacts, :manual_actions, :scheduled_actions
|
2017-05-26 04:31:42 -04:00
|
|
|
expect(subject[:details][:status]).to include :icon, :favicon, :text, :label
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains flags' do
|
|
|
|
expect(subject).to include :flags
|
|
|
|
expect(subject[:flags])
|
2017-06-01 04:56:00 -04:00
|
|
|
.to include :latest, :stuck,
|
2017-05-26 04:31:42 -04:00
|
|
|
:yaml_errors, :retryable, :cancelable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline is retryable' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-05-26 04:31:42 -04:00
|
|
|
|
|
|
|
let(:pipeline) do
|
|
|
|
create(:ci_pipeline, status: :success, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:ci_build, :failed, pipeline: pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user has ability to retry pipeline' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-07-18 10:32:34 -04:00
|
|
|
project.add_developer(user)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2017-05-26 04:31:42 -04:00
|
|
|
|
|
|
|
it 'retryable flag is true' do
|
|
|
|
expect(subject[:flags][:retryable]).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user does not have ability to retry pipeline' do
|
|
|
|
it 'retryable flag is false' do
|
|
|
|
expect(subject[:flags][:retryable]).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline is cancelable' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-05-26 04:31:42 -04:00
|
|
|
|
|
|
|
let(:pipeline) do
|
|
|
|
create(:ci_pipeline, status: :running, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:ci_build, :pending, pipeline: pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user has ability to cancel pipeline' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-07-18 10:32:34 -04:00
|
|
|
project.add_developer(user)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2017-05-26 04:31:42 -04:00
|
|
|
|
|
|
|
it 'cancelable flag is true' do
|
|
|
|
expect(subject[:flags][:cancelable]).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user does not have ability to cancel pipeline' do
|
|
|
|
it 'cancelable flag is false' do
|
|
|
|
expect(subject[:flags][:cancelable]).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-07 06:32:16 -04:00
|
|
|
context 'when pipeline has commit statuses' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline) }
|
2017-07-03 17:58:28 -04:00
|
|
|
|
2017-06-07 06:32:16 -04:00
|
|
|
before do
|
|
|
|
create(:generic_commit_status, pipeline: pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains stages' do
|
|
|
|
expect(subject).to include(:details)
|
|
|
|
expect(subject[:details]).to include(:stages)
|
2017-11-06 16:35:46 -05:00
|
|
|
expect(subject[:details][:stages].first).to include(name: 'test')
|
2017-06-07 06:32:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-26 04:31:42 -04:00
|
|
|
context 'when pipeline has YAML errors' do
|
|
|
|
let(:pipeline) do
|
2019-11-13 07:06:22 -05:00
|
|
|
create(:ci_pipeline, yaml_errors: 'Some error occurred')
|
2017-05-26 04:31:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains information about error' do
|
|
|
|
expect(subject[:yaml_errors]).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains flag that indicates there are errors' do
|
|
|
|
expect(subject[:flags][:yaml_errors]).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline does not have YAML errors' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline) }
|
|
|
|
|
|
|
|
it 'does not contain field that normally holds an error' do
|
|
|
|
expect(subject).not_to have_key(:yaml_errors)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains flag that indicates there are no errors' do
|
|
|
|
expect(subject[:flags][:yaml_errors]).to be false
|
|
|
|
end
|
|
|
|
end
|
2019-10-16 05:07:51 -04:00
|
|
|
|
|
|
|
context 'when pipeline is triggered by other pipeline' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:ci_sources_pipeline, pipeline: pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains an information about depedent pipeline' do
|
|
|
|
expect(subject[:triggered_by]).to be_a(Hash)
|
|
|
|
expect(subject[:triggered_by][:path]).not_to be_nil
|
|
|
|
expect(subject[:triggered_by][:details]).not_to be_nil
|
|
|
|
expect(subject[:triggered_by][:details][:status]).not_to be_nil
|
|
|
|
expect(subject[:triggered_by][:project]).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline triggered other pipeline' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline) }
|
2020-07-10 08:09:15 -04:00
|
|
|
let(:build) { create(:ci_build, name: 'child', stage: 'test', pipeline: pipeline) }
|
|
|
|
let(:bridge) { create(:ci_bridge, name: 'cross-project', stage: 'build', pipeline: pipeline) }
|
|
|
|
let(:child_pipeline) { create(:ci_pipeline, project: pipeline.project) }
|
|
|
|
let(:cross_project_pipeline) { create(:ci_pipeline) }
|
2019-10-16 05:07:51 -04:00
|
|
|
|
|
|
|
before do
|
2020-07-10 08:09:15 -04:00
|
|
|
create(:ci_sources_pipeline, source_job: build, pipeline: child_pipeline)
|
|
|
|
create(:ci_sources_pipeline, source_job: bridge, pipeline: cross_project_pipeline)
|
2019-10-16 05:07:51 -04:00
|
|
|
end
|
|
|
|
|
2020-07-10 08:09:15 -04:00
|
|
|
it 'contains an information about dependent pipeline', :aggregate_failures do
|
2019-10-16 05:07:51 -04:00
|
|
|
expect(subject[:triggered]).to be_a(Array)
|
|
|
|
expect(subject[:triggered].length).to eq(2)
|
|
|
|
expect(subject[:triggered].first[:path]).not_to be_nil
|
|
|
|
expect(subject[:triggered].first[:details]).not_to be_nil
|
|
|
|
expect(subject[:triggered].first[:details][:status]).not_to be_nil
|
|
|
|
expect(subject[:triggered].first[:project]).not_to be_nil
|
2020-07-10 08:09:15 -04:00
|
|
|
|
|
|
|
source_jobs = subject[:triggered]
|
|
|
|
.index_by { |pipeline| pipeline[:id] }
|
|
|
|
.transform_values { |pipeline| pipeline.fetch(:source_job) }
|
|
|
|
|
|
|
|
expect(source_jobs[cross_project_pipeline.id][:name]).to eq('cross-project')
|
|
|
|
expect(source_jobs[child_pipeline.id][:name]).to eq('child')
|
2019-10-16 05:07:51 -04:00
|
|
|
end
|
|
|
|
end
|
2020-12-20 19:10:18 -05:00
|
|
|
|
|
|
|
context 'when a pipeline belongs to a public project' do
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline, status: :success, project: project) }
|
|
|
|
|
|
|
|
context 'that has artifacts' do
|
|
|
|
let!(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
|
|
|
|
|
|
|
|
it 'contains information about artifacts' do
|
|
|
|
expect(subject[:details][:artifacts].length).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'that has non public artifacts' do
|
|
|
|
let!(:build) { create(:ci_build, :success, :artifacts, :non_public_artifacts, pipeline: pipeline) }
|
|
|
|
|
|
|
|
it 'does not contain information about artifacts' do
|
|
|
|
expect(subject[:details][:artifacts].length).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-26 04:31:42 -04:00
|
|
|
end
|
|
|
|
end
|