2016-12-21 13:26:47 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PipelineEntity do
|
2017-05-26 08:31:42 +00:00
|
|
|
set(:user) { create(:user) }
|
2016-12-21 13:26:47 +00:00
|
|
|
let(:request) { double('request') }
|
|
|
|
|
|
|
|
before do
|
2017-07-18 14:32:34 +00:00
|
|
|
stub_not_protect_default_branch
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
2016-12-21 13:26:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:entity) do
|
|
|
|
described_class.represent(pipeline, request: request)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#as_json' do
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
context 'when pipeline is empty' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline) }
|
|
|
|
|
|
|
|
it 'contains required fields' do
|
2017-05-24 13:13:51 +00:00
|
|
|
expect(subject).to include :id, :user, :path, :coverage, :source
|
2016-12-21 13:26:47 +00:00
|
|
|
expect(subject).to include :ref, :commit
|
|
|
|
expect(subject).to include :updated_at, :created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains details' do
|
|
|
|
expect(subject).to include :details
|
|
|
|
expect(subject[:details])
|
|
|
|
.to include :duration, :finished_at
|
2018-04-05 21:04:42 +00:00
|
|
|
expect(subject[:details][:status]).to include :icon, :favicon, :text, :label, :tooltip
|
2016-12-21 13:26:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains flags' do
|
|
|
|
expect(subject).to include :flags
|
|
|
|
expect(subject[:flags])
|
2017-08-31 11:47:29 +00:00
|
|
|
.to include :latest, :stuck, :auto_devops,
|
2016-12-21 13:26:47 +00:00
|
|
|
:yaml_errors, :retryable, :cancelable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline is retryable' do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2016-12-21 13:26:47 +00: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 18:18:56 +00:00
|
|
|
before do
|
2017-07-18 14:32:34 +00:00
|
|
|
project.add_developer(user)
|
2017-06-14 18:18:56 +00:00
|
|
|
end
|
2016-12-21 13:26:47 +00:00
|
|
|
|
|
|
|
it 'contains retry path' do
|
|
|
|
expect(subject[:retry_path]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user does not have ability to retry pipeline' do
|
|
|
|
it 'does not contain retry path' do
|
|
|
|
expect(subject).not_to have_key(:retry_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline is cancelable' do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2016-12-21 13:26:47 +00: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 18:18:56 +00:00
|
|
|
before do
|
2017-07-18 14:32:34 +00:00
|
|
|
project.add_developer(user)
|
2017-06-14 18:18:56 +00:00
|
|
|
end
|
2016-12-21 13:26:47 +00:00
|
|
|
|
|
|
|
it 'contains cancel path' do
|
|
|
|
expect(subject[:cancel_path]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user does not have ability to cancel pipeline' do
|
|
|
|
it 'does not contain cancel path' do
|
|
|
|
expect(subject).not_to have_key(:cancel_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-20 11:44:31 +00:00
|
|
|
context 'when pipeline ref is empty' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(pipeline).to receive(:ref).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not generate branch path' do
|
|
|
|
expect(subject[:ref][:path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2017-10-03 11:18:59 +00:00
|
|
|
|
|
|
|
context 'when pipeline has a failure reason set' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
pipeline.drop!(:config_error)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a correct failure reason' do
|
|
|
|
expect(subject[:failure_reason])
|
|
|
|
.to eq 'CI/CD YAML configuration error!'
|
|
|
|
end
|
|
|
|
end
|
2016-12-21 13:26:47 +00:00
|
|
|
end
|
|
|
|
end
|