Link Here
|
58 |
$c->render( json => $filter, status => 200 ); |
58 |
$c->render( json => $filter, status => 200 ); |
59 |
}; |
59 |
}; |
60 |
|
60 |
|
|
|
61 |
get '/pagination_headers_without_page_size' => sub { |
62 |
my $c = shift; |
63 |
$c->add_pagination_headers({ total => 10, params => { _page => 2, firstname => 'Jonathan' } }); |
64 |
$c->render( json => { ok => 1 }, status => 200 ); |
65 |
}; |
66 |
|
67 |
get '/pagination_headers_without_page' => sub { |
68 |
my $c = shift; |
69 |
$c->add_pagination_headers({ total => 10, params => { _per_page => 4, firstname => 'Jonathan' } }); |
70 |
$c->render( json => { ok => 1 }, status => 200 ); |
71 |
}; |
72 |
|
61 |
# The tests |
73 |
# The tests |
62 |
|
74 |
|
63 |
use Test::More tests => 2; |
75 |
use Test::More tests => 2; |
64 |
use Test::Mojo; |
76 |
use Test::Mojo; |
65 |
|
77 |
|
|
|
78 |
use t::lib::Mocks; |
79 |
|
66 |
subtest 'add_pagination_headers() tests' => sub { |
80 |
subtest 'add_pagination_headers() tests' => sub { |
67 |
|
81 |
|
68 |
plan tests => 45; |
82 |
plan tests => 64; |
69 |
|
83 |
|
70 |
my $t = Test::Mojo->new; |
84 |
my $t = Test::Mojo->new; |
71 |
|
85 |
|
Link Here
|
117 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="last"/ ) |
131 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="last"/ ) |
118 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=4.*>; rel="last"/ ) |
132 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=4.*>; rel="last"/ ) |
119 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ ); |
133 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ ); |
|
|
134 |
|
135 |
t::lib::Mocks::mock_preference('RESTdefaultPageSize', 3); |
136 |
$t->get_ok('/pagination_headers_without_page_size') |
137 |
->status_is( 200 ) |
138 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) |
139 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/ ) |
140 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/ ) |
141 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) |
142 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="next",/ ) |
143 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=3.*>; rel="next",/ ) |
144 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="next",/ ) |
145 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="first",/ ) |
146 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="first",/ ) |
147 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="first",/ ) |
148 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="last"/ ) |
149 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=4.*>; rel="last"/ ) |
150 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ ); |
151 |
|
152 |
$t->get_ok('/pagination_headers_without_page') |
153 |
->status_is( 200 ) |
154 |
->header_is( 'X-Total-Count' => undef, 'X-Total-Count header absent' ) |
155 |
->header_is( 'Link' => undef, 'Link header absent' ); |
156 |
|
157 |
|
120 |
}; |
158 |
}; |
121 |
|
159 |
|
122 |
subtest 'dbic_merge_pagination() tests' => sub { |
160 |
subtest 'dbic_merge_pagination() tests' => sub { |
123 |
- |
|
|