Commit 2d9261c4 authored by Allison Browne's avatar Allison Browne Committed by Stan Hu

Add specs for filtering by multiple statuses

Add specs that ensure that the filtering works properly
when filtering against multiple statuses
parent c3279091
......@@ -76,7 +76,7 @@ module Ci
unknown_statuses = params[:scope] - ::CommitStatus::AVAILABLE_STATUSES
raise ArgumentError, 'Scope contains invalid value(s)' unless unknown_statuses.empty?
builds.where(status: params[:scope]) # rubocop: disable CodeReuse/ActiveRecord
builds.with_statuses(params[:scope])
end
def jobs_by_type(relation, type)
......
......@@ -7,9 +7,9 @@ RSpec.describe Ci::JobsFinder, '#execute' do
let_it_be(:admin) { create(:user, :admin) }
let_it_be(:project) { create(:project, :private, public_builds: false) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:job_1) { create(:ci_build) }
let_it_be(:job_2) { create(:ci_build, :running) }
let_it_be(:job_3) { create(:ci_build, :success, pipeline: pipeline, name: 'build') }
let_it_be(:pending_job) { create(:ci_build, :pending) }
let_it_be(:running_job) { create(:ci_build, :running) }
let_it_be(:successful_job) { create(:ci_build, :success, pipeline: pipeline, name: 'build') }
let(:params) { {} }
......@@ -17,7 +17,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
subject { described_class.new(current_user: admin, params: params).execute }
it 'returns all jobs' do
expect(subject).to match_array([job_1, job_2, job_3])
expect(subject).to match_array([pending_job, running_job, successful_job])
end
context 'non admin user' do
......@@ -37,7 +37,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end
context 'scope is present' do
let(:jobs) { [job_1, job_2, job_3] }
let(:jobs) { [pending_job, running_job, successful_job] }
where(:scope, :index) do
[
......@@ -55,11 +55,11 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end
context 'scope is an array' do
let(:jobs) { [job_1, job_2, job_3] }
let(:params) {{ scope: ['running'] }}
let(:jobs) { [pending_job, running_job, successful_job, canceled_job] }
let(:params) {{ scope: %w'running success' }}
it 'filters by the job statuses in the scope' do
expect(subject).to match_array([job_2])
expect(subject).to contain_exactly(running_job, successful_job)
end
end
end
......@@ -73,7 +73,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end
it 'returns jobs for the specified project' do
expect(subject).to match_array([job_3])
expect(subject).to match_array([successful_job])
end
end
......@@ -99,7 +99,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
context 'when pipeline is present' do
before_all do
project.add_maintainer(user)
job_3.update!(retried: true)
successful_job.update!(retried: true)
end
let_it_be(:job_4) { create(:ci_build, :success, pipeline: pipeline, name: 'build') }
......@@ -122,7 +122,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
let(:params) { { include_retried: true } }
it 'returns retried jobs' do
expect(subject).to match_array([job_3, job_4])
expect(subject).to match_array([successful_job, job_4])
end
end
end
......
......@@ -9,9 +9,10 @@ RSpec.describe Resolvers::ProjectJobsResolver do
let_it_be(:irrelevant_project) { create(:project, :repository) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:irrelevant_pipeline) { create(:ci_pipeline, project: irrelevant_project) }
let_it_be(:build_one) { create(:ci_build, :success, name: 'Build One', pipeline: pipeline) }
let_it_be(:build_two) { create(:ci_build, :success, name: 'Build Two', pipeline: pipeline) }
let_it_be(:build_three) { create(:ci_build, :failed, name: 'Build Three', pipeline: pipeline) }
let_it_be(:successful_build) { create(:ci_build, :success, name: 'Build One', pipeline: pipeline) }
let_it_be(:successful_build_two) { create(:ci_build, :success, name: 'Build Two', pipeline: pipeline) }
let_it_be(:failed_build) { create(:ci_build, :failed, name: 'Build Three', pipeline: pipeline) }
let_it_be(:pending_build) { create(:ci_build, :pending, name: 'Build Three', pipeline: pipeline) }
let(:irrelevant_build) { create(:ci_build, name: 'Irrelevant Build', pipeline: irrelevant_pipeline)}
let(:args) { {} }
......@@ -28,11 +29,17 @@ RSpec.describe Resolvers::ProjectJobsResolver do
context 'with statuses argument' do
let(:args) { { statuses: [Types::Ci::JobStatusEnum.coerce_isolated_input('SUCCESS')] } }
it { is_expected.to contain_exactly(build_one, build_two) }
it { is_expected.to contain_exactly(successful_build, successful_build_two) }
end
context 'with multiple statuses' do
let(:args) { { statuses: [Types::Ci::JobStatusEnum.coerce_isolated_input('SUCCESS'), Types::Ci::JobStatusEnum.coerce_isolated_input('FAILED')] } }
it { is_expected.to contain_exactly(successful_build, successful_build_two, failed_build) }
end
context 'without statuses argument' do
it { is_expected.to contain_exactly(build_one, build_two, build_three) }
it { is_expected.to contain_exactly(successful_build, successful_build_two, failed_build, pending_build) }
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