debian-mirror-gitlab/spec/finders/ci/jobs_finder_spec.rb

172 lines
4.1 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Ci::JobsFinder, '#execute' do
2020-03-13 15:44:24 +05:30
let_it_be(:user) { create(:user) }
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) }
2020-01-01 13:55:28 +05:30
let(:params) { {} }
context 'no project' 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])
end
context 'non admin user' do
let(:admin) { user }
it 'returns no jobs' do
expect(subject).to be_empty
end
end
context 'without user' do
let(:admin) { nil }
it 'returns no jobs' do
expect(subject).to be_empty
end
end
2020-11-24 15:15:51 +05:30
context 'with ci_jobs_finder_refactor ff enabled' do
before do
stub_feature_flags(ci_jobs_finder_refactor: true)
2020-01-01 13:55:28 +05:30
end
2020-11-24 15:15:51 +05:30
context 'scope is present' do
let(:jobs) { [job_1, job_2, job_3] }
where(:scope, :index) do
[
['pending', 0],
['running', 1],
['finished', 2]
]
end
with_them do
let(:params) { { scope: scope } }
2020-01-01 13:55:28 +05:30
2020-11-24 15:15:51 +05:30
it { expect(subject).to match_array([jobs[index]]) }
end
2020-01-01 13:55:28 +05:30
end
2020-11-24 15:15:51 +05:30
context 'scope is an array' do
let(:jobs) { [job_1, job_2, job_3] }
let(:params) {{ scope: ['running'] }}
2020-01-01 13:55:28 +05:30
2020-11-24 15:15:51 +05:30
it 'filters by the job statuses in the scope' do
expect(subject).to match_array([job_2])
end
end
end
context 'with ci_jobs_finder_refactor ff disabled' do
2020-01-01 13:55:28 +05:30
before do
2020-11-24 15:15:51 +05:30
stub_feature_flags(ci_jobs_finder_refactor: false)
2020-01-01 13:55:28 +05:30
end
2020-11-24 15:15:51 +05:30
context 'scope is present' do
let(:jobs) { [job_1, job_2, job_3] }
where(:scope, :index) do
[
['pending', 0],
['running', 1],
['finished', 2]
]
end
with_them do
let(:params) { { scope: scope } }
it { expect(subject).to match_array([jobs[index]]) }
end
2020-01-01 13:55:28 +05:30
end
end
2020-11-24 15:15:51 +05:30
end
2020-01-01 13:55:28 +05:30
2020-11-24 15:15:51 +05:30
context 'with ci_jobs_finder_refactor ff enabled' do
before do
stub_feature_flags(ci_jobs_finder_refactor: true)
end
context 'a project is present' do
subject { described_class.new(current_user: user, project: project, params: params).execute }
context 'user has access to the project' do
before do
project.add_maintainer(user)
end
it 'returns jobs for the specified project' do
expect(subject).to match_array([job_3])
end
2020-01-01 13:55:28 +05:30
end
2020-11-24 15:15:51 +05:30
context 'user has no access to project builds' do
before do
project.add_guest(user)
end
it 'returns no jobs' do
expect(subject).to be_empty
end
end
context 'without user' do
let(:user) { nil }
it 'returns no jobs' do
expect(subject).to be_empty
end
2020-01-01 13:55:28 +05:30
end
end
2020-11-24 15:15:51 +05:30
end
2020-01-01 13:55:28 +05:30
2020-11-24 15:15:51 +05:30
context 'with ci_jobs_finder_refactor ff disabled' do
before do
stub_feature_flags(ci_jobs_finder_refactor: false)
end
context 'a project is present' do
subject { described_class.new(current_user: user, project: project, params: params).execute }
2020-01-01 13:55:28 +05:30
2020-11-24 15:15:51 +05:30
context 'user has access to the project' do
before do
project.add_maintainer(user)
end
it 'returns jobs for the specified project' do
expect(subject).to match_array([job_3])
end
end
context 'user has no access to project builds' do
before do
project.add_guest(user)
end
it 'returns no jobs' do
expect(subject).to be_empty
end
end
context 'without user' do
let(:user) { nil }
it 'returns no jobs' do
expect(subject).to be_empty
end
2020-01-01 13:55:28 +05:30
end
end
end
end