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 361-366
subtest 'add checkout' => sub {
Link Here
|
361 |
|
361 |
|
362 |
my $item1 = $builder->build_sample_item; |
362 |
my $item1 = $builder->build_sample_item; |
363 |
my $item1_id = $item1->id; |
363 |
my $item1_id = $item1->id; |
|
|
364 |
my $item2 = $builder->build_sample_item; |
365 |
my $item2_id = $item2->id; |
364 |
|
366 |
|
365 |
my %issuingimpossible = (); |
367 |
my %issuingimpossible = (); |
366 |
my %needsconfirmation = (); |
368 |
my %needsconfirmation = (); |
Lines 400-406
subtest 'add checkout' => sub {
Link Here
|
400 |
my $token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maXJtMSI6MSwiY29uZmlybTIiOjF9.4QBpITwnIGOAfohyKjaFDoeBWnGmQTdyJrPn9pavArw"; |
402 |
my $token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maXJtMSI6MSwiY29uZmlybTIiOjF9.4QBpITwnIGOAfohyKjaFDoeBWnGmQTdyJrPn9pavArw"; |
401 |
$t->post_ok( |
403 |
$t->post_ok( |
402 |
"//$userid:$password@/api/v1/checkouts?confirmation=$token" => json => { |
404 |
"//$userid:$password@/api/v1/checkouts?confirmation=$token" => json => { |
403 |
item_id => $item1_id, |
405 |
item_id => $item2_id, |
404 |
patron_id => $patron_id |
406 |
patron_id => $patron_id |
405 |
} |
407 |
} |
406 |
)->status_is(201)->or(sub { diag $t->tx->res->body }); |
408 |
)->status_is(201)->or(sub { diag $t->tx->res->body }); |
Lines 408-410
subtest 'add checkout' => sub {
Link Here
|
408 |
|
410 |
|
409 |
$schema->storage->txn_rollback; |
411 |
$schema->storage->txn_rollback; |
410 |
}; |
412 |
}; |
411 |
- |
413 |
|
|
|
414 |
subtest 'delete checkout' => sub { |
415 |
|
416 |
plan tests => 11; |
417 |
|
418 |
$schema->storage->txn_begin; |
419 |
my $librarian = $builder->build_object( |
420 |
{ |
421 |
class => 'Koha::Patrons', |
422 |
value => { flags => 2 } |
423 |
} |
424 |
); |
425 |
my $password = 'thePassword123'; |
426 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
427 |
my $userid = $librarian->userid; |
428 |
|
429 |
my $patron = $builder->build_object( |
430 |
{ |
431 |
class => 'Koha::Patrons', |
432 |
value => { flags => 0 } |
433 |
} |
434 |
); |
435 |
my $unauth_password = 'thePassword000'; |
436 |
$patron->set_password( |
437 |
{ password => $unauth_password, skip_validattion => 1 } ); |
438 |
my $unauth_userid = $patron->userid; |
439 |
|
440 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
441 |
my $library_id = $branch->id; |
442 |
my $item1 = $builder->build_sample_item; |
443 |
my $item1_id = $item1->id; |
444 |
|
445 |
|
446 |
$t->delete_ok( |
447 |
"//$unauth_userid:$unauth_password@/api/v1/checkouts" => json => |
448 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(403) |
449 |
->json_is( |
450 |
{ |
451 |
error => "Authorization failure. Missing required permission(s).", |
452 |
required_permissions => |
453 |
{ circulate => "circulate_remaining_permissions" } |
454 |
} |
455 |
); |
456 |
|
457 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
458 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(400) |
459 |
->json_is( |
460 |
'/error' => 'Item not checked out' ); |
461 |
|
462 |
AddIssue( $patron->unblessed, $item1->barcode ); |
463 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
464 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(201); |
465 |
|
466 |
$item1->delete; |
467 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts/" => json => |
468 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(409) |
469 |
->json_is( |
470 |
'/error' => 'Item not found' ); |
471 |
$schema->storage->txn_rollback; |
472 |
}; |