summaryrefslogtreecommitdiff
path: root/spec/lib/bitbucket_server/page_spec.rb
blob: 2da1d0995caa4323d39a0ad163d3179a81678669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

require 'spec_helper'

describe BitbucketServer::Page do
  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