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;
30 use JSON qw(encode_json);
32 my $schema = Koha::Database->new->schema;
33 my $builder = t::lib::TestBuilder->new;
35 my $t = Test::Mojo->new('Koha::REST::V1');
36 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
38 subtest 'list() tests' => sub {
42 $schema->storage->txn_begin;
44 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
46 my $category = $builder->build_object(
48 class => 'Koha::Patron::Categories',
49 value => { categorycode => 'TEST', description => 'Test' }
53 $category->add_library_limit( $library->branchcode );
55 my $librarian = $builder->build_object(
57 class => 'Koha::Patrons',
58 value => { flags => 2**3, categorycode => 'TEST', branchcode => $library->branchcode } # parameters flag = 3
62 my $password = 'thePassword123';
63 $librarian->set_password( { password => $password, skip_validation => 1 } );
64 my $userid = $librarian->userid;
66 $t->get_ok("//$userid:$password@/api/v1/patron_categories")->status_is(200);
68 $t->get_ok("//$userid:$password@/api/v1/patron_categories?q={\"me.categorycode\":\"TEST\"}")->status_is(200)
69 ->json_has('/0/name')->json_is( '/0/name' => 'Test' )->json_hasnt('/1');
73 my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } );
75 my $off_limits_category = $builder->build_object(
77 class => 'Koha::Patron::Categories',
78 value => { categorycode => 'CANT', description => 'Cant' }
82 my $off_limits_librarian = $builder->build_object(
84 class => 'Koha::Patrons',
86 { flags => 2**3, categorycode => 'CANT', branchcode => $library_2->branchcode } # parameters flag = 3
89 my $off_limits_password = 'thePassword123';
90 $off_limits_librarian->set_password( { password => $password, skip_validation => 1 } );
91 my $off_limits_userid = $off_limits_librarian->userid;
93 $t->get_ok("//$off_limits_userid:$off_limits_password@/api/v1/patron_categories?q={\"me.categorycode\":\"TEST\"}")
94 ->status_is(200)->json_hasnt('/0');
96 # Off limits librarian category has changed to one within limits
98 $off_limits_librarian->branchcode( $library->branchcode )->store;
100 $t->get_ok("//$off_limits_userid:$off_limits_password@/api/v1/patron_categories?q={\"me.categorycode\":\"TEST\"}")
101 ->status_is(200)->json_has('/0/name')->json_is( '/0/name' => 'Test' )->json_hasnt('/1');
103 $schema->storage->txn_rollback;