Commit 4ea62832 authored by Stan Hu's avatar Stan Hu

Merge branch 'add-specs-for-filtering-by-multiple-statuses' into 'master'

Add specs for filtering by multiple statuses

See merge request gitlab-org/gitlab!83132
parents cc45d8e1 2d9261c4
...@@ -76,7 +76,7 @@ module Ci ...@@ -76,7 +76,7 @@ module Ci
unknown_statuses = params[:scope] - ::CommitStatus::AVAILABLE_STATUSES unknown_statuses = params[:scope] - ::CommitStatus::AVAILABLE_STATUSES
raise ArgumentError, 'Scope contains invalid value(s)' unless unknown_statuses.empty? 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 end
def jobs_by_type(relation, type) def jobs_by_type(relation, type)
......
...@@ -7,9 +7,9 @@ RSpec.describe Ci::JobsFinder, '#execute' do ...@@ -7,9 +7,9 @@ RSpec.describe Ci::JobsFinder, '#execute' do
let_it_be(:admin) { create(:user, :admin) } let_it_be(:admin) { create(:user, :admin) }
let_it_be(:project) { create(:project, :private, public_builds: false) } let_it_be(:project) { create(:project, :private, public_builds: false) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:job_1) { create(:ci_build) } let_it_be(:pending_job) { create(:ci_build, :pending) }
let_it_be(:job_2) { create(:ci_build, :running) } let_it_be(:running_job) { create(:ci_build, :running) }
let_it_be(:job_3) { create(:ci_build, :success, pipeline: pipeline, name: 'build') } let_it_be(:successful_job) { create(:ci_build, :success, pipeline: pipeline, name: 'build') }
let(:params) { {} } let(:params) { {} }
...@@ -17,7 +17,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do ...@@ -17,7 +17,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
subject { described_class.new(current_user: admin, params: params).execute } subject { described_class.new(current_user: admin, params: params).execute }
it 'returns all jobs' do 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 end
context 'non admin user' do context 'non admin user' do
...@@ -37,7 +37,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do ...@@ -37,7 +37,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end end
context 'scope is present' do 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 where(:scope, :index) do
[ [
...@@ -55,11 +55,11 @@ RSpec.describe Ci::JobsFinder, '#execute' do ...@@ -55,11 +55,11 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end end
context 'scope is an array' do context 'scope is an array' do
let(:jobs) { [job_1, job_2, job_3] } let(:jobs) { [pending_job, running_job, successful_job, canceled_job] }
let(:params) {{ scope: ['running'] }} let(:params) {{ scope: %w'running success' }}
it 'filters by the job statuses in the scope' do 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 end
end end
...@@ -73,7 +73,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do ...@@ -73,7 +73,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
end end
it 'returns jobs for the specified project' do it 'returns jobs for the specified project' do
expect(subject).to match_array([job_3]) expect(subject).to match_array([successful_job])
end end
end end
...@@ -99,7 +99,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do ...@@ -99,7 +99,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
context 'when pipeline is present' do context 'when pipeline is present' do
before_all do before_all do
project.add_maintainer(user) project.add_maintainer(user)
job_3.update!(retried: true) successful_job.update!(retried: true)
end end
let_it_be(:job_4) { create(:ci_build, :success, pipeline: pipeline, name: 'build') } let_it_be(:job_4) { create(:ci_build, :success, pipeline: pipeline, name: 'build') }
...@@ -122,7 +122,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do ...@@ -122,7 +122,7 @@ RSpec.describe Ci::JobsFinder, '#execute' do
let(:params) { { include_retried: true } } let(:params) { { include_retried: true } }
it 'returns retried jobs' do 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 end
end end
......
...@@ -9,9 +9,10 @@ RSpec.describe Resolvers::ProjectJobsResolver do ...@@ -9,9 +9,10 @@ RSpec.describe Resolvers::ProjectJobsResolver do
let_it_be(:irrelevant_project) { create(:project, :repository) } let_it_be(:irrelevant_project) { create(:project, :repository) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:irrelevant_pipeline) { create(:ci_pipeline, project: irrelevant_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(:successful_build) { 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(:successful_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(: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(:irrelevant_build) { create(:ci_build, name: 'Irrelevant Build', pipeline: irrelevant_pipeline)}
let(:args) { {} } let(:args) { {} }
...@@ -28,11 +29,17 @@ RSpec.describe Resolvers::ProjectJobsResolver do ...@@ -28,11 +29,17 @@ RSpec.describe Resolvers::ProjectJobsResolver do
context 'with statuses argument' do context 'with statuses argument' do
let(:args) { { statuses: [Types::Ci::JobStatusEnum.coerce_isolated_input('SUCCESS')] } } 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 end
context 'without statuses argument' do 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
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