|
Link Here
|
| 33 |
|
33 |
|
| 34 |
get '/pagination_headers' => sub { |
34 |
get '/pagination_headers' => sub { |
| 35 |
my $c = shift; |
35 |
my $c = shift; |
| 36 |
$c->add_pagination_headers({ total => 10, params => { _page => 2, _per_page => 3, firstname => 'Jonathan' } }); |
36 |
$c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 2, _per_page => 3, firstname => 'Jonathan' } }); |
| 37 |
$c->render( json => { ok => 1 }, status => 200 ); |
37 |
$c->render( json => { ok => 1 }, status => 200 ); |
| 38 |
}; |
38 |
}; |
| 39 |
|
39 |
|
| 40 |
get '/pagination_headers_first_page' => sub { |
40 |
get '/pagination_headers_first_page' => sub { |
| 41 |
my $c = shift; |
41 |
my $c = shift; |
| 42 |
$c->add_pagination_headers({ total => 10, params => { _page => 1, _per_page => 3, firstname => 'Jonathan' } }); |
42 |
$c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 1, _per_page => 3, firstname => 'Jonathan' } }); |
| 43 |
$c->render( json => { ok => 1 }, status => 200 ); |
43 |
$c->render( json => { ok => 1 }, status => 200 ); |
| 44 |
}; |
44 |
}; |
| 45 |
|
45 |
|
| 46 |
get '/pagination_headers_last_page' => sub { |
46 |
get '/pagination_headers_last_page' => sub { |
| 47 |
my $c = shift; |
47 |
my $c = shift; |
| 48 |
$c->add_pagination_headers({ total => 10, params => { _page => 4, _per_page => 3, firstname => 'Jonathan' } }); |
48 |
$c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 4, _per_page => 3, firstname => 'Jonathan' } }); |
| 49 |
$c->render( json => { ok => 1 }, status => 200 ); |
49 |
$c->render( json => { ok => 1 }, status => 200 ); |
| 50 |
}; |
50 |
}; |
| 51 |
|
51 |
|
|
Link Here
|
| 60 |
|
60 |
|
| 61 |
get '/pagination_headers_without_page_size' => sub { |
61 |
get '/pagination_headers_without_page_size' => sub { |
| 62 |
my $c = shift; |
62 |
my $c = shift; |
| 63 |
$c->add_pagination_headers({ total => 10, params => { _page => 2, firstname => 'Jonathan' } }); |
63 |
$c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 2, firstname => 'Jonathan' } }); |
| 64 |
$c->render( json => { ok => 1 }, status => 200 ); |
64 |
$c->render( json => { ok => 1 }, status => 200 ); |
| 65 |
}; |
65 |
}; |
| 66 |
|
66 |
|
| 67 |
get '/pagination_headers_without_page' => sub { |
67 |
get '/pagination_headers_without_page' => sub { |
| 68 |
my $c = shift; |
68 |
my $c = shift; |
| 69 |
$c->add_pagination_headers({ total => 10, params => { _per_page => 3, firstname => 'Jonathan' } }); |
69 |
$c->add_pagination_headers({ total => 10, base_total => 12, params => { _per_page => 3, firstname => 'Jonathan' } }); |
| 70 |
$c->render( json => { ok => 1 }, status => 200 ); |
70 |
$c->render( json => { ok => 1 }, status => 200 ); |
| 71 |
}; |
71 |
}; |
| 72 |
|
72 |
|
|
Link Here
|
| 75 |
$c->add_pagination_headers( |
75 |
$c->add_pagination_headers( |
| 76 |
{ |
76 |
{ |
| 77 |
total => 10, |
77 |
total => 10, |
|
|
78 |
base_total => 12, |
| 78 |
params => { _per_page => -1, firstname => 'Jonathan' } |
79 |
params => { _per_page => -1, firstname => 'Jonathan' } |
| 79 |
} |
80 |
} |
| 80 |
); |
81 |
); |
|
Link Here
|
| 86 |
$c->add_pagination_headers( |
87 |
$c->add_pagination_headers( |
| 87 |
{ |
88 |
{ |
| 88 |
total => 10, |
89 |
total => 10, |
|
|
90 |
base_total => 12, |
| 89 |
params => { page => 100, _per_page => -1, firstname => 'Jonathan' } |
91 |
params => { page => 100, _per_page => -1, firstname => 'Jonathan' } |
| 90 |
} |
92 |
} |
| 91 |
); |
93 |
); |
|
Link Here
|
| 101 |
|
103 |
|
| 102 |
subtest 'add_pagination_headers() tests' => sub { |
104 |
subtest 'add_pagination_headers() tests' => sub { |
| 103 |
|
105 |
|
| 104 |
plan tests => 101; |
106 |
plan tests => 109; |
| 105 |
|
107 |
|
| 106 |
my $t = Test::Mojo->new; |
108 |
my $t = Test::Mojo->new; |
| 107 |
|
109 |
|
| 108 |
$t->get_ok('/empty') |
110 |
$t->get_ok('/empty') |
| 109 |
->status_is( 200 ) |
111 |
->status_is( 200 ) |
| 110 |
->header_is( 'X-Total-Count' => undef, 'X-Total-Count is undefined' ) |
112 |
->header_is( 'X-Total-Count' => undef, 'X-Total-Count is undefined' ) |
|
|
113 |
->header_is( 'X-Base-Total-Count' => undef, 'X-Base-Total-Count is undefined' ) |
| 111 |
->header_is( 'Link' => undef, 'Link is undefined' ); |
114 |
->header_is( 'Link' => undef, 'Link is undefined' ); |
| 112 |
|
115 |
|
| 113 |
$t->get_ok('/pagination_headers') |
116 |
$t->get_ok('/pagination_headers') |
| 114 |
->status_is( 200 ) |
117 |
->status_is( 200 ) |
| 115 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) |
118 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) |
|
|
119 |
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) |
| 116 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ ) |
120 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ ) |
| 117 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=1.*>; rel="prev",/ ) |
121 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=1.*>; rel="prev",/ ) |
| 118 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) |
122 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) |
|
Link Here
|
| 129 |
$t->get_ok('/pagination_headers_first_page') |
133 |
$t->get_ok('/pagination_headers_first_page') |
| 130 |
->status_is( 200 ) |
134 |
->status_is( 200 ) |
| 131 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) |
135 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) |
|
|
136 |
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) |
| 132 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*>; rel="prev",/ ) |
137 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*>; rel="prev",/ ) |
| 133 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="next",/ ) |
138 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="next",/ ) |
| 134 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=2.*>; rel="next",/ ) |
139 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=2.*>; rel="next",/ ) |
|
Link Here
|
| 143 |
$t->get_ok('/pagination_headers_last_page') |
148 |
$t->get_ok('/pagination_headers_last_page') |
| 144 |
->status_is( 200 ) |
149 |
->status_is( 200 ) |
| 145 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) |
150 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) |
|
|
151 |
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) |
| 146 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ ) |
152 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ ) |
| 147 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=3.*>; rel="prev",/ ) |
153 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=3.*>; rel="prev",/ ) |
| 148 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) |
154 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) |
|
Link Here
|
| 158 |
$t->get_ok('/pagination_headers_without_page_size') |
164 |
$t->get_ok('/pagination_headers_without_page_size') |
| 159 |
->status_is( 200 ) |
165 |
->status_is( 200 ) |
| 160 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) |
166 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) |
|
|
167 |
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) |
| 161 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/ ) |
168 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/ ) |
| 162 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/ ) |
169 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/ ) |
| 163 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) |
170 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) |
|
Link Here
|
| 174 |
$t->get_ok('/pagination_headers_without_page') |
181 |
$t->get_ok('/pagination_headers_without_page') |
| 175 |
->status_is( 200 ) |
182 |
->status_is( 200 ) |
| 176 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, even without page param' ) |
183 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, even without page param' ) |
|
|
184 |
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) |
| 177 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/, 'First page, no previous' ) |
185 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/, 'First page, no previous' ) |
| 178 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' ) |
186 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' ) |
| 179 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' ) |
187 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' ) |
|
Link Here
|
| 190 |
$t->get_ok('/pagination_headers_with_minus_one') |
198 |
$t->get_ok('/pagination_headers_with_minus_one') |
| 191 |
->status_is( 200 ) |
199 |
->status_is( 200 ) |
| 192 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' ) |
200 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' ) |
|
|
201 |
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) |
| 193 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' ) |
202 |
->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' ) |
203 |
->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' ) |
204 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' ) |
|
Link Here
|
| 204 |
$t->get_ok('/pagination_headers_with_minus_one_and_invalid_page') |
213 |
$t->get_ok('/pagination_headers_with_minus_one_and_invalid_page') |
| 205 |
->status_is( 200 ) |
214 |
->status_is( 200 ) |
| 206 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' ) |
215 |
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' ) |
|
|
216 |
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) |
| 207 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' ) |
217 |
->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' ) |
218 |
->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' ) |
219 |
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' ) |