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 515-517
subtest 'add checkout' => sub {
Link Here
|
515 |
|
515 |
|
516 |
$schema->storage->txn_rollback; |
516 |
$schema->storage->txn_rollback; |
517 |
}; |
517 |
}; |
518 |
- |
518 |
|
|
|
519 |
subtest 'check in (return)' => sub { |
520 |
|
521 |
plan tests => 8; |
522 |
|
523 |
$schema->storage->txn_begin; |
524 |
|
525 |
my $patron = $builder->build_object( |
526 |
{ |
527 |
class => 'Koha::Patrons', |
528 |
value => { flags => 2 } |
529 |
} |
530 |
); |
531 |
my $password = 'thePassword000'; |
532 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
533 |
|
534 |
my $patron_id = $patron->borrowernumber; |
535 |
my $user_id = $patron->userid; |
536 |
|
537 |
my $item1 = $builder->build_sample_item; |
538 |
my $item1_id = $item1->id; |
539 |
|
540 |
my $branchcode = $item1->homebranch; |
541 |
my $wrong_branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
542 |
|
543 |
my $wrong_checkout = $builder->build_object( |
544 |
{ |
545 |
class => 'Koha::Old::Checkouts', |
546 |
value => { itemnumber => $item1_id, branchcode => $branchcode, borrowernumber => $patron_id } |
547 |
} |
548 |
); |
549 |
my $wrong_checkout_id = $wrong_checkout->id; |
550 |
|
551 |
my $checkout = $builder->build_object( |
552 |
{ |
553 |
class => 'Koha::Checkouts', |
554 |
value => { |
555 |
itemnumber => $item1_id, branchcode => $branchcode, borrowernumber => $patron_id, note => undef, |
556 |
notedate => undef, noteseen => undef |
557 |
} |
558 |
} |
559 |
); |
560 |
my $checkout_id = $checkout->id; |
561 |
|
562 |
$t->post_ok("//$user_id:$password@/api/v1/checkouts/$wrong_checkout_id/checkin/$branchcode")->status_is(400); |
563 |
|
564 |
$t->post_ok("//$user_id:$password@/api/v1/checkouts/$checkout_id/checkin")->status_is(404); |
565 |
|
566 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
567 |
$t->post_ok("//$user_id:$password@/api/v1/checkouts/$checkout_id/checkin/$wrong_branchcode")->status_is(403); |
568 |
|
569 |
$t->post_ok("//$user_id:$password@/api/v1/checkouts/$checkout_id/checkin/$branchcode")->status_is(201); |
570 |
|
571 |
$schema->storage->txn_rollback; |
572 |
}; |