gitlab-org--gitlab-foss/spec/finders/pipelines_finder_spec.rb

236 lines
7.9 KiB
Ruby
Raw Normal View History

2016-08-29 16:02:08 +00:00
require 'spec_helper'
describe PipelinesFinder do
2017-02-28 17:34:48 +00:00
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
2016-08-29 16:02:08 +00:00
let!(:tag_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 10.minutes.ago, ref: 'v1.0.0') }
let!(:created_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 9.minutes.ago, status: 'created') }
let!(:pending_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 8.minutes.ago, status: 'pending') }
let!(:running_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 7.minutes.ago, status: 'running') }
let!(:success_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 6.minutes.ago, status: 'success') }
let!(:failed_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 5.minutes.ago, status: 'failed') }
let!(:canceled_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 2.minutes.ago, status: 'canceled') }
let!(:skipped_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 1.minute.ago, status: 'skipped') }
2017-02-28 17:34:48 +00:00
let!(:yaml_errors_pipeline) { create(:ci_pipeline, project: project, user: user, yaml_errors: 'Syntax error') }
2016-08-29 16:02:08 +00:00
2017-02-28 17:34:48 +00:00
subject { described_class.new(project, params).execute }
2016-08-29 16:02:08 +00:00
describe "#execute" do
2017-02-28 17:34:48 +00:00
context 'when nothing is passed' do
let(:params) { {} }
it 'selects all pipelines' do
expect(subject.count).to be 9
expect(subject).to include tag_pipeline
expect(subject).to include created_pipeline
expect(subject).to include pending_pipeline
expect(subject).to include running_pipeline
expect(subject).to include success_pipeline
expect(subject).to include failed_pipeline
expect(subject).to include canceled_pipeline
expect(subject).to include skipped_pipeline
expect(subject).to include yaml_errors_pipeline
end
it 'orders in descending order on ID' do
expected_ids = [tag_pipeline.id,
created_pipeline.id,
pending_pipeline.id,
running_pipeline.id,
success_pipeline.id,
failed_pipeline.id,
canceled_pipeline.id,
skipped_pipeline.id,
yaml_errors_pipeline.id].sort.reverse
2017-02-28 17:34:48 +00:00
expect(subject.map(&:id)).to eq expected_ids
end
end
2016-08-29 16:02:08 +00:00
context 'when a scope is passed' do
2017-02-28 17:34:48 +00:00
context 'when selecting running' do
let(:params) { { scope: 'running' } }
it 'has only running status' do
expect(subject.map(&:status)).to include('running')
end
end
context 'when selecting pending' do
let(:params) { { scope: 'pending' } }
it 'has only pending status' do
expect(subject.map(&:status)).to include('pending')
end
end
context 'when selecting finished' do
let(:params) { { scope: 'finished' } }
2016-08-29 16:02:08 +00:00
2017-02-28 17:34:48 +00:00
it 'has only finished status' do
expect(subject.map(&:status)).to match_array %w(success canceled failed)
2016-08-29 16:02:08 +00:00
end
end
context 'when selecting branches' do
let(:params) { { scope: 'branches' } }
it 'excludes tags' do
2017-02-28 17:34:48 +00:00
expect(subject.count).to be 1
2016-08-29 16:02:08 +00:00
expect(subject).not_to include tag_pipeline
2017-02-28 17:34:48 +00:00
expect(subject.map(&:ref)).to include('master')
2016-08-29 16:02:08 +00:00
end
end
context 'when selecting tags' do
let(:params) { { scope: 'tags' } }
it 'excludes branches' do
2017-02-28 17:34:48 +00:00
expect(subject.count).to be 1
2016-08-29 16:02:08 +00:00
expect(subject).to include tag_pipeline
2017-02-28 17:34:48 +00:00
expect(subject.map(&:ref)).not_to include('master')
2016-08-29 16:02:08 +00:00
end
end
end
2017-02-28 17:34:48 +00:00
context 'when a status is passed' do
context 'when selecting running' do
let(:params) { { scope: 'running' } }
it 'has only running status' do
expect(subject.map(&:status)).to include('running')
end
end
context 'when selecting pending' do
let(:params) { { scope: 'pending' } }
it 'has only pending status' do
expect(subject.map(&:status)).to include('pending')
end
end
context 'when selecting success' do
let(:params) { { scope: 'success' } }
it 'has only success status' do
expect(subject.map(&:status)).to include('success')
end
end
context 'when selecting failed' do
let(:params) { { scope: 'failed' } }
it 'has only failed status' do
expect(subject.map(&:status)).to include('failed')
end
end
context 'when selecting canceled' do
let(:params) { { scope: 'canceled' } }
2016-08-29 16:02:08 +00:00
2017-02-28 17:34:48 +00:00
it 'has only canceled status' do
expect(subject.map(&:status)).to include('canceled')
end
end
2016-08-29 16:02:08 +00:00
2017-02-28 17:34:48 +00:00
context 'when selecting skipped' do
let(:params) { { scope: 'skipped' } }
it 'has only skipped status' do
expect(subject.map(&:status)).to include('skipped')
end
end
end
context 'when a ref is passed' do
context 'when a ref exists' do
let(:params) { { ref: 'master' } }
it 'selects all pipelines which belong to the ref' do
expect(subject.count).to be 8
expect(subject).to include created_pipeline
expect(subject).to include pending_pipeline
expect(subject).to include running_pipeline
expect(subject).to include success_pipeline
expect(subject).to include failed_pipeline
expect(subject).to include canceled_pipeline
expect(subject).to include skipped_pipeline
expect(subject).to include yaml_errors_pipeline
end
end
context 'when a ref does not exist' do
let(:params) { { ref: 'unique-ref' } }
it 'selects nothing' do
expect(subject).to be_empty
end
end
end
context 'when a username is passed' do
context 'when a username exists' do
let(:params) { { username: user.name } }
it 'selects all pipelines which belong to the username' do
expect(subject).to include success_pipeline
expect(subject).to include failed_pipeline
end
end
context 'when a username does not exist' do
let(:params) { { username: 'unique-username' } }
it 'selects nothing' do
expect(subject).to be_empty
end
end
end
context 'when a yaml_errors is passed' do
context 'when yaml_errors is true' do
let(:params) { { yaml_errors: true } }
it 'selects only pipelines has yaml_errors' do
expect(subject).to include yaml_errors_pipeline
end
end
context 'when yaml_errors is false' do
let(:params) { { yaml_errors: false } }
it 'selects only pipelines does not have yaml_errors' do
expect(subject).to include created_pipeline
expect(subject).to include pending_pipeline
expect(subject).to include running_pipeline
expect(subject).to include success_pipeline
expect(subject).to include failed_pipeline
expect(subject).to include canceled_pipeline
expect(subject).to include skipped_pipeline
end
end
end
context 'when a order_by and sort are passed' do
context 'when order by created_at asc' do
2017-02-28 17:34:48 +00:00
let(:params) { { order_by: 'created_at', sort: 'asc' } }
it 'sorts by created_at asc' do
expect(subject.first).to eq(tag_pipeline)
expect(subject.last).to eq(yaml_errors_pipeline)
end
end
context 'when order by created_at desc' do
let(:params) { { order_by: 'created_at', sort: 'desc' } }
it 'sorts by created_at desc' do
expect(subject.first).to eq(yaml_errors_pipeline)
expect(subject.last).to eq(tag_pipeline)
2017-02-28 17:34:48 +00:00
end
end
2016-08-29 16:02:08 +00:00
end
end
end