Link Here
|
75 |
|
75 |
|
76 |
t::lib::Mocks::mock_preference( 'RESTdefaultPageSize', 20 ); |
76 |
t::lib::Mocks::mock_preference( 'RESTdefaultPageSize', 20 ); |
77 |
|
77 |
|
78 |
my $libraries = |
78 |
my $cities = |
79 |
$t->get_ok("//$userid:$password@/api/v1/cities")->status_is(200) |
79 |
$t->get_ok("//$userid:$password@/api/v1/cities")->status_is(200) |
80 |
->header_is( 'X-Total-Count', '10' ) |
80 |
->header_is( 'X-Total-Count', '10' ) |
81 |
->header_is( 'X-Base-Total-Count', '10' ) |
81 |
->header_is( 'X-Base-Total-Count', '10' ) |
Link Here
|
87 |
qr#(_per_page=20\&_page=1|_page=1\&_per_page=20)>\; rel="last"# ) |
87 |
qr#(_per_page=20\&_page=1|_page=1\&_per_page=20)>\; rel="last"# ) |
88 |
->tx->res->json; |
88 |
->tx->res->json; |
89 |
|
89 |
|
90 |
is( scalar @{$libraries}, 10, '10 libraries retrieved' ); |
90 |
is( scalar @{$cities}, 10, '10 cities retrieved' ); |
91 |
|
91 |
|
92 |
$libraries = |
92 |
$cities = |
93 |
$t->get_ok("//$userid:$password@/api/v1/cities?q={\"name\":{\"-like\":\"\%A\"}}")->status_is(200) |
93 |
$t->get_ok("//$userid:$password@/api/v1/cities?q={\"name\":{\"-like\":\"\%A\"}}")->status_is(200) |
94 |
->header_is( 'X-Total-Count', '5', 'The resultset has 5 items' ) |
94 |
->header_is( 'X-Total-Count', '5', 'The resultset has 5 items' ) |
95 |
->header_is( 'X-Base-Total-Count', '10', 'The resultset, without the filter, has 10' ) |
95 |
->header_is( 'X-Base-Total-Count', '10', 'The resultset, without the filter, has 10' ) |
Link Here
|
101 |
qr#(_per_page=20.*\&_page=1.*|_page=1.*\&_per_page=20.*)>\; rel="last"# ) |
101 |
qr#(_per_page=20.*\&_page=1.*|_page=1.*\&_per_page=20.*)>\; rel="last"# ) |
102 |
->tx->res->json; |
102 |
->tx->res->json; |
103 |
|
103 |
|
104 |
is( scalar @{$libraries}, 5, '5 libraries retrieved' ); |
104 |
is( scalar @{$cities}, 5, '5 cities retrieved' ); |
105 |
|
105 |
|
106 |
t::lib::Mocks::mock_preference( 'RESTdefaultPageSize', 3 ); |
106 |
t::lib::Mocks::mock_preference( 'RESTdefaultPageSize', 3 ); |
107 |
|
107 |
|
108 |
# _per_page overrides RESTdefaultPageSize |
108 |
# _per_page overrides RESTdefaultPageSize |
109 |
$libraries = |
109 |
$cities = |
110 |
$t->get_ok("//$userid:$password@/api/v1/cities?_per_page=20") |
110 |
$t->get_ok("//$userid:$password@/api/v1/cities?_per_page=20") |
111 |
->status_is(200) |
111 |
->status_is(200) |
112 |
->header_is( 'X-Total-Count', '10' ) |
112 |
->header_is( 'X-Total-Count', '10' ) |
Link Here
|
119 |
qr#(_per_page=20\&_page=1|_page=1\&_per_page=20)>\; rel="last"# ) |
119 |
qr#(_per_page=20\&_page=1|_page=1\&_per_page=20)>\; rel="last"# ) |
120 |
->tx->res->json; |
120 |
->tx->res->json; |
121 |
|
121 |
|
122 |
is( scalar @{$libraries}, 10, '10 libraries retrieved' ); |
122 |
is( scalar @{$cities}, 10, '10 cities retrieved' ); |
123 |
|
123 |
|
124 |
# page 1 |
124 |
# page 1 |
125 |
$libraries = |
125 |
$cities = |
126 |
$t->get_ok("//$userid:$password@/api/v1/cities")->status_is(200) |
126 |
$t->get_ok("//$userid:$password@/api/v1/cities")->status_is(200) |
127 |
->header_is( 'X-Total-Count', '10' ) |
127 |
->header_is( 'X-Total-Count', '10' ) |
128 |
->header_is( 'X-Base-Total-Count', '10' ) |
128 |
->header_is( 'X-Base-Total-Count', '10' ) |
Link Here
|
135 |
qr#(_per_page=3\&_page=4|_page=4\&_per_page=3)>\; rel="last"# ) |
135 |
qr#(_per_page=3\&_page=4|_page=4\&_per_page=3)>\; rel="last"# ) |
136 |
->tx->res->json; |
136 |
->tx->res->json; |
137 |
|
137 |
|
138 |
is( scalar @{$libraries}, 3, '3 libraries retrieved' ); |
138 |
is( scalar @{$cities}, 3, '3 cities retrieved' ); |
139 |
|
139 |
|
140 |
# This tests X-Base-Total-Count, .* is used for q=, as we don't want |
140 |
# This tests X-Base-Total-Count, .* is used for q=, as we don't want |
141 |
# to add all combinations to the regex |
141 |
# to add all combinations to the regex |
142 |
$libraries = |
142 |
$cities = |
143 |
$t->get_ok("//$userid:$password@/api/v1/cities?_per_page=2&_page=2&q={\"name\":{\"-like\":\"\%A\"}}")->status_is(200) |
143 |
$t->get_ok("//$userid:$password@/api/v1/cities?_per_page=2&_page=2&q={\"name\":{\"-like\":\"\%A\"}}")->status_is(200) |
144 |
->header_is( 'X-Total-Count', '5' ) |
144 |
->header_is( 'X-Total-Count', '5' ) |
145 |
->header_is( 'X-Base-Total-Count', '10' ) |
145 |
->header_is( 'X-Base-Total-Count', '10' ) |
Link Here
|
153 |
qr#(_per_page=2.*\&_page=3.*|_page=3.*\&_per_page=2.*)>\; rel="last"# ) |
153 |
qr#(_per_page=2.*\&_page=3.*|_page=3.*\&_per_page=2.*)>\; rel="last"# ) |
154 |
->tx->res->json; |
154 |
->tx->res->json; |
155 |
|
155 |
|
156 |
is( scalar @{$libraries}, 2, '2 libraries retrieved' ); |
156 |
is( scalar @{$cities}, 2, '2 cities retrieved' ); |
157 |
|
157 |
|
158 |
# last page, with only one result |
158 |
# last page, with only one result |
159 |
$libraries = |
159 |
$cities = |
160 |
$t->get_ok("//$userid:$password@/api/v1/cities?_page=4")->status_is(200) |
160 |
$t->get_ok("//$userid:$password@/api/v1/cities?_page=4")->status_is(200) |
161 |
->header_is( 'X-Total-Count', '10' ) |
161 |
->header_is( 'X-Total-Count', '10' ) |
162 |
->header_is( 'X-Base-Total-Count', '10' ) |
162 |
->header_is( 'X-Base-Total-Count', '10' ) |
Link Here
|
169 |
qr#(_per_page=3\&_page=4|_page=4\&_per_page=3)>\; rel="last"# ) |
169 |
qr#(_per_page=3\&_page=4|_page=4\&_per_page=3)>\; rel="last"# ) |
170 |
->tx->res->json; |
170 |
->tx->res->json; |
171 |
|
171 |
|
172 |
is( scalar @{$libraries}, 1, '1 library retrieved' ); |
172 |
is( scalar @{$cities}, 1, '1 city retrieved' ); |
173 |
|
173 |
|
174 |
$libraries = |
174 |
$cities = |
175 |
$t->get_ok("//$userid:$password@/api/v1/cities?_per_page=-1") |
175 |
$t->get_ok("//$userid:$password@/api/v1/cities?_per_page=-1") |
176 |
->status_is(200) |
176 |
->status_is(200) |
177 |
->header_is( 'X-Total-Count', '10' ) |
177 |
->header_is( 'X-Total-Count', '10' ) |
Link Here
|
184 |
qr#(_per_page=-1\&_page=1|_page=1\&_per_page=-1)>\; rel="last"# ) |
184 |
qr#(_per_page=-1\&_page=1|_page=1\&_per_page=-1)>\; rel="last"# ) |
185 |
->tx->res->json; |
185 |
->tx->res->json; |
186 |
|
186 |
|
187 |
is( scalar @{$libraries}, 10, '10 libraries retrieved, -1 means all' ); |
187 |
is( scalar @{$cities}, 10, '10 cities retrieved, -1 means all' ); |
188 |
|
188 |
|
189 |
$schema->storage->txn_rollback; |
189 |
$schema->storage->txn_rollback; |
190 |
}; |
190 |
}; |
191 |
- |
|
|