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;
23 use t::lib::TestBuilder;
28 my $schema = Koha::Database->new->schema;
29 my $builder = t::lib::TestBuilder->new();
31 my $t = Test::Mojo->new('Koha::REST::V1');
33 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
35 subtest 'list() tests' => sub {
39 $schema->storage->txn_begin;
41 my $patron = $builder->build_object({
42 class => 'Koha::Patrons',
43 value => { flags => 2 ** 4 } # 'borrowers' flag == 4
45 my $password = 'thePassword123';
46 $patron->set_password({ password => $password, skip_validation => 1 });
47 my $userid = $patron->userid;
49 $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds')
50 ->status_is( 200, 'SWAGGER3.2.2' )
53 my $hold_1 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } });
54 my $hold_2 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } });
56 $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds')
57 ->status_is( 200, 'SWAGGER3.2.2' )
58 ->json_is( '' => [ $hold_1->to_api, $hold_2->to_api ], 'Holds retrieved' );
60 my $non_existent_patron = $builder->build_object({ class => 'Koha::Patrons' });
61 my $non_existent_patron_id = $non_existent_patron->id;
62 # get rid of the patron
63 $non_existent_patron->delete;
65 $t->get_ok("//$userid:$password@/api/v1/patrons/" . $non_existent_patron_id . '/holds')
67 ->json_is( '/error' => 'Patron not found' );
69 $schema->storage->txn_rollback;