2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'fast_spec_helper'
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe BitbucketServer::Page do
|
2018-11-18 11:00:15 +05:30
|
|
|
let(:response) { { 'values' => [{ 'description' => 'Test' }], 'isLastPage' => false, 'nextPageStart' => 2 } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
# Autoloading hack
|
|
|
|
BitbucketServer::Representation::PullRequest.new({})
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#items' do
|
|
|
|
it 'returns collection of needed objects' do
|
|
|
|
page = described_class.new(response, :pull_request)
|
|
|
|
|
|
|
|
expect(page.items.first).to be_a(BitbucketServer::Representation::PullRequest)
|
|
|
|
expect(page.items.count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#attrs' do
|
|
|
|
it 'returns attributes' do
|
|
|
|
page = described_class.new(response, :pull_request)
|
|
|
|
|
|
|
|
expect(page.attrs.keys).to include(:isLastPage, :nextPageStart)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#next?' do
|
|
|
|
it 'returns true' do
|
|
|
|
page = described_class.new(response, :pull_request)
|
|
|
|
|
|
|
|
expect(page.next?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
response['isLastPage'] = true
|
|
|
|
response.delete('nextPageStart')
|
|
|
|
page = described_class.new(response, :pull_request)
|
|
|
|
|
|
|
|
expect(page.next?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#next' do
|
|
|
|
it 'returns next attribute' do
|
|
|
|
page = described_class.new(response, :pull_request)
|
|
|
|
|
|
|
|
expect(page.next).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|