|
Lines 33-42
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
Link Here
|
| 33 |
|
33 |
|
| 34 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
34 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 35 |
|
35 |
|
| 36 |
$schema->storage->txn_begin; |
|
|
| 37 |
|
| 38 |
subtest 'list() tests' => sub { |
36 |
subtest 'list() tests' => sub { |
| 39 |
plan tests => 10; |
37 |
|
|
|
38 |
plan tests => 6; |
| 39 |
|
| 40 |
$schema->storage->txn_begin; |
| 40 |
|
41 |
|
| 41 |
Koha::SearchFilters->search()->delete(); |
42 |
Koha::SearchFilters->search()->delete(); |
| 42 |
|
43 |
|
|
Lines 94-127
subtest 'list() tests' => sub {
Link Here
|
| 94 |
->json_has('/2/search_filter_id') |
95 |
->json_has('/2/search_filter_id') |
| 95 |
->json_has('/3/search_filter_id'); |
96 |
->json_has('/3/search_filter_id'); |
| 96 |
|
97 |
|
| 97 |
subtest 'query parameters' => sub { |
98 |
$schema->storage->txn_rollback; |
| 98 |
|
|
|
| 99 |
plan tests => 12; |
| 100 |
$t->get_ok("//$userid:$password@/api/v1/search_filters?name=" . $search_filter_2->name) |
| 101 |
->status_is(200) |
| 102 |
->json_is( [ $search_filter_2->to_api ] ); |
| 103 |
$t->get_ok("//$userid:$password@/api/v1/search_filters?name=NotAName") |
| 104 |
->status_is(200) |
| 105 |
->json_is( [ ] ); |
| 106 |
$t->get_ok("//$userid:$password@/api/v1/search_filters?filter_query=kw:any") |
| 107 |
->status_is(200) |
| 108 |
->json_is( [ $search_filter_3->to_api ] ); |
| 109 |
$t->get_ok("//$userid:$password@/api/v1/search_filters?filter_limits=mc-itype,phr:BK") |
| 110 |
->status_is(200) |
| 111 |
->json_is( [ $search_filter_1->to_api, $search_filter_2->to_api ] ); |
| 112 |
}; |
| 113 |
|
| 114 |
# Warn on unsupported query parameter |
| 115 |
$t->get_ok( "//$userid:$password@/api/v1/search_filters?filter_blah=blah" ) |
| 116 |
->status_is(400) |
| 117 |
->json_is( [{ path => '/query/filter_blah', message => 'Malformed query string'}] ); |
| 118 |
|
| 119 |
}; |
99 |
}; |
| 120 |
|
100 |
|
| 121 |
subtest 'get() tests' => sub { |
101 |
subtest 'get() tests' => sub { |
| 122 |
|
102 |
|
| 123 |
plan tests => 9; |
103 |
plan tests => 9; |
| 124 |
|
104 |
|
|
|
105 |
$schema->storage->txn_begin; |
| 106 |
|
| 125 |
my $patron = $builder->build_object({ |
107 |
my $patron = $builder->build_object({ |
| 126 |
class => 'Koha::Patrons', |
108 |
class => 'Koha::Patrons', |
| 127 |
value => { flags => 3 } |
109 |
value => { flags => 3 } |
|
Lines 150-161
subtest 'get() tests' => sub {
Link Here
|
| 150 |
->status_is( 401, 'Cannot search filters without permission' ) |
132 |
->status_is( 401, 'Cannot search filters without permission' ) |
| 151 |
->json_is( '/error' => 'Authentication failure.' ); |
133 |
->json_is( '/error' => 'Authentication failure.' ); |
| 152 |
|
134 |
|
|
|
135 |
$schema->storage->txn_rollback; |
| 153 |
}; |
136 |
}; |
| 154 |
|
137 |
|
| 155 |
subtest 'add() tests' => sub { |
138 |
subtest 'add() tests' => sub { |
| 156 |
|
139 |
|
| 157 |
plan tests => 17; |
140 |
plan tests => 17; |
| 158 |
|
141 |
|
|
|
142 |
$schema->storage->txn_begin; |
| 143 |
|
| 159 |
my $authorized_patron = $builder->build_object({ |
144 |
my $authorized_patron = $builder->build_object({ |
| 160 |
class => 'Koha::Patrons', |
145 |
class => 'Koha::Patrons', |
| 161 |
value => { flags => 0 } |
146 |
value => { flags => 0 } |
|
Lines 231-241
subtest 'add() tests' => sub {
Link Here
|
| 231 |
] |
216 |
] |
| 232 |
); |
217 |
); |
| 233 |
|
218 |
|
|
|
219 |
$schema->storage->txn_rollback; |
| 234 |
}; |
220 |
}; |
| 235 |
|
221 |
|
| 236 |
subtest 'update() tests' => sub { |
222 |
subtest 'update() tests' => sub { |
|
|
223 |
|
| 237 |
plan tests => 15; |
224 |
plan tests => 15; |
| 238 |
|
225 |
|
|
|
226 |
$schema->storage->txn_begin; |
| 227 |
|
| 239 |
my $authorized_patron = $builder->build_object({ |
228 |
my $authorized_patron = $builder->build_object({ |
| 240 |
class => 'Koha::Patrons', |
229 |
class => 'Koha::Patrons', |
| 241 |
value => { flags => 0 } |
230 |
value => { flags => 0 } |
|
Lines 271-288
subtest 'update() tests' => sub {
Link Here
|
| 271 |
->status_is(403); |
260 |
->status_is(403); |
| 272 |
|
261 |
|
| 273 |
my $search_filter_update = { |
262 |
my $search_filter_update = { |
| 274 |
name => "Filter update", |
263 |
name => "Filter update", |
| 275 |
filter_query => "ti:The hobbit", |
264 |
query => "ti:The hobbit", |
| 276 |
filter_limits => "mc-ccode:fantasy", |
265 |
limits => "mc-ccode:fantasy", |
| 277 |
}; |
266 |
}; |
| 278 |
|
267 |
|
| 279 |
my $test = $t->put_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id" => json => $search_filter_update ) |
268 |
my $test = $t->put_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id" => json => $search_filter_update ) |
| 280 |
->status_is(200, 'Authorized user can update a macro') |
269 |
->status_is(200, 'Authorized user can update a macro') |
| 281 |
->json_is( '/search_filter_id' => $search_filter_id, 'We get back the id' ) |
270 |
->json_is( '/search_filter_id' => $search_filter_id, 'We get back the id' ) |
| 282 |
->json_is( '/name' => $search_filter_update->{name}, 'We get back the name' ) |
271 |
->json_is( '/name' => $search_filter_update->{name}, 'We get back the name' ) |
| 283 |
->json_is( '/filter_query' => $search_filter_update->{filter_query}, 'We get back our query' ) |
272 |
->json_is( '/query' => $search_filter_update->{query}, 'We get back our query' ) |
| 284 |
->json_is( '/filter_limits' => $search_filter_update->{filter_limits}, 'We get back our limits' ) |
273 |
->json_is( '/limits' => $search_filter_update->{limits}, 'We get back our limits' ) |
| 285 |
->json_is( '/opac' => 1, 'We get back our opac visibility unchanged' ) |
274 |
->json_is( '/opac' => 1, 'We get back our opac visibility unchanged' ) |
| 286 |
->json_is( '/staff_client' => 1, 'We get back our staff client visibility unchanged' ); |
275 |
->json_is( '/staff_client' => 1, 'We get back our staff client visibility unchanged' ); |
| 287 |
|
276 |
|
| 288 |
# Authorized attempt to write invalid data |
277 |
# Authorized attempt to write invalid data |
|
Lines 307-317
subtest 'update() tests' => sub {
Link Here
|
| 307 |
$t->put_ok("//$auth_userid:$password@/api/v1/search_filters/$non_existent_code" => json => $search_filter_update) |
296 |
$t->put_ok("//$auth_userid:$password@/api/v1/search_filters/$non_existent_code" => json => $search_filter_update) |
| 308 |
->status_is(404); |
297 |
->status_is(404); |
| 309 |
|
298 |
|
|
|
299 |
$schema->storage->txn_rollback; |
| 310 |
}; |
300 |
}; |
| 311 |
|
301 |
|
| 312 |
subtest 'delete() tests' => sub { |
302 |
subtest 'delete() tests' => sub { |
|
|
303 |
|
| 313 |
plan tests => 4; |
304 |
plan tests => 4; |
| 314 |
|
305 |
|
|
|
306 |
$schema->storage->txn_begin; |
| 307 |
|
| 315 |
my $authorized_patron = $builder->build_object({ |
308 |
my $authorized_patron = $builder->build_object({ |
| 316 |
class => 'Koha::Patrons', |
309 |
class => 'Koha::Patrons', |
| 317 |
value => { flags => 0 } |
310 |
value => { flags => 0 } |
|
Lines 348-353
subtest 'delete() tests' => sub {
Link Here
|
| 348 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id") |
341 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id") |
| 349 |
->status_is( 204, 'Can delete search filter with permission'); |
342 |
->status_is( 204, 'Can delete search filter with permission'); |
| 350 |
|
343 |
|
|
|
344 |
$schema->storage->txn_rollback; |
| 351 |
}; |
345 |
}; |
| 352 |
|
|
|
| 353 |
$schema->storage->txn_rollback; |
| 354 |
- |