Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 105; |
20 |
use Test::More tests => 106; |
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 435-440
subtest 'add checkout' => sub {
Link Here
|
435 |
|
435 |
|
436 |
my $item1 = $builder->build_sample_item; |
436 |
my $item1 = $builder->build_sample_item; |
437 |
my $item1_id = $item1->id; |
437 |
my $item1_id = $item1->id; |
|
|
438 |
my $item2 = $builder->build_sample_item; |
439 |
my $item2_id = $item2->id; |
438 |
|
440 |
|
439 |
my %issuingimpossible = (); |
441 |
my %issuingimpossible = (); |
440 |
my %needsconfirmation = (); |
442 |
my %needsconfirmation = (); |
Lines 471-477
subtest 'add checkout' => sub {
Link Here
|
471 |
my $token = Koha::Token->new->generate_jwt( { id => $librarian->id . ":" . $item1_id . ":confirm1:confirm2" } ); |
473 |
my $token = Koha::Token->new->generate_jwt( { id => $librarian->id . ":" . $item1_id . ":confirm1:confirm2" } ); |
472 |
$t->post_ok( |
474 |
$t->post_ok( |
473 |
"//$userid:$password@/api/v1/checkouts?confirmation=$token" => json => { |
475 |
"//$userid:$password@/api/v1/checkouts?confirmation=$token" => json => { |
474 |
item_id => $item1_id, |
476 |
item_id => $item2_id, |
475 |
patron_id => $patron_id |
477 |
patron_id => $patron_id |
476 |
} |
478 |
} |
477 |
)->status_is(201)->or( sub { diag $t->tx->res->body } ); |
479 |
)->status_is(201)->or( sub { diag $t->tx->res->body } ); |
Lines 515-517
subtest 'add checkout' => sub {
Link Here
|
515 |
|
517 |
|
516 |
$schema->storage->txn_rollback; |
518 |
$schema->storage->txn_rollback; |
517 |
}; |
519 |
}; |
518 |
- |
520 |
|
|
|
521 |
subtest 'delete checkout' => sub { |
522 |
|
523 |
plan tests => 11; |
524 |
|
525 |
$schema->storage->txn_begin; |
526 |
my $librarian = $builder->build_object( |
527 |
{ |
528 |
class => 'Koha::Patrons', |
529 |
value => { flags => 2 } |
530 |
} |
531 |
); |
532 |
my $password = 'thePassword123'; |
533 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
534 |
my $userid = $librarian->userid; |
535 |
|
536 |
my $patron = $builder->build_object( |
537 |
{ |
538 |
class => 'Koha::Patrons', |
539 |
value => { flags => 0 } |
540 |
} |
541 |
); |
542 |
my $unauth_password = 'thePassword000'; |
543 |
$patron->set_password( |
544 |
{ password => $unauth_password, skip_validattion => 1 } ); |
545 |
my $unauth_userid = $patron->userid; |
546 |
|
547 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
548 |
my $library_id = $branch->id; |
549 |
my $item1 = $builder->build_sample_item; |
550 |
my $item1_id = $item1->id; |
551 |
|
552 |
|
553 |
$t->delete_ok( |
554 |
"//$unauth_userid:$unauth_password@/api/v1/checkouts" => json => |
555 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(403) |
556 |
->json_is( |
557 |
{ |
558 |
error => "Authorization failure. Missing required permission(s).", |
559 |
required_permissions => |
560 |
{ circulate => "circulate_remaining_permissions" } |
561 |
} |
562 |
); |
563 |
|
564 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
565 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(400) |
566 |
->json_is( |
567 |
'/error' => 'Item not checked out' ); |
568 |
|
569 |
AddIssue( $patron->unblessed, $item1->barcode ); |
570 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
571 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(201); |
572 |
|
573 |
$item1->delete; |
574 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts/" => json => |
575 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(409) |
576 |
->json_is( |
577 |
'/error' => 'Item not found' ); |
578 |
$schema->storage->txn_rollback; |
579 |
}; |