View | Details | Raw Unified | Return to bug 38291
Collapse All | Expand All

(-)a/t/db_dependent/api/v1/library_groups.t (-1 / +79 lines)
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 <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
use Test::Mojo;
22
use Test::Warn;
23
use Test::NoWarnings;
24
25
use t::lib::TestBuilder;
26
use t::lib::Mocks;
27
28
use List::Util qw(min);
29
30
use Koha::Library::Groups;
31
use Koha::Database;
32
33
my $schema  = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
35
36
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
37
38
my $t = Test::Mojo->new('Koha::REST::V1');
39
40
subtest 'list() tests' => sub {
41
    plan tests => 3;
42
43
    $schema->storage->txn_begin;
44
45
    my $patron = $builder->build_object(
46
        {
47
            class => 'Koha::Patrons',
48
            value => { flags => 4 }
49
        }
50
    );
51
    my $password = 'thePassword123';
52
    $patron->set_password( { password => $password, skip_validation => 1 } );
53
    my $userid = $patron->userid;
54
55
    my $root_group1 = Koha::Library::Group->new(
56
        {
57
            title => "LibGroup1",
58
        }
59
    )->store();
60
61
    my $lg1groupA =
62
        Koha::Library::Group->new( { parent_id => $root_group1->id, title => 'LibGroup1 SubGroupA' } )->store();
63
    my $lg1groupA1 =
64
        Koha::Library::Group->new( { parent_id => $lg1groupA->id, title => 'LibGroup1 SubGroupA SubGroup1' } )->store();
65
    my $lg1groupA2 =
66
        Koha::Library::Group->new( { parent_id => $lg1groupA->id, title => 'LibGroup1 SubGroupA SubGroup2' } )->store();
67
    my $lg1groupB =
68
        Koha::Library::Group->new( { parent_id => $root_group1->id, title => 'LibGroup1 SubGroupB' } )->store();
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
};

Return to bug 38291