|
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 253-258
subtest 'get_availability' => sub {
Link Here
|
| 253 |
my $patron = $builder->build_object( |
253 |
my $patron = $builder->build_object( |
| 254 |
{ |
254 |
{ |
| 255 |
class => 'Koha::Patrons', |
255 |
class => 'Koha::Patrons', |
|
|
256 |
|
| 256 |
value => { flags => 0 } |
257 |
value => { flags => 0 } |
| 257 |
} |
258 |
} |
| 258 |
); |
259 |
); |
|
Lines 325-330
subtest 'get_availability' => sub {
Link Here
|
| 325 |
)->status_is(200)->json_is( '/blockers' => {} ) |
326 |
)->status_is(200)->json_is( '/blockers' => {} ) |
| 326 |
->json_is( '/confirms' => { confirm1 => 1, confirm2 => 'please' } ) |
327 |
->json_is( '/confirms' => { confirm1 => 1, confirm2 => 'please' } ) |
| 327 |
->json_is( '/warnings' => {} ) |
328 |
->json_is( '/warnings' => {} ) |
|
|
329 |
|
| 328 |
->json_is( '/confirmation_token' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maXJtMSI6MSwiY29uZmlybTIiOjF9.4QBpITwnIGOAfohyKjaFDoeBWnGmQTdyJrPn9pavArw' ); |
330 |
->json_is( '/confirmation_token' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maXJtMSI6MSwiY29uZmlybTIiOjF9.4QBpITwnIGOAfohyKjaFDoeBWnGmQTdyJrPn9pavArw' ); |
| 329 |
|
331 |
|
| 330 |
$schema->storage->txn_rollback; |
332 |
$schema->storage->txn_rollback; |
|
Lines 349-354
subtest 'add checkout' => sub {
Link Here
|
| 349 |
{ |
351 |
{ |
| 350 |
class => 'Koha::Patrons', |
352 |
class => 'Koha::Patrons', |
| 351 |
value => { flags => 0 } |
353 |
value => { flags => 0 } |
|
|
354 |
|
| 352 |
} |
355 |
} |
| 353 |
); |
356 |
); |
| 354 |
my $unauth_password = 'thePassword000'; |
357 |
my $unauth_password = 'thePassword000'; |
|
Lines 362-367
subtest 'add checkout' => sub {
Link Here
|
| 362 |
my $item1 = $builder->build_sample_item; |
365 |
my $item1 = $builder->build_sample_item; |
| 363 |
my $item1_id = $item1->id; |
366 |
my $item1_id = $item1->id; |
| 364 |
|
367 |
|
|
|
368 |
my $item2 = $builder->build_sample_item; |
| 369 |
my $item2_id = $item2->id; |
| 370 |
|
| 365 |
my %issuingimpossible = (); |
371 |
my %issuingimpossible = (); |
| 366 |
my %needsconfirmation = (); |
372 |
my %needsconfirmation = (); |
| 367 |
my %alerts = (); |
373 |
my %alerts = (); |
|
Lines 399-406
subtest 'add checkout' => sub {
Link Here
|
| 399 |
|
405 |
|
| 400 |
my $token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maXJtMSI6MSwiY29uZmlybTIiOjF9.4QBpITwnIGOAfohyKjaFDoeBWnGmQTdyJrPn9pavArw"; |
406 |
my $token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maXJtMSI6MSwiY29uZmlybTIiOjF9.4QBpITwnIGOAfohyKjaFDoeBWnGmQTdyJrPn9pavArw"; |
| 401 |
$t->post_ok( |
407 |
$t->post_ok( |
|
|
408 |
|
| 402 |
"//$userid:$password@/api/v1/checkouts?confirmation=$token" => json => { |
409 |
"//$userid:$password@/api/v1/checkouts?confirmation=$token" => json => { |
| 403 |
item_id => $item1_id, |
410 |
item_id => $item2_id, |
| 404 |
patron_id => $patron_id |
411 |
patron_id => $patron_id |
| 405 |
} |
412 |
} |
| 406 |
)->status_is(201)->or(sub { diag $t->tx->res->body }); |
413 |
)->status_is(201)->or(sub { diag $t->tx->res->body }); |
|
Lines 411-417
subtest 'add checkout' => sub {
Link Here
|
| 411 |
|
418 |
|
| 412 |
subtest 'delete checkout' => sub { |
419 |
subtest 'delete checkout' => sub { |
| 413 |
|
420 |
|
| 414 |
plan tests => 4; |
421 |
plan tests => 11; |
| 415 |
|
422 |
|
| 416 |
$schema->storage->txn_begin; |
423 |
$schema->storage->txn_begin; |
| 417 |
my $librarian = $builder->build_object( |
424 |
my $librarian = $builder->build_object( |
|
Lines 435-470
subtest 'delete checkout' => sub {
Link Here
|
| 435 |
{ password => $unauth_password, skip_validattion => 1 } ); |
442 |
{ password => $unauth_password, skip_validattion => 1 } ); |
| 436 |
my $unauth_userid = $patron->userid; |
443 |
my $unauth_userid = $patron->userid; |
| 437 |
|
444 |
|
| 438 |
my $branch = $builder->build_sample_branch; |
445 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 439 |
my $library_id = $branch->id; |
446 |
my $library_id = $branch->id; |
| 440 |
my $item1 = $builder->build_sample_item; |
447 |
my $item1 = $builder->build_sample_item; |
| 441 |
my $item1_id = $item1->id; |
448 |
my $item1_id = $item1->id; |
| 442 |
|
|
|
| 443 |
|
449 |
|
| 444 |
$t->delete_ok( |
450 |
$t->delete_ok( |
| 445 |
"//$unauth_userid:$unauth_password@/api/v1/checkouts" => json => |
451 |
"//$unauth_userid:$unauth_password@/api/v1/checkouts" => json => |
| 446 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(403) |
452 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(403) |
| 447 |
->json_is( |
453 |
->json_is( |
| 448 |
{ |
454 |
{ |
| 449 |
error => "checkin not allowed", |
455 |
error => "Authorization failure. Missing required permission(s).", |
| 450 |
required_permissions => |
456 |
required_permissions => |
| 451 |
{ circulate => "circulate_remaining_permissions" } |
457 |
{ circulate => "circulate_remaining_permissions" } |
| 452 |
} |
458 |
} |
| 453 |
); |
459 |
); |
| 454 |
|
460 |
|
| 455 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
461 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
| 456 |
{ item_id => $item1_id, patron_id => $library_id } )->status_is(400) |
462 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(400) |
| 457 |
->json_is( |
463 |
->json_is( |
| 458 |
'/error' => 'Item not checked out' ); |
464 |
'/error' => 'Item not checked out' ); |
| 459 |
|
465 |
|
| 460 |
AddIssue( $patron, $item1->barcode ); |
466 |
AddIssue( $patron->unblessed, $item1->barcode ); |
| 461 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
467 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => |
| 462 |
{ item_id => $item1_id, patron_id => $library_id } )->status_is(201); |
468 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(201); |
| 463 |
|
469 |
|
| 464 |
$item1->delete; |
470 |
$item1->delete; |
| 465 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts/" => json => |
471 |
$t->delete_ok( "//$userid:$password@/api/v1/checkouts/" => json => |
| 466 |
{ item_id => $item1_id, patron_id => $library_id } )->status_is(409) |
472 |
{ item_id => $item1_id, library_id => $library_id } )->status_is(409) |
| 467 |
->json_is( |
473 |
->json_is( |
| 468 |
'/error' => 'Item not found' ); |
474 |
'/error' => 'Item not found' ); |
|
|
475 |
|
| 469 |
$schema->storage->txn_rollback; |
476 |
$schema->storage->txn_rollback; |
| 470 |
}; |
477 |
}; |
| 471 |
- |
|
|