2020-06-23 00:09:42 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Resolvers::ProjectPipelineResolver do
|
2020-06-23 00:09:42 +05:30
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline, project: project, iid: '1234') }
|
|
|
|
let_it_be(:other_pipeline) { create(:ci_pipeline) }
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
specify do
|
|
|
|
expect(described_class).to have_nullable_graphql_type(::Types::Ci::PipelineType)
|
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def resolve_pipeline(project, args)
|
|
|
|
resolve(described_class, obj: project, args: args, ctx: { current_user: current_user })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'resolves pipeline for the passed iid' do
|
|
|
|
result = batch_sync do
|
|
|
|
resolve_pipeline(project, { iid: '1234' })
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to eq(pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'errors when no iid is passed' do
|
|
|
|
expect { resolve_pipeline(project, {}) }.to raise_error(ArgumentError)
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
context 'when the pipeline is a dangling pipeline' do
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:pipeline) do
|
2020-11-24 15:15:51 +05:30
|
|
|
dangling_source = ::Enums::Ci::Pipeline.dangling_sources.each_value.first
|
|
|
|
create(:ci_pipeline, source: dangling_source, project: project)
|
2020-10-24 23:57:45 +05:30
|
|
|
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-23 00:09:42 +05:30
|
|
|
end
|