|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 101; |
20 |
use Test::More tests => 102; |
| 21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
| 22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
| 23 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
|
Lines 375-380
subtest 'add checkout' => sub {
Link Here
|
| 375 |
|
375 |
|
| 376 |
my $item1 = $builder->build_sample_item; |
376 |
my $item1 = $builder->build_sample_item; |
| 377 |
my $item1_id = $item1->id; |
377 |
my $item1_id = $item1->id; |
|
|
378 |
my $item2 = $builder->build_sample_item; |
| 379 |
my $item2_id = $item2->id; |
| 378 |
|
380 |
|
| 379 |
my %issuingimpossible = (); |
381 |
my %issuingimpossible = (); |
| 380 |
my %needsconfirmation = (); |
382 |
my %needsconfirmation = (); |
|
Lines 420-426
subtest 'add checkout' => sub {
Link Here
|
| 420 |
); |
422 |
); |
| 421 |
$t->post_ok( |
423 |
$t->post_ok( |
| 422 |
"//$userid:$password@/api/v1/checkouts?confirmation=$token" => json => { |
424 |
"//$userid:$password@/api/v1/checkouts?confirmation=$token" => json => { |
| 423 |
item_id => $item1_id, |
425 |
item_id => $item2_id, |
| 424 |
patron_id => $patron_id |
426 |
patron_id => $patron_id |
| 425 |
} |
427 |
} |
| 426 |
)->status_is(201)->or(sub { diag $t->tx->res->body }); |
428 |
)->status_is(201)->or(sub { diag $t->tx->res->body }); |
|
Lines 428-430
subtest 'add checkout' => sub {
Link Here
|
| 428 |
|
430 |
|
| 429 |
$schema->storage->txn_rollback; |
431 |
$schema->storage->txn_rollback; |
| 430 |
}; |
432 |
}; |
| 431 |
- |
433 |
|
|
|
434 |
subtest 'delete checkout' => sub { |
| 435 |
|
| 436 |
plan tests => 11; |
| 437 |
|
| 438 |
$schema->storage->txn_begin; |
| 439 |
my $librarian = $builder->build_object( |
| 440 |
{ |
| 441 |
class => 'Koha::Patrons', |
| 442 |
value => { flags => 2 } |
| 443 |
} |
| 444 |
); |
| 445 |
my $password = 'thePassword123'; |
| 446 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 447 |
my $userid = $librarian->userid; |
| 448 |
|
| 449 |
my $patron = $builder->build_object( |
| 450 |
{ |
| 451 |
class => 'Koha::Patrons', |
| 452 |
value => { flags => 0 } |
| 453 |
} |
| 454 |
); |
| 455 |
my $unauth_password = 'thePassword000'; |
| 456 |
$patron->set_password( |
| 457 |
{ password => $unauth_password, skip_validattion => 1 } ); |
| 458 |
my $unauth_userid = $patron->userid; |
| 459 |
|
| 460 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 461 |
my $library_id = $branch->id; |
| 462 |
my $item1 = $builder->build_sample_item; |
| 463 |
my $item1_id = $item1->id; |
| 464 |
|
| 465 |
|
| 466 |
$t->delete_ok( |
| 467 |
"//$unauth_userid:$unauth_password@/api/v1/checkouts" => json => |
| 468 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(403) |
| 469 |
->json_is( |
| 470 |
{ |
| 471 |
error => "Authorization failure. Missing required permission(s).", |
| 472 |
required_permissions => |
| 473 |
{ circulate => "circulate_remaining_permissions" } |
| 474 |
} |
| 475 |
); |
| 476 |
|
| 477 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
| 478 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(400) |
| 479 |
->json_is( |
| 480 |
'/error' => 'Item not checked out' ); |
| 481 |
|
| 482 |
AddIssue( $patron->unblessed, $item1->barcode ); |
| 483 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
| 484 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(201); |
| 485 |
|
| 486 |
$item1->delete; |
| 487 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts/" => json => |
| 488 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(409) |
| 489 |
->json_is( |
| 490 |
'/error' => 'Item not found' ); |
| 491 |
$schema->storage->txn_rollback; |
| 492 |
}; |