2020-06-15 14:08:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-26 05:08:59 -04:00
|
|
|
RSpec.describe Resolvers::ProjectPipelineResolver do
|
2020-06-15 14:08:43 -04:00
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let_it_be(:project) { create(:project) }
|
2021-03-05 01:09:26 -05:00
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline, project: project, iid: '1234', sha: 'sha') }
|
2021-04-12 08:09:15 -04:00
|
|
|
let_it_be(:other_project_pipeline) { create(:ci_pipeline, project: project, iid: '1235', sha: 'sha2') }
|
2020-06-15 14:08:43 -04:00
|
|
|
let_it_be(:other_pipeline) { create(:ci_pipeline) }
|
2021-04-21 17:09:40 -04:00
|
|
|
|
2020-06-15 14:08:43 -04:00
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
specify do
|
|
|
|
expect(described_class).to have_nullable_graphql_type(::Types::Ci::PipelineType)
|
|
|
|
end
|
|
|
|
|
2020-06-15 14:08:43 -04:00
|
|
|
def resolve_pipeline(project, args)
|
|
|
|
resolve(described_class, obj: project, args: args, ctx: { current_user: current_user })
|
|
|
|
end
|
|
|
|
|
2020-11-30 07:09:21 -05:00
|
|
|
before do
|
|
|
|
project.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
2020-06-15 14:08:43 -04:00
|
|
|
it 'resolves pipeline for the passed iid' do
|
2021-04-12 08:09:15 -04:00
|
|
|
expect(Ci::PipelinesFinder)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(project, current_user, iids: ['1234'])
|
|
|
|
.and_call_original
|
|
|
|
|
2020-06-15 14:08:43 -04:00
|
|
|
result = batch_sync do
|
|
|
|
resolve_pipeline(project, { iid: '1234' })
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to eq(pipeline)
|
|
|
|
end
|
|
|
|
|
2021-03-05 01:09:26 -05:00
|
|
|
it 'resolves pipeline for the passed sha' do
|
2021-04-12 08:09:15 -04:00
|
|
|
expect(Ci::PipelinesFinder)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(project, current_user, sha: ['sha'])
|
|
|
|
.and_call_original
|
|
|
|
|
2021-03-05 01:09:26 -05:00
|
|
|
result = batch_sync do
|
|
|
|
resolve_pipeline(project, { sha: 'sha' })
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to eq(pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'keeps the queries under the threshold for iid' do
|
2020-11-30 07:09:21 -05:00
|
|
|
control = ActiveRecord::QueryRecorder.new do
|
|
|
|
batch_sync { resolve_pipeline(project, { iid: '1234' }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
expect do
|
|
|
|
batch_sync do
|
|
|
|
resolve_pipeline(project, { iid: '1234' })
|
|
|
|
resolve_pipeline(project, { iid: '1235' })
|
|
|
|
end
|
|
|
|
end.not_to exceed_query_limit(control)
|
|
|
|
end
|
|
|
|
|
2021-03-05 01:09:26 -05:00
|
|
|
it 'keeps the queries under the threshold for sha' do
|
|
|
|
control = ActiveRecord::QueryRecorder.new do
|
|
|
|
batch_sync { resolve_pipeline(project, { sha: 'sha' }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
expect do
|
|
|
|
batch_sync do
|
|
|
|
resolve_pipeline(project, { sha: 'sha' })
|
|
|
|
resolve_pipeline(project, { sha: 'sha2' })
|
|
|
|
end
|
|
|
|
end.not_to exceed_query_limit(control)
|
|
|
|
end
|
|
|
|
|
2020-06-15 14:08:43 -04:00
|
|
|
it 'does not resolve a pipeline outside the project' do
|
|
|
|
result = batch_sync do
|
|
|
|
resolve_pipeline(other_pipeline.project, { iid: '1234' })
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to be_nil
|
|
|
|
end
|
|
|
|
|
2021-03-05 01:09:26 -05:00
|
|
|
it 'errors when no iid or sha is passed' do
|
|
|
|
expect { resolve_pipeline(project, {}) }
|
|
|
|
.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'errors when both iid and sha are passed' do
|
|
|
|
expect { resolve_pipeline(project, { iid: '1234', sha: 'sha' }) }
|
|
|
|
.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
|
2020-06-15 14:08:43 -04:00
|
|
|
end
|
2020-08-18 05:10:05 -04:00
|
|
|
|
2020-09-07 08:08:27 -04:00
|
|
|
context 'when the pipeline is a dangling pipeline' do
|
2020-08-18 05:10:05 -04:00
|
|
|
let(:pipeline) do
|
2020-09-07 08:08:27 -04:00
|
|
|
dangling_source = ::Enums::Ci::Pipeline.dangling_sources.each_value.first
|
|
|
|
create(:ci_pipeline, source: dangling_source, project: project)
|
2020-08-18 05:10:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'resolves pipeline for the passed iid' do
|
|
|
|
result = batch_sync do
|
|
|
|
resolve_pipeline(project, { iid: pipeline.iid.to_s })
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to eq(pipeline)
|
|
|
|
end
|
|
|
|
end
|
2020-06-15 14:08:43 -04:00
|
|
|
end
|