debian-mirror-gitlab/spec/graphql/resolvers/ci/all_jobs_resolver_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
2.1 KiB
Ruby
Raw Normal View History

2022-11-25 23:54:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::Ci::AllJobsResolver do
include GraphqlHelpers
let_it_be(:successful_job) { create(:ci_build, :success, name: 'Job One') }
let_it_be(:successful_job_two) { create(:ci_build, :success, name: 'Job Two') }
let_it_be(:failed_job) { create(:ci_build, :failed, name: 'Job Three') }
let_it_be(:pending_job) { create(:ci_build, :pending, name: 'Job Three') }
let(:args) { {} }
subject { resolve_jobs(args) }
describe '#resolve' do
2023-03-04 22:38:38 +05:30
context 'with admin' do
let(:current_user) { create(:admin) }
2022-11-25 23:54:43 +05:30
2023-03-04 22:38:38 +05:30
shared_examples 'executes as admin' do
context 'with statuses argument' do
let(:args) { { statuses: [Types::Ci::JobStatusEnum.coerce_isolated_input('SUCCESS')] } }
it { is_expected.to contain_exactly(successful_job, successful_job_two) }
end
context 'with multiple statuses' do
let(:args) do
{ statuses: [Types::Ci::JobStatusEnum.coerce_isolated_input('SUCCESS'),
Types::Ci::JobStatusEnum.coerce_isolated_input('FAILED')] }
end
it { is_expected.to contain_exactly(successful_job, successful_job_two, failed_job) }
end
2022-11-25 23:54:43 +05:30
2023-03-04 22:38:38 +05:30
context 'without statuses argument' do
it { is_expected.to contain_exactly(successful_job, successful_job_two, failed_job, pending_job) }
2022-11-25 23:54:43 +05:30
end
2023-03-04 22:38:38 +05:30
end
2022-11-25 23:54:43 +05:30
2023-03-04 22:38:38 +05:30
context 'when admin mode setting is disabled', :do_not_mock_admin_mode_setting do
it_behaves_like 'executes as admin'
2022-11-25 23:54:43 +05:30
end
2023-03-04 22:38:38 +05:30
context 'when admin mode setting is enabled' do
context 'when in admin mode', :enable_admin_mode do
it_behaves_like 'executes as admin'
end
context 'when not in admin mode' do
it { is_expected.to be_empty }
end
2022-11-25 23:54:43 +05:30
end
end
context 'with unauthorized user' do
let(:current_user) { nil }
it { is_expected.to be_empty }
end
end
private
def resolve_jobs(args = {}, context = { current_user: current_user })
resolve(described_class, args: args, ctx: context)
end
end