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;
26 use Koha::Patron::Attributes;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 my $t = Test::Mojo->new('Koha::REST::V1');
34 subtest 'list() tests' => sub {
38 $schema->storage->txn_begin;
40 Koha::Patrons->search->delete;
42 my $librarian = $builder->build_object(
44 class => 'Koha::Patrons',
45 value => { flags => 2**28 }
49 my $password = 'thePassword123';
50 $librarian->set_password( { password => $password, skip_validation => 1 } );
51 my $userid = $librarian->userid;
55 ## Authorized user tests
56 # One erm_user created, should get returned
57 $librarian->discard_changes;
58 $t->get_ok("//$userid:$password@/api/v1/erm/users")->status_is(200)
59 ->json_is( [ $librarian->to_api ] );
61 my $another_erm_user = $builder->build_object(
63 class => 'Koha::Patrons',
64 value => { flags => 2**28 }
68 # Two erm_users created, they should both be returned
69 $t->get_ok("//$userid:$password@/api/v1/erm/users")->status_is(200)
70 ->json_is( [ $librarian->to_api ] );
72 # Warn on unsupported query parameter
73 $t->get_ok("//$userid:$password@/api/v1/erm/users?blah=blah")
76 [ { path => '/query/blah', message => 'Malformed query string' } ] );
78 my $patron = $builder->build_object(
80 class => 'Koha::Patrons',
81 value => { flags => 0 }
85 $patron->set_password( { password => $password, skip_validation => 1 } );
86 my $unauth_userid = $patron->userid;
88 $t->get_ok("//$unauth_userid:$password@/api/v1/erm/users")->status_is(403);
90 $schema->storage->txn_rollback;