3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 1;
25 use t::lib::TestBuilder;
30 my $schema = Koha::Database->new->schema;
31 my $builder = t::lib::TestBuilder->new;
33 my $t = Test::Mojo->new('Koha::REST::V1');
34 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
36 subtest 'unhandled_exception() tests' => sub {
40 $schema->storage->txn_begin;
42 my $authorized_patron = $builder->build_object(
44 class => 'Koha::Patrons',
45 value => { flags => 2**4 } # borrowers flag = 4
48 my $password = 'thePassword123';
49 $authorized_patron->set_password(
50 { password => $password, skip_validation => 1 } );
51 my $userid = $authorized_patron->userid;
53 my $message = 'delete died';
55 my $mock_patron = Test::MockModule->new('Koha::Patron');
56 $mock_patron->mock( 'delete', sub { Koha::Exceptions::Exception->throw($message); } );
58 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
60 $t->delete_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id )
63 { error => 'Something went wrong, check Koha logs for details.',
64 error_code => 'internal_server_error',
68 $schema->storage->txn_rollback;