|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 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. |
| 9 |
# |
| 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. |
| 14 |
# |
| 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>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::More tests => 1; |
| 21 |
use Test::Mojo; |
| 22 |
|
| 23 |
use t::lib::TestBuilder; |
| 24 |
use t::lib::Mocks; |
| 25 |
|
| 26 |
use JSON qw(encode_json); |
| 27 |
|
| 28 |
use Koha::Database; |
| 29 |
|
| 30 |
my $schema = Koha::Database->new->schema; |
| 31 |
my $builder = t::lib::TestBuilder->new(); |
| 32 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 33 |
|
| 34 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
| 35 |
|
| 36 |
subtest 'list_managers() tests' => sub { |
| 37 |
|
| 38 |
plan tests => 3; |
| 39 |
|
| 40 |
$schema->storage->txn_begin; |
| 41 |
|
| 42 |
my $patron_with_permission = |
| 43 |
$builder->build_object( { class => 'Koha::Patrons', value => { flags => 2**11 } } ) |
| 44 |
; ## 11 == acquisition |
| 45 |
my $patron_without_permission = |
| 46 |
$builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); |
| 47 |
my $superlibrarian = |
| 48 |
$builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
| 49 |
my $password = 'thePassword123'; |
| 50 |
$superlibrarian->set_password( { password => $password, skip_validation => 1 } ); |
| 51 |
my $userid = $superlibrarian->userid; |
| 52 |
|
| 53 |
my $api_filter = encode_json( |
| 54 |
{ 'me.patron_id' => |
| 55 |
[ $patron_with_permission->id, $patron_without_permission->id, $superlibrarian->id ] |
| 56 |
} |
| 57 |
); |
| 58 |
|
| 59 |
$t->get_ok("//$userid:$password@/api/v1/acquisitions/baskets/managers?q=$api_filter") |
| 60 |
->status_is(200)->json_is( [ $patron_with_permission->to_api, $superlibrarian->to_api ] ); |
| 61 |
|
| 62 |
$schema->storage->txn_rollback; |
| 63 |
}; |