Lines 244-250
$schema->storage->txn_rollback;
Link Here
|
244 |
|
244 |
|
245 |
subtest 'get_availability' => sub { |
245 |
subtest 'get_availability' => sub { |
246 |
|
246 |
|
247 |
plan tests => 28; |
247 |
plan tests => 29; |
248 |
|
248 |
|
249 |
$schema->storage->txn_begin; |
249 |
$schema->storage->txn_begin; |
250 |
my $librarian = $builder->build_object( |
250 |
my $librarian = $builder->build_object( |
Lines 346-358
subtest 'get_availability' => sub {
Link Here
|
346 |
), |
346 |
), |
347 |
'Correct token' |
347 |
'Correct token' |
348 |
); |
348 |
); |
|
|
349 |
%needsconfirmation = (); |
350 |
|
351 |
subtest 'public availability' => sub { |
352 |
plan tests => 18; |
353 |
|
354 |
# Available, Not authentication required |
355 |
$t->get_ok( |
356 |
"/api/v1/public/checkouts/availability?item_id=$item1_id&patron_id=$patron_id" |
357 |
)->status_is(200)->json_is( '/blockers' => {} ) |
358 |
->json_is( '/confirms' => {} )->json_is( '/warnings' => {} ) |
359 |
->json_has('/confirmation_token'); |
360 |
|
361 |
# Needs confirmation upgrade to blocker |
362 |
%needsconfirmation = ( TOO_MANY => 1, ISSUED_TO_ANOTHER => 1 ); |
363 |
$t->get_ok( |
364 |
"/api/v1/public/checkouts/availability?item_id=$item1_id&patron_id=$patron_id" |
365 |
)->status_is(200) |
366 |
->json_is( '/blockers' => { TOO_MANY => 1, ISSUED_TO_ANOTHER => 1 } ) |
367 |
->json_is( '/confirms' => {} )->json_is( '/warnings' => {} ) |
368 |
->json_has('/confirmation_token'); |
369 |
%needsconfirmation = (); |
370 |
|
371 |
# Remove personal information from public endpoint |
372 |
%issuingimpossible = ( |
373 |
issued_borrowernumber => 'private', |
374 |
issued_cardnumber => 'private', |
375 |
issued_firstname => 'private', |
376 |
issued_surname => 'private', |
377 |
resborrowernumber => 'private', |
378 |
resbranchcode => 'private', |
379 |
rescardnumber => 'private', |
380 |
reserve_id => 'private', |
381 |
resfirstname => 'private', |
382 |
resreservedate => 'private', |
383 |
ressurname => 'private', |
384 |
item_notforloan => 'private' |
385 |
); |
386 |
%alerts = ( |
387 |
issued_borrowernumber => 'private', |
388 |
issued_cardnumber => 'private', |
389 |
issued_firstname => 'private', |
390 |
issued_surname => 'private', |
391 |
resborrowernumber => 'private', |
392 |
resbranchcode => 'private', |
393 |
rescardnumber => 'private', |
394 |
reserve_id => 'private', |
395 |
resfirstname => 'private', |
396 |
resreservedate => 'private', |
397 |
ressurname => 'private', |
398 |
item_notforloan => 'private' |
399 |
); |
400 |
|
401 |
%needsconfirmation = ( |
402 |
issued_borrowernumber => 'private', |
403 |
issued_cardnumber => 'private', |
404 |
issued_firstname => 'private', |
405 |
issued_surname => 'private', |
406 |
resborrowernumber => 'private', |
407 |
resbranchcode => 'private', |
408 |
rescardnumber => 'private', |
409 |
reserve_id => 'private', |
410 |
resfirstname => 'private', |
411 |
resreservedate => 'private', |
412 |
ressurname => 'private', |
413 |
item_notforloan => 'private' |
414 |
); |
415 |
$t->get_ok( |
416 |
"/api/v1/public/checkouts/availability?item_id=$item1_id&patron_id=$patron_id" |
417 |
)->status_is(200)->json_is( '/blockers' => {} ) |
418 |
->json_is( '/confirms' => {} )->json_is( '/warnings' => {} ) |
419 |
->json_has('/confirmation_token'); |
420 |
%issuingimpossible = (); |
421 |
%alerts = (); |
422 |
%needsconfirmation = (); |
423 |
}; |
349 |
|
424 |
|
350 |
$schema->storage->txn_rollback; |
425 |
$schema->storage->txn_rollback; |
351 |
}; |
426 |
}; |
352 |
|
427 |
|
353 |
subtest 'add checkout' => sub { |
428 |
subtest 'add checkout' => sub { |
354 |
|
429 |
|
355 |
plan tests => 9; |
430 |
plan tests => 10; |
356 |
|
431 |
|
357 |
$schema->storage->txn_begin; |
432 |
$schema->storage->txn_begin; |
358 |
my $librarian = $builder->build_object( |
433 |
my $librarian = $builder->build_object( |
Lines 432-436
subtest 'add checkout' => sub {
Link Here
|
432 |
)->status_is(201)->or(sub { diag $t->tx->res->body }); |
507 |
)->status_is(201)->or(sub { diag $t->tx->res->body }); |
433 |
%needsconfirmation = (); |
508 |
%needsconfirmation = (); |
434 |
|
509 |
|
|
|
510 |
subtest 'public add' => sub { |
511 |
plan tests => 14; |
512 |
|
513 |
my $useridp = $patron->userid; |
514 |
$patron->set_password( |
515 |
{ password => $password, skip_validation => 1 } ); |
516 |
|
517 |
# Feature disabled |
518 |
t::lib::Mocks::mock_preference( 'OpacTrustedCheckout', 0 ); |
519 |
|
520 |
$t->post_ok( "/api/v1/public/patrons/$patron_id/checkouts" => json => |
521 |
{ item_id => $item1_id, patron_id => $patron_id } ) |
522 |
->status_is(401)->json_is( |
523 |
{ |
524 |
error => "Authentication failure." |
525 |
} |
526 |
); |
527 |
|
528 |
$t->post_ok( |
529 |
"//$useridp:$password@/api/v1/public/patrons/$patron_id/checkouts" |
530 |
=> json => { item_id => $item1_id, patron_id => $patron_id } ) |
531 |
->status_is(405) |
532 |
->json_is( |
533 |
{ error => "Feature disabled", error_code => "FEATURE_DISABLED" } ); |
534 |
|
535 |
# Feature enabled |
536 |
t::lib::Mocks::mock_preference( 'OpacTrustedCheckout', 1 ); |
537 |
|
538 |
$t->post_ok( "/api/v1/public/patrons/$patron_id/checkouts" => json => |
539 |
{ item_id => $item1_id, patron_id => $patron_id } ) |
540 |
->status_is(401)->json_is( |
541 |
{ |
542 |
error => "Authentication failure." |
543 |
} |
544 |
); |
545 |
|
546 |
$t->post_ok( |
547 |
"//$userid:$password@/api/v1/public/patrons/$patron_id/checkouts" |
548 |
=> json => { item_id => $item1_id, patron_id => $patron_id } ) |
549 |
->status_is(403)->json_is( |
550 |
{ |
551 |
error => |
552 |
"Authorization failure. Missing required permission(s).", |
553 |
required_permissions => undef |
554 |
} |
555 |
); |
556 |
|
557 |
$t->post_ok( |
558 |
"//$useridp:$password@/api/v1/public/patrons/$patron_id/checkouts" |
559 |
=> json => { item_id => $item1_id, patron_id => $patron_id } ) |
560 |
->status_is(201); |
561 |
}; |
562 |
|
435 |
$schema->storage->txn_rollback; |
563 |
$schema->storage->txn_rollback; |
436 |
}; |
564 |
}; |
437 |
- |
|
|