From 137c19cce845745ebfd8479ebf4e5829bfb81650 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 17 Oct 2023 23:37:01 +0200 Subject: [PATCH] add previous_page? --- app/graphql/connections/cursor_connection.rb | 4 +++ .../connections/cursor_connection_spec.rb | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/graphql/connections/cursor_connection.rb b/app/graphql/connections/cursor_connection.rb index 34db4fb56..dc9699530 100644 --- a/app/graphql/connections/cursor_connection.rb +++ b/app/graphql/connections/cursor_connection.rb @@ -62,6 +62,10 @@ module Connections [limit, inverted] end + def previous_page?(after, result_size, limit, inverted) + after.present? || (result_size == limit && inverted) + end + def load_nodes @nodes ||= begin ensure_valid_params diff --git a/spec/graphql/connections/cursor_connection_spec.rb b/spec/graphql/connections/cursor_connection_spec.rb index 57ef64b89..2410e7401 100644 --- a/spec/graphql/connections/cursor_connection_spec.rb +++ b/spec/graphql/connections/cursor_connection_spec.rb @@ -57,4 +57,30 @@ RSpec.describe Connections::CursorConnection do it { is_expected.to eq(limit: 3, inverted: true) } end end + + describe '.previous_page?' do + let(:after) { nil } + let(:result_size) { nil } + let(:limit) { nil } + let(:inverted) { false } + + subject do + cursor = Connections::CursorConnection.new(Dossier) + cursor.send(:previous_page?, after, result_size, limit, inverted) + end + + context 'when after is present' do + let(:after) { :after } + + it { is_expected.to be true } + end + + context 'when inverted and result_size == limit' do + let(:inverted) { true } + let(:result_size) { 3 } + let(:limit) { 3 } + + it { is_expected.to be true } + end + end end