Skip to content

Commit

Permalink
Add pagination specs
Browse files Browse the repository at this point in the history
  • Loading branch information
phylor authored and rmehner committed Jun 13, 2022
1 parent f43dbae commit ec15a2e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/ioki/apis/endpoints/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,34 @@
expect(result.map(&:id)).to eq(%w[001 002 003 004 005])
end

it 'paginates and returns the first page' do
result = endpoint.call client, [], model_class: model_class, params: params, paginate: true

expect(result).to be_kind_of(Ioki::Model::Response)

expect(result.data).to be_kind_of(Array)
expect(result.data.size).to eq(2)
expect(result.data.map(&:id)).to eq(%w[001 002])

expect(result.meta).to be_kind_of(Ioki::Model::Meta)
expect(result.meta.page).to eq 1
expect(result.meta.last_page).to be false
end

it 'paginates and returns another page' do
result = endpoint.call client, [], model_class: model_class, params: params.merge(page: 3), paginate: true

expect(result).to be_kind_of(Ioki::Model::Response)

expect(result.data).to be_kind_of(Array)
expect(result.data.size).to eq(1)
expect(result.data.map(&:id)).to eq(%w[005])

expect(result.meta).to be_kind_of(Ioki::Model::Meta)
expect(result.meta.page).to eq 3
expect(result.meta.last_page).to be true
end

it 'yields 5 times to the given block using auto_paginate' do
expect do |block|
endpoint.call client, [], model_class: model_class, params: params, auto_paginate: true, &block
Expand Down

0 comments on commit ec15a2e

Please sign in to comment.