|
Link Here
|
| 70 |
$c->render( json => { ok => 1 }, status => 200 ); |
70 |
$c->render( json => { ok => 1 }, status => 200 ); |
| 71 |
}; |
71 |
}; |
| 72 |
|
72 |
|
|
|
73 |
get '/pagination_headers_with_minus_one' => sub { |
| 74 |
my $c = shift; |
| 75 |
$c->add_pagination_headers( |
| 76 |
{ |
| 77 |
total => 10, |
| 78 |
params => { _per_page => -1, firstname => 'Jonathan' } |
| 79 |
} |
| 80 |
); |
| 81 |
$c->render( json => { ok => 1 }, status => 200 ); |
| 82 |
}; |
| 83 |
|
| 84 |
get '/pagination_headers_with_minus_one_and_invalid_page' => sub { |
| 85 |
my $c = shift; |
| 86 |
$c->add_pagination_headers( |
| 87 |
{ |
| 88 |
total => 10, |
| 89 |
params => { page => 100, _per_page => -1, firstname => 'Jonathan' } |
| 90 |
} |
| 91 |
); |
| 92 |
$c->render( json => { ok => 1 }, status => 200 ); |
| 93 |
}; |
| 94 |
|
| 73 |
# The tests |
95 |
# The tests |
| 74 |
|
96 |
|
| 75 |
use Test::More tests => 2; |
97 |
use Test::More tests => 2; |
|
Link Here
|
| 79 |
|
101 |
|
| 80 |
subtest 'add_pagination_headers() tests' => sub { |
102 |
subtest 'add_pagination_headers() tests' => sub { |
| 81 |
|
103 |
|
| 82 |
plan tests => 75; |
104 |
plan tests => 101; |
| 83 |
|
105 |
|
| 84 |
my $t = Test::Mojo->new; |
106 |
my $t = Test::Mojo->new; |
| 85 |
|
107 |
|
|
Link Here
|
| 164 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="last"/ ) |
186 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="last"/ ) |
| 165 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=4.*>; rel="last"/ ) |
187 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=4.*>; rel="last"/ ) |
| 166 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ ); |
188 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ ); |
|
|
189 |
|
| 190 |
$t->get_ok('/pagination_headers_with_minus_one') |
| 191 |
->status_is( 200 ) |
| 192 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' ) |
| 193 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' ) |
| 194 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' ) |
| 195 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' ) |
| 196 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="next",/, 'No next page, all resources are fetched' ) |
| 197 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="first",/ ) |
| 198 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="first",/ ) |
| 199 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="first",/ ) |
| 200 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="last"/ ) |
| 201 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="last"/ ) |
| 202 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ ); |
| 203 |
|
| 204 |
$t->get_ok('/pagination_headers_with_minus_one_and_invalid_page') |
| 205 |
->status_is( 200 ) |
| 206 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' ) |
| 207 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' ) |
| 208 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' ) |
| 209 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' ) |
| 210 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="next",/, 'No next page, all resources are fetched' ) |
| 211 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="first",/ ) |
| 212 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="first",/ ) |
| 213 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="first",/ ) |
| 214 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="last"/ ) |
| 215 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="last"/ ) |
| 216 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ ); |
| 167 |
}; |
217 |
}; |
| 168 |
|
218 |
|
| 169 |
subtest 'dbic_merge_pagination() tests' => sub { |
219 |
subtest 'dbic_merge_pagination() tests' => sub { |