| 
      
            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 | 
               | 
            
            
              | 26 | 
              use Koha::Database;  | 
            
            
              | 27 | 
               | 
            
            
              | 28 | 
              my $schema  = Koha::Database->new->schema;  | 
            
            
              | 29 | 
              my $builder = t::lib::TestBuilder->new();  | 
            
            
              | 30 | 
               | 
            
            
              | 31 | 
              my $t = Test::Mojo->new('Koha::REST::V1'); | 
            
            
              | 32 | 
               | 
            
            
              | 33 | 
              t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );  | 
            
            
              | 34 | 
               | 
            
            
              | 35 | 
              subtest 'list() tests' => sub { | 
            
            
              | 36 | 
               | 
            
            
              | 37 | 
                  plan tests => 9;  | 
            
            
              | 38 | 
               | 
            
            
              | 39 | 
                  $schema->storage->txn_begin;  | 
            
            
              | 40 | 
               | 
            
            
              | 41 | 
                  my $patron = $builder->build_object(  | 
            
            
              | 42 | 
                      { | 
            
            
              | 43 | 
                          class => 'Koha::Patrons',  | 
            
            
              | 44 | 
                          value => { flags => 2**27 }    # recalls flag == 27 | 
            
            
              | 45 | 
                      }  | 
            
            
              | 46 | 
                  );  | 
            
            
              | 47 | 
                  my $password = 'thePassword123';  | 
            
            
              | 48 | 
                  $patron->set_password( { password => $password, skip_validation => 1 } ); | 
            
            
              | 49 | 
                  my $userid = $patron->userid;  | 
            
            
              | 50 | 
               | 
            
            
              | 51 | 
                  $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/recalls' )->status_is( 200, 'SWAGGER3.2.2' )  | 
            
            
              | 52 | 
                      ->json_is( [] );  | 
            
            
              | 53 | 
               | 
            
            
              | 54 | 
                  my $recall_1 = $builder->build_object( { class => 'Koha::Recalls', value => { patron_id => $patron->id } } ); | 
            
            
              | 55 | 
                  my $recall_2 = $builder->build_object( { class => 'Koha::Recalls', value => { patron_id => $patron->id } } ); | 
            
            
              | 56 | 
               | 
            
            
              | 57 | 
                  $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/recalls?_order_by=+me.recall_id' )  | 
            
            
              | 58 | 
                      ->status_is( 200, 'SWAGGER3.2.2' )  | 
            
            
              | 59 | 
                      ->json_is( '' => [ $recall_1->to_api, $recall_2->to_api ], 'Recalls retrieved' );  | 
            
            
              | 60 | 
               | 
            
            
              | 61 | 
                  my $non_existent_patron    = $builder->build_object( { class => 'Koha::Patrons' } ); | 
            
            
              | 62 | 
                  my $non_existent_patron_id = $non_existent_patron->id;  | 
            
            
              | 63 | 
               | 
            
            
              | 64 | 
                  # get rid of the patron  | 
            
            
              | 65 | 
                  $non_existent_patron->delete;  | 
            
            
              | 66 | 
               | 
            
            
              | 67 | 
                  $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $non_existent_patron_id . '/recalls' )->status_is(404)  | 
            
            
              | 68 | 
                      ->json_is( '/error' => 'Patron not found' );  | 
            
            
              | 69 | 
               | 
            
            
              | 70 | 
                  $schema->storage->txn_rollback;  | 
            
            
              | 71 | 
              };  |