Line 0
Link Here
|
0 |
- |
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 |
use Test::Warn; |
23 |
|
24 |
use t::lib::TestBuilder; |
25 |
use t::lib::Mocks; |
26 |
|
27 |
use List::Util qw(min); |
28 |
|
29 |
use Koha::Library::Groups; |
30 |
use Koha::Database; |
31 |
|
32 |
my $schema = Koha::Database->new->schema; |
33 |
my $builder = t::lib::TestBuilder->new; |
34 |
|
35 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
36 |
|
37 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
38 |
|
39 |
subtest 'list() tests' => sub { |
40 |
plan tests => 3; |
41 |
|
42 |
$schema->storage->txn_begin; |
43 |
|
44 |
my $patron = $builder->build_object( |
45 |
{ |
46 |
class => 'Koha::Patrons', |
47 |
value => { flags => 4 } |
48 |
} |
49 |
); |
50 |
my $password = 'thePassword123'; |
51 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
52 |
my $userid = $patron->userid; |
53 |
|
54 |
my $root_group1 = Koha::Library::Group->new( |
55 |
{ |
56 |
title => "LibGroup1", |
57 |
} |
58 |
)->store(); |
59 |
|
60 |
my $lg1groupA = |
61 |
Koha::Library::Group->new( { parent_id => $root_group1->id, title => 'LibGroup1 SubGroupA' } )->store(); |
62 |
my $lg1groupA1 = |
63 |
Koha::Library::Group->new( { parent_id => $lg1groupA->id, title => 'LibGroup1 SubGroupA SubGroup1' } )->store(); |
64 |
my $lg1groupA2 = |
65 |
Koha::Library::Group->new( { parent_id => $lg1groupA->id, title => 'LibGroup1 SubGroupA SubGroup2' } )->store(); |
66 |
my $lg1groupB = |
67 |
Koha::Library::Group->new( { parent_id => $root_group1->id, title => 'LibGroup1 SubGroupB' } )->store(); |
68 |
|
69 |
|
70 |
## Authorized user tests |
71 |
# Make sure we are returned with the correct amount of libraries |
72 |
$t->get_ok("//$userid:$password@/api/v1/library_groups")->status_is( 200, 'SWAGGER3.2.2' ); |
73 |
|
74 |
my $response_count = scalar @{ $t->tx->res->json }; |
75 |
my $expected_count = Koha::Library::Groups->count; |
76 |
is( $response_count, $expected_count, 'Results count is as expected' ); |
77 |
|
78 |
$schema->storage->txn_rollback; |
79 |
}; |