diff options
author | Marin Jankovski <maxlazio@gmail.com> | 2019-07-03 12:55:56 +0300 |
---|---|---|
committer | Marin Jankovski <maxlazio@gmail.com> | 2019-07-03 12:55:56 +0300 |
commit | c20c9e2940b0f94547246d05b7b526f0b1571027 (patch) | |
tree | c548960a37ab7447ff542e0844e838f973c118fb /spec/lib/gitlab/graphql | |
parent | 49d689fb3c7781c861f995aaafef4b224581020b (diff) | |
parent | 2ca9bda400c0ed647c3ef342dcc0aa56c558cebe (diff) |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
Diffstat (limited to 'spec/lib/gitlab/graphql')
4 files changed, 86 insertions, 1 deletions
diff --git a/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb b/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb index 20842f55014..50138d272c4 100644 --- a/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb +++ b/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb @@ -67,7 +67,7 @@ describe Gitlab::Graphql::Authorize::AuthorizeResource do end describe '#authorize!' do - it 'does not raise an error' do + it 'raises an error' do expect { loading_resource.authorize!(project) }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) end end diff --git a/spec/lib/gitlab/graphql/copy_field_description_spec.rb b/spec/lib/gitlab/graphql/copy_field_description_spec.rb new file mode 100644 index 00000000000..e7462c5b954 --- /dev/null +++ b/spec/lib/gitlab/graphql/copy_field_description_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Graphql::CopyFieldDescription do + subject { Class.new.include(described_class) } + + describe '.copy_field_description' do + let(:type) do + Class.new(Types::BaseObject) do + graphql_name "TestType" + + field :field_name, GraphQL::STRING_TYPE, null: true, description: 'Foo' + end + end + + it 'returns the correct description' do + expect(subject.copy_field_description(type, :field_name)).to eq('Foo') + end + end +end diff --git a/spec/lib/gitlab/graphql/find_argument_in_parent_spec.rb b/spec/lib/gitlab/graphql/find_argument_in_parent_spec.rb new file mode 100644 index 00000000000..91e90315b3e --- /dev/null +++ b/spec/lib/gitlab/graphql/find_argument_in_parent_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Graphql::FindArgumentInParent do + describe '#find' do + def build_node(parent = nil, args: {}) + props = { irep_node: double(arguments: args) } + props[:parent] = parent if parent # The root node shouldn't respond to parent + + double(props) + end + + let(:parent) do + build_node( + build_node( + build_node( + build_node, + args: { myArg: 1 } + ) + ) + ) + end + let(:arg_name) { :my_arg } + + it 'searches parents and returns the argument' do + expect(described_class.find(parent, :my_arg)).to eq(1) + end + + it 'can find argument when passed in as both Ruby and GraphQL-formatted symbols and strings' do + [:my_arg, :myArg, 'my_arg', 'myArg'].each do |arg| + expect(described_class.find(parent, arg)).to eq(1) + end + end + + it 'returns nil if no arguments found in parents' do + expect(described_class.find(parent, :bar)).to eq(nil) + end + + it 'can limit the depth it searches to' do + expect(described_class.find(parent, :my_arg, limit_depth: 1)).to eq(nil) + end + end +end diff --git a/spec/lib/gitlab/graphql/loaders/pipeline_for_sha_loader_spec.rb b/spec/lib/gitlab/graphql/loaders/pipeline_for_sha_loader_spec.rb new file mode 100644 index 00000000000..927476cc655 --- /dev/null +++ b/spec/lib/gitlab/graphql/loaders/pipeline_for_sha_loader_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Gitlab::Graphql::Loaders::PipelineForShaLoader do + include GraphqlHelpers + + describe '#find_last' do + it 'batch-resolves latest pipeline' do + project = create(:project, :repository) + pipeline1 = create(:ci_pipeline, project: project, ref: project.default_branch, sha: project.commit.sha) + pipeline2 = create(:ci_pipeline, project: project, ref: project.default_branch, sha: project.commit.sha) + pipeline3 = create(:ci_pipeline, project: project, ref: 'improve/awesome', sha: project.commit('improve/awesome').sha) + + result = batch(max_queries: 1) do + [pipeline1.sha, pipeline3.sha].map { |sha| described_class.new(project, sha).find_last } + end + + expect(result).to contain_exactly(pipeline2, pipeline3) + end + end +end |