| 
      
            Lines 116-123
          get '/my_patrons' => sub {
      
      
        Link Here
      
     | 
  
        
          | 116 | 
              );  | 
          116 | 
              );  | 
        
        
          | 117 | 
          };  | 
          117 | 
          };  | 
        
        
          | 118 | 
           | 
          118 | 
           | 
        
            
               | 
               | 
              119 | 
              get '/my_patrons/:patron_id' => sub { | 
            
            
              | 120 | 
               | 
            
            
              | 121 | 
                  my $c = shift;  | 
            
            
              | 122 | 
               | 
            
            
              | 123 | 
                  my $patron_id = $c->param('patron_id'); | 
            
            
              | 124 | 
                  my $patron = $c->objects->find( scalar Koha::Patrons->new, $patron_id );  | 
            
            
              | 125 | 
               | 
            
            
              | 126 | 
                  $c->render(  | 
            
            
              | 127 | 
                      status => 200,  | 
            
            
              | 128 | 
                      json   => $patron  | 
            
            
              | 129 | 
                  );  | 
            
            
              | 130 | 
              };  | 
            
            
              | 131 | 
               | 
            
        
          | 119 | 
          # The tests  | 
          132 | 
          # The tests  | 
        
          
            
              | 120 | 
              use Test::More tests => 14;  | 
              133 | 
              use Test::More tests => 15;  | 
            
        
          | 121 | 
          use Test::Mojo;  | 
          134 | 
          use Test::Mojo;  | 
        
        
          | 122 | 
           | 
          135 | 
           | 
        
        
          | 123 | 
          use t::lib::Mocks;  | 
          136 | 
          use t::lib::Mocks;  | 
        
  
    | 
      
            Lines 618-620
          subtest 'objects.search helper, search_limited() tests' => sub {
      
      
        Link Here
      
     | 
  
        
          | 618 | 
           | 
          631 | 
           | 
        
        
          | 619 | 
              $schema->storage->txn_rollback;  | 
          632 | 
              $schema->storage->txn_rollback;  | 
        
        
          | 620 | 
          };  | 
          633 | 
          };  | 
        
          
            
              | 621 | 
              -   | 
              634 | 
               | 
            
            
               | 
               | 
              635 | 
              subtest 'objects.find helper, search_limited() tests' => sub { | 
            
            
              | 636 | 
               | 
            
            
              | 637 | 
                  plan tests => 12;  | 
            
            
              | 638 | 
               | 
            
            
              | 639 | 
                  $schema->storage->txn_begin;  | 
            
            
              | 640 | 
               | 
            
            
              | 641 | 
                  my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); | 
            
            
              | 642 | 
                  my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); | 
            
            
              | 643 | 
               | 
            
            
              | 644 | 
                  my $patron_1 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_1->id } }); | 
            
            
              | 645 | 
                  my $patron_2 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_2->id } }); | 
            
            
              | 646 | 
               | 
            
            
              | 647 | 
                  my @libraries_where_can_see_patrons = ( $library_1->id, $library_2->id );  | 
            
            
              | 648 | 
               | 
            
            
              | 649 | 
                  my $t = Test::Mojo->new;  | 
            
            
              | 650 | 
               | 
            
            
              | 651 | 
                  my $mocked_patron = Test::MockModule->new('Koha::Patron'); | 
            
            
              | 652 | 
                  $mocked_patron->mock( 'libraries_where_can_see_patrons', sub  | 
            
            
              | 653 | 
                      { | 
            
            
              | 654 | 
                          return @libraries_where_can_see_patrons;  | 
            
            
              | 655 | 
                      }  | 
            
            
              | 656 | 
                  );  | 
            
            
              | 657 | 
               | 
            
            
              | 658 | 
                  my $patron = $builder->build_object({ class => 'Koha::Patrons' }); | 
            
            
              | 659 | 
               | 
            
            
              | 660 | 
                  t::lib::Mocks::mock_userenv({ patron => $patron }); | 
            
            
              | 661 | 
               | 
            
            
              | 662 | 
                  $t->get_ok( "/my_patrons/" . $patron_1->id )  | 
            
            
              | 663 | 
                    ->status_is(200)  | 
            
            
              | 664 | 
                    ->json_is( '/patron_id' => $patron_1->id );  | 
            
            
              | 665 | 
               | 
            
            
              | 666 | 
                  $t->get_ok( "/my_patrons/" . $patron_2->id )  | 
            
            
              | 667 | 
                    ->status_is(200)  | 
            
            
              | 668 | 
                    ->json_is( '/patron_id' => $patron_2->id );  | 
            
            
              | 669 | 
               | 
            
            
              | 670 | 
                  @libraries_where_can_see_patrons = ( $library_2->id );  | 
            
            
              | 671 | 
               | 
            
            
              | 672 | 
                  $t->get_ok( "/my_patrons/" . $patron_1->id )  | 
            
            
              | 673 | 
                    ->status_is(200)  | 
            
            
              | 674 | 
                    ->json_is( undef );  | 
            
            
              | 675 | 
               | 
            
            
              | 676 | 
                  $t->get_ok( "/my_patrons/" . $patron_2->id )  | 
            
            
              | 677 | 
                    ->status_is(200)  | 
            
            
              | 678 | 
                    ->json_is( '/patron_id' => $patron_2->id );  | 
            
            
              | 679 | 
               | 
            
            
              | 680 | 
                  $schema->storage->txn_rollback;  | 
            
            
              | 681 | 
              };  |