Welcome to mirror list, hosted at ThFree Co, Russian Federation.

all_jobs_resolver_spec.rb « ci « resolvers « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2a7d0a8171b292c8bcface0af65270d4795acf8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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) { {} }
  let(:current_user) { create(:admin) }

  subject { resolve_jobs(args) }

  describe '#resolve' do
    context 'with authorized user' 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

      context 'without statuses argument' do
        it { is_expected.to contain_exactly(successful_job, successful_job_two, failed_job, pending_job) }
      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