| 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 |  | 
            
              | 23 | use t::lib::TestBuilder; | 
            
              | 24 | use t::lib::Mocks; | 
            
              | 25 | use t::lib::Dates; | 
            
              | 26 |  | 
            
              | 27 | use C4::Auth; | 
            
              | 28 | use Koha::Database; | 
            
              | 29 |  | 
            
              | 30 | use JSON qw(encode_json); | 
            
              | 31 |  | 
            
              | 32 | my $schema  = Koha::Database->new->schema; | 
            
              | 33 | my $builder = t::lib::TestBuilder->new; | 
            
              | 34 |  | 
            
              | 35 | my $t = Test::Mojo->new('Koha::REST::V1'); | 
            
              | 36 | t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); | 
            
              | 37 |  | 
            
              | 38 | subtest 'list() tests' => sub { | 
            
              | 39 |  | 
            
              | 40 |     plan tests => 7; | 
            
              | 41 |  | 
            
              | 42 |     $schema->storage->txn_begin; | 
            
              | 43 |  | 
            
              | 44 |     # delete all patrons | 
            
              | 45 |     Koha::Patrons->search->delete; | 
            
              | 46 |  | 
            
              | 47 |     # delete all categories | 
            
              | 48 |     Koha::Patron::Categories->search->delete; | 
            
              | 49 |  | 
            
              | 50 |     $builder->build_object( | 
            
              | 51 |         { | 
            
              | 52 |             class => 'Koha::Patron::Categories', | 
            
              | 53 |             value => { categorycode => 'TEST', description => 'Test' } | 
            
              | 54 |         } | 
            
              | 55 |     ); | 
            
              | 56 |  | 
            
              | 57 |     my $librarian = $builder->build_object( | 
            
              | 58 |         { | 
            
              | 59 |             class => 'Koha::Patrons', | 
            
              | 60 |             value => { flags => 2**3, categorycode => 'TEST' }    # parameters flag = 3 | 
            
              | 61 |         } | 
            
              | 62 |     ); | 
            
              | 63 |  | 
            
              | 64 |     my $password = 'thePassword123'; | 
            
              | 65 |     $librarian->set_password( { password => $password, skip_validation => 1 } ); | 
            
              | 66 |     my $userid = $librarian->userid; | 
            
              | 67 |  | 
            
              | 68 |     $t->get_ok("//$userid:$password@/api/v1/patron_categories")->status_is(200); | 
            
              | 69 |  | 
            
              | 70 |     $t->get_ok("//$userid:$password@/api/v1/patron_categories")->status_is(200)->json_has('/0/name') | 
            
              | 71 |         ->json_is( '/0/name' => 'Test' )->json_hasnt('/1'); | 
            
              | 72 |  | 
            
              | 73 |     $schema->storage->txn_rollback; | 
            
              | 74 |  | 
            
              | 75 | }; |