debian-mirror-gitlab/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb

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

118 lines
4 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe ResolvesPipelines do
2018-11-08 19:23:39 +05:30
include GraphqlHelpers
subject(:resolver) do
Class.new(Resolvers::BaseResolver) do
include ResolvesPipelines
def resolve(**args)
resolve_pipelines(object, args)
end
end
end
2022-05-07 20:08:51 +05:30
let_it_be(:current_user) { create(:user) }
2020-01-01 13:55:28 +05:30
2020-04-08 14:13:33 +05:30
let_it_be(:project) { create(:project, :private) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:failed_pipeline) { create(:ci_pipeline, :failed, project: project) }
2021-12-11 22:18:48 +05:30
let_it_be(:success_pipeline) { create(:ci_pipeline, :success, project: project) }
2020-04-08 14:13:33 +05:30
let_it_be(:ref_pipeline) { create(:ci_pipeline, project: project, ref: 'awesome-feature') }
let_it_be(:sha_pipeline) { create(:ci_pipeline, project: project, sha: 'deadbeef') }
2022-05-07 20:08:51 +05:30
let_it_be(:username_pipeline) { create(:ci_pipeline, project: project, user: current_user) }
2021-12-11 22:18:48 +05:30
let_it_be(:all_pipelines) do
[
pipeline,
failed_pipeline,
success_pipeline,
ref_pipeline,
2022-05-07 20:08:51 +05:30
sha_pipeline,
username_pipeline
2021-12-11 22:18:48 +05:30
]
end
2018-11-08 19:23:39 +05:30
before do
project.add_developer(current_user)
end
2022-05-07 20:08:51 +05:30
it { is_expected.to have_graphql_arguments(:status, :scope, :ref, :sha, :source, :updated_after, :updated_before, :username) }
2018-11-08 19:23:39 +05:30
it 'finds all pipelines' do
2021-12-11 22:18:48 +05:30
expect(resolve_pipelines).to contain_exactly(*all_pipelines)
2018-11-08 19:23:39 +05:30
end
it 'allows filtering by status' do
expect(resolve_pipelines(status: 'failed')).to contain_exactly(failed_pipeline)
end
2021-12-11 22:18:48 +05:30
it 'allows filtering by scope' do
expect(resolve_pipelines(scope: 'finished')).to contain_exactly(failed_pipeline, success_pipeline)
end
2018-11-08 19:23:39 +05:30
it 'allows filtering by ref' do
expect(resolve_pipelines(ref: 'awesome-feature')).to contain_exactly(ref_pipeline)
end
it 'allows filtering by sha' do
expect(resolve_pipelines(sha: 'deadbeef')).to contain_exactly(sha_pipeline)
end
2021-11-11 11:23:49 +05:30
context 'filtering by source' do
let_it_be(:source_pipeline) { create(:ci_pipeline, project: project, source: 'web') }
2022-03-02 08:16:31 +05:30
it 'does filter by source' do
expect(resolve_pipelines(source: 'web')).to contain_exactly(source_pipeline)
2021-11-11 11:23:49 +05:30
end
2022-03-02 08:16:31 +05:30
it 'returns all the pipelines' do
expect(resolve_pipelines).to contain_exactly(*all_pipelines, source_pipeline)
2021-11-11 11:23:49 +05:30
end
end
2022-05-07 20:08:51 +05:30
it 'allows filtering by username' do
expect(resolve_pipelines(username: current_user.username)).to contain_exactly(username_pipeline)
end
context 'filtering by updated_at' do
let_it_be(:old_pipeline) { create(:ci_pipeline, project: project, updated_at: 2.days.ago) }
let_it_be(:older_pipeline) { create(:ci_pipeline, project: project, updated_at: 5.days.ago) }
it 'filters by updated_after' do
expect(resolve_pipelines(updated_after: 3.days.ago)).to contain_exactly(old_pipeline, *all_pipelines)
end
it 'filters by updated_before' do
expect(resolve_pipelines(updated_before: 3.days.ago)).to contain_exactly(older_pipeline)
end
it 'filters by both updated_after and updated_before with valid date range' do
expect(resolve_pipelines(updated_after: 10.days.ago, updated_before: 3.days.ago)).to contain_exactly(older_pipeline)
end
it 'filters by both updated_after and updated_before with invalid date range' do
# updated_after is before updated_before so result set is empty - impossible
expect(resolve_pipelines(updated_after: 3.days.ago, updated_before: 10.days.ago)).to be_empty
end
end
2018-11-08 19:23:39 +05:30
it 'does not return any pipelines if the user does not have access' do
expect(resolve_pipelines({}, {})).to be_empty
end
2019-07-31 22:56:46 +05:30
it 'increases field complexity based on arguments' do
2021-10-27 15:23:28 +05:30
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String, resolver_class: resolver, null: false, max_page_size: 1)
2019-07-31 22:56:46 +05:30
2022-05-07 20:08:51 +05:30
expect(field.complexity.call({}, {}, 1)).to eq 2
expect(field.complexity.call({}, { sha: 'foo' }, 1)).to eq 4
expect(field.complexity.call({}, { sha: 'ref' }, 1)).to eq 4
2019-07-31 22:56:46 +05:30
end
2018-11-08 19:23:39 +05:30
def resolve_pipelines(args = {}, context = { current_user: current_user })
resolve(resolver, obj: project, args: args, ctx: context)
end
end