Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 3; |
22 |
use Test::More tests => 4; |
23 |
use Test::Mojo; |
23 |
use Test::Mojo; |
24 |
use Test::Warn; |
24 |
use Test::Warn; |
25 |
|
25 |
|
Lines 321-323
subtest 'pickup_locations() tests' => sub {
Link Here
|
321 |
|
321 |
|
322 |
$schema->storage->txn_rollback; |
322 |
$schema->storage->txn_rollback; |
323 |
}; |
323 |
}; |
324 |
- |
324 |
|
|
|
325 |
subtest 'checkout() tests' => sub { |
326 |
|
327 |
plan tests => 12; |
328 |
|
329 |
$schema->storage->txn_begin; |
330 |
|
331 |
my $item = $builder->build_sample_item; |
332 |
my $patron = $builder->build_object( |
333 |
{ |
334 |
class => 'Koha::Patrons', |
335 |
value => { flags => 4 } |
336 |
} |
337 |
); |
338 |
|
339 |
# Make sure we have at least 10 items |
340 |
for ( 1..10 ) { |
341 |
$builder->build_sample_item; |
342 |
} |
343 |
|
344 |
my $nonprivilegedpatron = $builder->build_object( |
345 |
{ |
346 |
class => 'Koha::Patrons', |
347 |
value => { flags => 0 } |
348 |
} |
349 |
); |
350 |
|
351 |
my $password = 'thePassword123'; |
352 |
|
353 |
$nonprivilegedpatron->set_password( |
354 |
{ password => $password, skip_validation => 1 } ); |
355 |
|
356 |
my $userid = $nonprivilegedpatron->userid; |
357 |
my $itemid = $item->id; |
358 |
my $patronid = $patron->id; |
359 |
|
360 |
$t->get_ok( "//$userid:$password@/api/v1/items/$itemid/checkout/$patronid" ) |
361 |
->status_is(403) |
362 |
->json_is( |
363 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
364 |
|
365 |
$t->get_ok( "//$userid:$password@/api/v1/items/" . $non_existent_code ) |
366 |
->status_is(404) |
367 |
->json_is( |
368 |
'/error' => 'Item not found' ); |
369 |
|
370 |
$userid = $patron->userid; |
371 |
|
372 |
$t->get_ok( "//$userid:$password@/api/v1/items?_per_page=10" ) |
373 |
->status_is( 200, 'SWAGGER3.2.2' ); |
374 |
|
375 |
my $response_count = scalar @{ $t->tx->res->json }; |
376 |
|
377 |
is( $response_count, 10, 'The API returns 10 items' ); |
378 |
|
379 |
$t->get_ok( "//$userid:$password@/api/v1/items?external_id=" . $item->barcode ) |
380 |
->status_is(200) |
381 |
->json_is( '' => [ $item->to_api ], 'SWAGGER3.3.2'); |
382 |
|
383 |
my $barcode = $item->barcode; |
384 |
$item->delete; |
385 |
|
386 |
$t->get_ok( "//$userid:$password@/api/v1/items?external_id=" . $item->barcode ) |
387 |
->status_is(200) |
388 |
->json_is( '' => [] ); |
389 |
|
390 |
$schema->storage->txn_rollback; |
391 |
}; |