diff options
Diffstat (limited to 'spec/lib/gitlab/graphql')
26 files changed, 201 insertions, 24 deletions
diff --git a/spec/lib/gitlab/graphql/authorize/authorize_field_service_spec.rb b/spec/lib/gitlab/graphql/authorize/authorize_field_service_spec.rb index c1dab5feb91..efe6c27c463 100644 --- a/spec/lib/gitlab/graphql/authorize/authorize_field_service_spec.rb +++ b/spec/lib/gitlab/graphql/authorize/authorize_field_service_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' # Also see spec/graphql/features/authorization_spec.rb for # integration tests of AuthorizeFieldService -describe Gitlab::Graphql::Authorize::AuthorizeFieldService do +RSpec.describe Gitlab::Graphql::Authorize::AuthorizeFieldService do def type(type_authorizations = []) Class.new(Types::BaseObject) do graphql_name 'TestType' diff --git a/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb b/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb index 67cb064b966..83873081a98 100644 --- a/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb +++ b/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Authorize::AuthorizeResource do +RSpec.describe Gitlab::Graphql::Authorize::AuthorizeResource do let(:fake_class) do Class.new do include Gitlab::Graphql::Authorize::AuthorizeResource diff --git a/spec/lib/gitlab/graphql/calls_gitaly/instrumentation_spec.rb b/spec/lib/gitlab/graphql/calls_gitaly/instrumentation_spec.rb index d93ce464a92..f16767f7d14 100644 --- a/spec/lib/gitlab/graphql/calls_gitaly/instrumentation_spec.rb +++ b/spec/lib/gitlab/graphql/calls_gitaly/instrumentation_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Gitlab::Graphql::CallsGitaly::Instrumentation do +RSpec.describe Gitlab::Graphql::CallsGitaly::Instrumentation do subject { described_class.new } describe '#calls_gitaly_check' do diff --git a/spec/lib/gitlab/graphql/copy_field_description_spec.rb b/spec/lib/gitlab/graphql/copy_field_description_spec.rb index e7462c5b954..310b4046b56 100644 --- a/spec/lib/gitlab/graphql/copy_field_description_spec.rb +++ b/spec/lib/gitlab/graphql/copy_field_description_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::CopyFieldDescription do +RSpec.describe Gitlab::Graphql::CopyFieldDescription do subject { Class.new.include(described_class) } describe '.copy_field_description' do diff --git a/spec/lib/gitlab/graphql/docs/renderer_spec.rb b/spec/lib/gitlab/graphql/docs/renderer_spec.rb index 87079a1786c..81ef7fcda97 100644 --- a/spec/lib/gitlab/graphql/docs/renderer_spec.rb +++ b/spec/lib/gitlab/graphql/docs/renderer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Docs::Renderer do +RSpec.describe Gitlab::Graphql::Docs::Renderer do describe '#contents' do # Returns a Schema that uses the given `type` def mock_schema(type) diff --git a/spec/lib/gitlab/graphql/find_argument_in_parent_spec.rb b/spec/lib/gitlab/graphql/find_argument_in_parent_spec.rb index 91e90315b3e..68b24a60a99 100644 --- a/spec/lib/gitlab/graphql/find_argument_in_parent_spec.rb +++ b/spec/lib/gitlab/graphql/find_argument_in_parent_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::FindArgumentInParent do +RSpec.describe Gitlab::Graphql::FindArgumentInParent do describe '#find' do def build_node(parent = nil, args: {}) props = { irep_node: double(arguments: args) } diff --git a/spec/lib/gitlab/graphql/generic_tracing_spec.rb b/spec/lib/gitlab/graphql/generic_tracing_spec.rb index ae92dcc40af..cd116225ecd 100644 --- a/spec/lib/gitlab/graphql/generic_tracing_spec.rb +++ b/spec/lib/gitlab/graphql/generic_tracing_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::GenericTracing do +RSpec.describe Gitlab::Graphql::GenericTracing do let(:graphql_duration_seconds_histogram) { double('Gitlab::Metrics::NullMetric') } it 'updates graphql histogram with expected labels' do diff --git a/spec/lib/gitlab/graphql/loaders/batch_lfs_oid_loader_spec.rb b/spec/lib/gitlab/graphql/loaders/batch_lfs_oid_loader_spec.rb index b3d57c899d5..ae5d9686c54 100644 --- a/spec/lib/gitlab/graphql/loaders/batch_lfs_oid_loader_spec.rb +++ b/spec/lib/gitlab/graphql/loaders/batch_lfs_oid_loader_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Loaders::BatchLfsOidLoader do +RSpec.describe Gitlab::Graphql::Loaders::BatchLfsOidLoader do include GraphqlHelpers let_it_be(:project) { create(:project, :repository) } diff --git a/spec/lib/gitlab/graphql/loaders/batch_model_loader_spec.rb b/spec/lib/gitlab/graphql/loaders/batch_model_loader_spec.rb index 79f9ecb39cf..cf1f00bc176 100644 --- a/spec/lib/gitlab/graphql/loaders/batch_model_loader_spec.rb +++ b/spec/lib/gitlab/graphql/loaders/batch_model_loader_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Loaders::BatchModelLoader do +RSpec.describe Gitlab::Graphql::Loaders::BatchModelLoader do describe '#find' do let(:issue) { create(:issue) } let(:user) { create(:user) } diff --git a/spec/lib/gitlab/graphql/loaders/batch_project_statistics_loader_spec.rb b/spec/lib/gitlab/graphql/loaders/batch_project_statistics_loader_spec.rb index ec2fcad31e5..7ae28fdcf0f 100644 --- a/spec/lib/gitlab/graphql/loaders/batch_project_statistics_loader_spec.rb +++ b/spec/lib/gitlab/graphql/loaders/batch_project_statistics_loader_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Loaders::BatchProjectStatisticsLoader do +RSpec.describe Gitlab::Graphql::Loaders::BatchProjectStatisticsLoader do describe '#find' do it 'only queries once for project statistics' do stats = create_list(:project_statistics, 2) diff --git a/spec/lib/gitlab/graphql/loaders/batch_root_storage_statistics_loader_spec.rb b/spec/lib/gitlab/graphql/loaders/batch_root_storage_statistics_loader_spec.rb index 38931f7ab5e..f73eace274d 100644 --- a/spec/lib/gitlab/graphql/loaders/batch_root_storage_statistics_loader_spec.rb +++ b/spec/lib/gitlab/graphql/loaders/batch_root_storage_statistics_loader_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Loaders::BatchRootStorageStatisticsLoader do +RSpec.describe Gitlab::Graphql::Loaders::BatchRootStorageStatisticsLoader do describe '#find' do it 'only queries once for project statistics' do stats = create_list(:namespace_root_storage_statistics, 2) diff --git a/spec/lib/gitlab/graphql/loaders/issuable_loader_spec.rb b/spec/lib/gitlab/graphql/loaders/issuable_loader_spec.rb new file mode 100644 index 00000000000..180966de895 --- /dev/null +++ b/spec/lib/gitlab/graphql/loaders/issuable_loader_spec.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do + subject { described_class.new(parent, finder) } + + let(:params) { HashWithIndifferentAccess.new } + + describe '#find_all' do + let(:finder) { double(:finder, params: params, execute: %i[x y z]) } + + where(:factory, :param_name) do + %i[project group].map { |thing| [thing, :"#{thing}_id"] } + end + + with_them do + let(:parent) { build_stubbed(factory) } + + it 'assignes the parent parameter, and batching_find_alls the finder' do + expect(subject.find_all).to contain_exactly(:x, :y, :z) + expect(params).to include(param_name => parent) + end + end + + context 'the parent is of an unexpected type' do + let(:parent) { build(:merge_request) } + + it 'raises an error if we pass an unexpected parent' do + expect { subject.find_all }.to raise_error(/Unexpected parent/) + end + end + end + + describe '#batching_find_all' do + context 'the finder params are anything other than [iids]' do + let(:finder) { double(:finder, params: params, execute: [:foo]) } + let(:parent) { build_stubbed(:project) } + + it 'batching_find_alls the finder, setting the correct parent parameter' do + expect(subject.batching_find_all).to eq([:foo]) + expect(params[:project_id]).to eq(parent) + end + + it 'allows a post-process block' do + expect(subject.batching_find_all(&:first)).to eq(:foo) + end + end + + context 'the finder params are exactly [iids]' do + # Dumb finder class, that only implements what we need, and has + # predictable query counts. + let(:finder_class) do + Class.new do + attr_reader :current_user, :params + + def initialize(user, args) + @current_user = user + @params = HashWithIndifferentAccess.new(args.to_h) + end + + def execute + params[:project_id].issues.where(iid: params[:iids]) + end + end + end + + it 'batches requests' do + issue_a = create(:issue) + issue_b = create(:issue) + issue_c = create(:issue, project: issue_a.project) + proj_1 = issue_a.project + proj_2 = issue_b.project + user = create(:user, developer_projects: [proj_1, proj_2]) + + finder_a = finder_class.new(user, iids: [issue_a.iid]) + finder_b = finder_class.new(user, iids: [issue_b.iid]) + finder_c = finder_class.new(user, iids: [issue_c.iid]) + + results = [] + + expect do + results.concat(described_class.new(proj_1, finder_a).batching_find_all) + results.concat(described_class.new(proj_2, finder_b).batching_find_all) + results.concat(described_class.new(proj_1, finder_c).batching_find_all) + end.not_to exceed_query_limit(0) + + expect do + results = results.map(&:sync) + end.not_to exceed_query_limit(2) + + expect(results).to contain_exactly(issue_a, issue_b, issue_c) + end + end + end +end diff --git a/spec/lib/gitlab/graphql/markdown_field/resolver_spec.rb b/spec/lib/gitlab/graphql/markdown_field/resolver_spec.rb index b95bcdef188..af604e1c7d5 100644 --- a/spec/lib/gitlab/graphql/markdown_field/resolver_spec.rb +++ b/spec/lib/gitlab/graphql/markdown_field/resolver_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Gitlab::Graphql::MarkdownField::Resolver do +RSpec.describe Gitlab::Graphql::MarkdownField::Resolver do include Gitlab::Routing let(:resolver) { described_class.new(:note) } diff --git a/spec/lib/gitlab/graphql/markdown_field_spec.rb b/spec/lib/gitlab/graphql/markdown_field_spec.rb index 866a20801d3..e3da925376e 100644 --- a/spec/lib/gitlab/graphql/markdown_field_spec.rb +++ b/spec/lib/gitlab/graphql/markdown_field_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Gitlab::Graphql::MarkdownField do +RSpec.describe Gitlab::Graphql::MarkdownField do describe '.markdown_field' do it 'creates the field with some default attributes' do field = class_with_markdown_field(:test_html, null: true, method: :hello).fields['testHtml'] diff --git a/spec/lib/gitlab/graphql/mount_mutation_spec.rb b/spec/lib/gitlab/graphql/mount_mutation_spec.rb new file mode 100644 index 00000000000..d6b932e08d2 --- /dev/null +++ b/spec/lib/gitlab/graphql/mount_mutation_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Gitlab::Graphql::MountMutation do + let_it_be(:mutation) do + Class.new(Mutations::BaseMutation) do + graphql_name 'TestMutation' + + argument :foo, GraphQL::STRING_TYPE, required: false + field :bar, GraphQL::STRING_TYPE, null: true + end + end + + describe '.mount_mutation' do + subject(:field) do + mutation_type = mutation_type_factory do |f| + f.mount_mutation(mutation) + end + + mutation_type.get_field('testMutation').to_graphql + end + + it 'mounts a mutation' do + expect(field.mutation).to be_present + end + end + + describe '.mount_aliased_mutation' do + subject(:field) do + mutation_type = mutation_type_factory do |f| + f.mount_aliased_mutation('MyAlias', mutation) + end + + mutation_type.get_field('myAlias').to_graphql + end + + it 'mounts a mutation' do + expect(field.mutation).to be_present + end + + it 'has a correct `graphql_name`' do + expect(field.mutation.graphql_name).to eq('MyAlias') + end + + it 'has a correct type' do + expect(field.type.name).to eq('MyAliasPayload') + end + + it 'has a correct input argument' do + expect(field.arguments['input'].type.unwrap.name).to eq('MyAliasInput') + end + end + + def mutation_type_factory + Class.new(GraphQL::Schema::Object) do + include Gitlab::Graphql::MountMutation + + graphql_name 'MutationType' + + yield(self) if block_given? + end + end +end diff --git a/spec/lib/gitlab/graphql/pagination/externally_paginated_array_connection_spec.rb b/spec/lib/gitlab/graphql/pagination/externally_paginated_array_connection_spec.rb index 11cf14523c2..932bcd8cd92 100644 --- a/spec/lib/gitlab/graphql/pagination/externally_paginated_array_connection_spec.rb +++ b/spec/lib/gitlab/graphql/pagination/externally_paginated_array_connection_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Pagination::ExternallyPaginatedArrayConnection do +RSpec.describe Gitlab::Graphql::Pagination::ExternallyPaginatedArrayConnection do let(:prev_cursor) { 1 } let(:next_cursor) { 6 } let(:values) { [2, 3, 4, 5] } diff --git a/spec/lib/gitlab/graphql/pagination/keyset/conditions/not_null_condition_spec.rb b/spec/lib/gitlab/graphql/pagination/keyset/conditions/not_null_condition_spec.rb index 33dc6bdea97..eecdaa3409f 100644 --- a/spec/lib/gitlab/graphql/pagination/keyset/conditions/not_null_condition_spec.rb +++ b/spec/lib/gitlab/graphql/pagination/keyset/conditions/not_null_condition_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Pagination::Keyset::Conditions::NotNullCondition do +RSpec.describe Gitlab::Graphql::Pagination::Keyset::Conditions::NotNullCondition do describe '#build' do let(:operators) { ['>', '>'] } let(:before_or_after) { :after } diff --git a/spec/lib/gitlab/graphql/pagination/keyset/conditions/null_condition_spec.rb b/spec/lib/gitlab/graphql/pagination/keyset/conditions/null_condition_spec.rb index 1c74f2fb0ab..582f96299ec 100644 --- a/spec/lib/gitlab/graphql/pagination/keyset/conditions/null_condition_spec.rb +++ b/spec/lib/gitlab/graphql/pagination/keyset/conditions/null_condition_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Pagination::Keyset::Conditions::NullCondition do +RSpec.describe Gitlab::Graphql::Pagination::Keyset::Conditions::NullCondition do describe '#build' do let(:values) { [nil, 500] } let(:operators) { [nil, '>'] } diff --git a/spec/lib/gitlab/graphql/pagination/keyset/connection_spec.rb b/spec/lib/gitlab/graphql/pagination/keyset/connection_spec.rb index ed728444b17..65698caac34 100644 --- a/spec/lib/gitlab/graphql/pagination/keyset/connection_spec.rb +++ b/spec/lib/gitlab/graphql/pagination/keyset/connection_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Pagination::Keyset::Connection do +RSpec.describe Gitlab::Graphql::Pagination::Keyset::Connection do let(:nodes) { Project.all.order(id: :asc) } let(:arguments) { {} } let(:query_type) { GraphQL::ObjectType.new } diff --git a/spec/lib/gitlab/graphql/pagination/keyset/order_info_spec.rb b/spec/lib/gitlab/graphql/pagination/keyset/order_info_spec.rb index cb5656d7c00..9f310f30253 100644 --- a/spec/lib/gitlab/graphql/pagination/keyset/order_info_spec.rb +++ b/spec/lib/gitlab/graphql/pagination/keyset/order_info_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Pagination::Keyset::OrderInfo do +RSpec.describe Gitlab::Graphql::Pagination::Keyset::OrderInfo do describe '#build_order_list' do let(:order_list) { described_class.build_order_list(relation) } diff --git a/spec/lib/gitlab/graphql/pagination/keyset/query_builder_spec.rb b/spec/lib/gitlab/graphql/pagination/keyset/query_builder_spec.rb index 7fd5b889cf9..31c02fd43e8 100644 --- a/spec/lib/gitlab/graphql/pagination/keyset/query_builder_spec.rb +++ b/spec/lib/gitlab/graphql/pagination/keyset/query_builder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Pagination::Keyset::QueryBuilder do +RSpec.describe Gitlab::Graphql::Pagination::Keyset::QueryBuilder do context 'when number of ordering fields is 0' do it 'raises an error' do expect { described_class.new(Issue.arel_table, [], {}, :after) } diff --git a/spec/lib/gitlab/graphql/pagination/offset_active_record_relation_connection_spec.rb b/spec/lib/gitlab/graphql/pagination/offset_active_record_relation_connection_spec.rb index 931b1e708de..86f35de94ed 100644 --- a/spec/lib/gitlab/graphql/pagination/offset_active_record_relation_connection_spec.rb +++ b/spec/lib/gitlab/graphql/pagination/offset_active_record_relation_connection_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection do +RSpec.describe Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection do it 'subclasses from GraphQL::Relay::RelationConnection' do expect(described_class.superclass).to eq GraphQL::Pagination::ActiveRecordRelationConnection end diff --git a/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb b/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb index 66033736e01..89d2ab8bb87 100644 --- a/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb +++ b/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer do +RSpec.describe Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer do subject { described_class.new } describe '#analyze?' do @@ -17,9 +17,27 @@ describe Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer do end context 'feature flag enabled by default' do + let(:monotonic_time_before) { 42 } + let(:monotonic_time_after) { 500 } + let(:monotonic_time_duration) { monotonic_time_after - monotonic_time_before } + it 'enables the analyzer' do expect(subject.analyze?(anything)).to be_truthy end + + it 'returns a duration in seconds' do + allow(GraphQL::Analysis).to receive(:analyze_query).and_return([4, 2]) + allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(monotonic_time_before, monotonic_time_after) + allow(Gitlab::GraphqlLogger).to receive(:info) + + expected_duration = monotonic_time_duration + memo = subject.initial_value(spy('query')) + + subject.final_value(memo) + + expect(memo).to have_key(:duration_s) + expect(memo[:duration_s]).to eq(expected_duration) + end end end end diff --git a/spec/lib/gitlab/graphql/representation/submodule_tree_entry_spec.rb b/spec/lib/gitlab/graphql/representation/submodule_tree_entry_spec.rb index ed092a846ae..eb56f1f9671 100644 --- a/spec/lib/gitlab/graphql/representation/submodule_tree_entry_spec.rb +++ b/spec/lib/gitlab/graphql/representation/submodule_tree_entry_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Representation::SubmoduleTreeEntry do +RSpec.describe Gitlab::Graphql::Representation::SubmoduleTreeEntry do let(:project) { create(:project, :repository) } let(:repository) { project.repository } diff --git a/spec/lib/gitlab/graphql/representation/tree_entry_spec.rb b/spec/lib/gitlab/graphql/representation/tree_entry_spec.rb index d45e690160c..f4eb7b37774 100644 --- a/spec/lib/gitlab/graphql/representation/tree_entry_spec.rb +++ b/spec/lib/gitlab/graphql/representation/tree_entry_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Representation::TreeEntry do +RSpec.describe Gitlab::Graphql::Representation::TreeEntry do let(:project) { create(:project, :repository) } let(:repository) { project.repository } diff --git a/spec/lib/gitlab/graphql/timeout_spec.rb b/spec/lib/gitlab/graphql/timeout_spec.rb index 8e04586d0ec..3669a89ba7c 100644 --- a/spec/lib/gitlab/graphql/timeout_spec.rb +++ b/spec/lib/gitlab/graphql/timeout_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Graphql::Timeout do +RSpec.describe Gitlab::Graphql::Timeout do it 'inherits from ' do expect(described_class.superclass).to eq GraphQL::Schema::Timeout end |