diff options
Diffstat (limited to 'spec/lib/gitlab/graphql/pagination')
4 files changed, 42 insertions, 3 deletions
diff --git a/spec/lib/gitlab/graphql/pagination/array_connection_spec.rb b/spec/lib/gitlab/graphql/pagination/array_connection_spec.rb new file mode 100644 index 00000000000..03cf53bb990 --- /dev/null +++ b/spec/lib/gitlab/graphql/pagination/array_connection_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Gitlab::Graphql::Pagination::ArrayConnection do + let(:nodes) { (1..10) } + + subject(:connection) { described_class.new(nodes, max_page_size: 100) } + + it_behaves_like 'a connection with collection methods' + + it_behaves_like 'a redactable connection' do + let(:unwanted) { 5 } + 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 932bcd8cd92..d2475d1edb9 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 @@ -10,7 +10,13 @@ RSpec.describe Gitlab::Graphql::Pagination::ExternallyPaginatedArrayConnection d let(:arguments) { {} } subject(:connection) do - described_class.new(all_nodes, { max_page_size: values.size }.merge(arguments)) + described_class.new(all_nodes, **{ max_page_size: values.size }.merge(arguments)) + end + + it_behaves_like 'a connection with collection methods' + + it_behaves_like 'a redactable connection' do + let(:unwanted) { 3 } end describe '#nodes' do diff --git a/spec/lib/gitlab/graphql/pagination/keyset/connection_spec.rb b/spec/lib/gitlab/graphql/pagination/keyset/connection_spec.rb index c8f368b15fc..0ac54a20fcc 100644 --- a/spec/lib/gitlab/graphql/pagination/keyset/connection_spec.rb +++ b/spec/lib/gitlab/graphql/pagination/keyset/connection_spec.rb @@ -10,17 +10,24 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::Connection do let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: nil, object: nil) } subject(:connection) do - described_class.new(nodes, { context: context, max_page_size: 3 }.merge(arguments)) + described_class.new(nodes, **{ context: context, max_page_size: 3 }.merge(arguments)) end def encoded_cursor(node) - described_class.new(nodes, { context: context }).cursor_for(node) + described_class.new(nodes, context: context).cursor_for(node) end def decoded_cursor(cursor) Gitlab::Json.parse(Base64Bp.urlsafe_decode64(cursor)) end + it_behaves_like 'a connection with collection methods' + + it_behaves_like 'a redactable connection' do + let_it_be(:projects) { create_list(:project, 2) } + let(:unwanted) { projects.second } + end + describe '#cursor_for' do let(:project) { create(:project) } let(:cursor) { connection.cursor_for(project) } 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 86f35de94ed..1ca7c1c3c69 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 @@ -6,4 +6,15 @@ RSpec.describe Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection it 'subclasses from GraphQL::Relay::RelationConnection' do expect(described_class.superclass).to eq GraphQL::Pagination::ActiveRecordRelationConnection end + + it_behaves_like 'a connection with collection methods' do + let(:connection) { described_class.new(Project.all) } + end + + it_behaves_like 'a redactable connection' do + let_it_be(:users) { create_list(:user, 2) } + + let(:connection) { described_class.new(User.all, max_page_size: 10) } + let(:unwanted) { users.second } + end end |