Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cursor_based_keyset_spec.rb « pagination « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4128f745ce78215b7b478d05194ad554273022fa (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Pagination::CursorBasedKeyset do
  subject { described_class }

  describe '.available_for_type?' do
    context 'with api_keyset_pagination_multi_order FF disabled' do
      before do
        stub_feature_flags(api_keyset_pagination_multi_order: false)
      end

      it 'returns true for Group' do
        expect(subject.available_for_type?(Group.all)).to be_truthy
      end

      it 'returns true for Ci::Build' do
        expect(subject.available_for_type?(Ci::Build.all)).to be_truthy
      end

      it 'returns true for Packages::BuildInfo' do
        expect(subject.available_for_type?(Packages::BuildInfo.all)).to be_truthy
      end

      it 'return false for User' do
        expect(subject.available_for_type?(User.all)).to be_falsey
      end
    end

    context 'with api_keyset_pagination_multi_order FF enabled' do
      before do
        stub_feature_flags(api_keyset_pagination_multi_order: true)
      end

      it 'returns true for Group' do
        expect(subject.available_for_type?(Group.all)).to be_truthy
      end

      it 'returns true for Ci::Build' do
        expect(subject.available_for_type?(Ci::Build.all)).to be_truthy
      end

      it 'returns true for Packages::BuildInfo' do
        expect(subject.available_for_type?(Packages::BuildInfo.all)).to be_truthy
      end

      it 'returns true for User' do
        expect(subject.available_for_type?(User.all)).to be_truthy
      end

      it 'return false for other types of relations' do
        expect(subject.available_for_type?(Issue.all)).to be_falsey
      end
    end
  end

  describe '.enforced_for_type?' do
    subject { described_class.enforced_for_type?(relation) }

    context 'when relation is Group' do
      let(:relation) { Group.all }

      it { is_expected.to be true }
    end

    context 'when relation is AuditEvent' do
      let(:relation) { AuditEvent.all }

      it { is_expected.to be false }
    end

    context 'when relation is Ci::Build' do
      let(:relation) { Ci::Build.all }

      it { is_expected.to be false }
    end
  end

  describe '.available?' do
    let(:request_context) { double('request_context', params: { order_by: order_by, sort: sort }) }
    let(:cursor_based_request_context) { Gitlab::Pagination::Keyset::CursorBasedRequestContext.new(request_context) }

    context 'with order-by name asc' do
      let(:order_by) { :name }
      let(:sort) { :asc }

      it 'returns true for Group' do
        expect(subject.available?(cursor_based_request_context, Group.all)).to be_truthy
      end

      it 'return false for other types of relations' do
        expect(subject.available?(cursor_based_request_context, Issue.all)).to be_falsey
        expect(subject.available?(cursor_based_request_context, Ci::Build.all)).to be_falsey
        expect(subject.available?(cursor_based_request_context, Packages::BuildInfo.all)).to be_falsey
      end
    end

    context 'with order-by id desc' do
      let(:order_by) { :id }
      let(:sort) { :desc }

      context 'with api_keyset_pagination_multi_order FF disabled' do
        before do
          stub_feature_flags(api_keyset_pagination_multi_order: false)
        end

        it 'returns true for Ci::Build' do
          expect(subject.available?(cursor_based_request_context, Ci::Build.all)).to be_truthy
        end

        it 'returns true for AuditEvent' do
          expect(subject.available?(cursor_based_request_context, AuditEvent.all)).to be_truthy
        end

        it 'returns true for Packages::BuildInfo' do
          expect(subject.available?(cursor_based_request_context, Packages::BuildInfo.all)).to be_truthy
        end

        it 'returns false for User' do
          expect(subject.available?(cursor_based_request_context, User.all)).to be_falsey
        end
      end

      context 'with api_keyset_pagination_multi_order FF enabled' do
        before do
          stub_feature_flags(api_keyset_pagination_multi_order: true)
        end

        it 'returns true for Ci::Build' do
          expect(subject.available?(cursor_based_request_context, Ci::Build.all)).to be_truthy
        end

        it 'returns true for AuditEvent' do
          expect(subject.available?(cursor_based_request_context, AuditEvent.all)).to be_truthy
        end

        it 'returns true for Packages::BuildInfo' do
          expect(subject.available?(cursor_based_request_context, Packages::BuildInfo.all)).to be_truthy
        end

        it 'returns true for User' do
          expect(subject.available?(cursor_based_request_context, User.all)).to be_truthy
        end
      end
    end

    context 'with other order-by columns' do
      let(:order_by) { :path }
      let(:sort) { :asc }

      it 'returns false for Group' do
        expect(subject.available?(cursor_based_request_context, Group.all)).to be_falsey
      end

      it 'return false for other types of relations' do
        expect(subject.available?(cursor_based_request_context, Issue.all)).to be_falsey
      end
    end
  end
end