@@ -, +, @@ --- t/db_dependent/api/v1/checkouts.t | 57 ++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) --- a/t/db_dependent/api/v1/checkouts.t +++ a/t/db_dependent/api/v1/checkouts.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 105; +use Test::More tests => 106; use Test::MockModule; use Test::Mojo; use t::lib::Mocks; @@ -515,3 +515,58 @@ subtest 'add checkout' => sub { $schema->storage->txn_rollback; }; + +subtest 'check in (return)' => sub { + + plan tests => 8; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 2 } + } + ); + my $password = 'thePassword000'; + $patron->set_password( { password => $password, skip_validation => 1 } ); + + my $patron_id = $patron->borrowernumber; + my $user_id = $patron->userid; + + my $item1 = $builder->build_sample_item; + my $item1_id = $item1->id; + + my $branchcode = $item1->homebranch; + my $wrong_branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; + + my $wrong_checkout = $builder->build_object( + { + class => 'Koha::Old::Checkouts', + value => { itemnumber => $item1_id, branchcode => $branchcode, borrowernumber => $patron_id } + } + ); + my $wrong_checkout_id = $wrong_checkout->id; + + my $checkout = $builder->build_object( + { + class => 'Koha::Checkouts', + value => { + itemnumber => $item1_id, branchcode => $branchcode, borrowernumber => $patron_id, note => undef, + notedate => undef, noteseen => undef + } + } + ); + my $checkout_id = $checkout->id; + + $t->post_ok("//$user_id:$password@/api/v1/checkouts/$wrong_checkout_id/checkin/$branchcode")->status_is(400); + + $t->post_ok("//$user_id:$password@/api/v1/checkouts/$checkout_id/checkin")->status_is(404); + + t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); + $t->post_ok("//$user_id:$password@/api/v1/checkouts/$checkout_id/checkin/$wrong_branchcode")->status_is(403); + + $t->post_ok("//$user_id:$password@/api/v1/checkouts/$checkout_id/checkin/$branchcode")->status_is(201); + + $schema->storage->txn_rollback; +}; --