add previous_page?

This commit is contained in:
simon lehericey 2023-10-17 23:37:01 +02:00 committed by Paul Chavard
parent 17aab9c891
commit 137c19cce8
2 changed files with 30 additions and 0 deletions

View file

@ -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

View file

@ -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