Bug 18589: (follow-up) Add borrowernumber test
authorAndrew Isherwood <andrew.isherwood@ptfs-europe.com>
Tue, 12 Mar 2019 09:19:56 +0000 (09:19 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 22 Mar 2019 20:21:49 +0000 (20:21 +0000)
As per comment #21:
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=18589#c21

We now test borrowernumber filter works. This test has come from
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=83184&action=diff
and will be removed from that bug

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

t/db_dependent/api/v1/illrequests.t

index a002881..fefb96d 100644 (file)
@@ -40,7 +40,7 @@ my $t              = Test::Mojo->new('Koha::REST::V1');
 
 subtest 'list() tests' => sub {
 
-    plan tests => 21;
+    plan tests => 24;
 
     # Mock ILLBackend (as object)
     my $backend = Test::MockObject->new;
@@ -81,7 +81,8 @@ subtest 'list() tests' => sub {
     $t->request_ok($tx)->status_is(200)->json_is( [] );
 
     my $library = $builder->build_object( { class => 'Koha::Libraries' } );
-    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
+    my $patron_1  = $builder->build_object( { class => 'Koha::Patrons' } );
+    my $patron_2  = $builder->build_object( { class => 'Koha::Patrons' } );
 
     # Create an ILL request
     my $illrequest = $builder->build_object(
@@ -90,7 +91,7 @@ subtest 'list() tests' => sub {
             value => {
                 backend        => 'Mock',
                 branchcode     => $library->branchcode,
-                borrowernumber => $patron->borrowernumber
+                borrowernumber => $patron_1->borrowernumber
             }
         }
     );
@@ -114,7 +115,7 @@ subtest 'list() tests' => sub {
     $tx->req->env( { REMOTE_ADDR => $remote_address } );
     $t->request_ok($tx)->status_is(200)
         ->json_has( '/0/patron', 'patron embedded' )
-        ->json_is( '/0/patron/patron_id', $patron->borrowernumber, 'The right patron is embeded')
+        ->json_is( '/0/patron/patron_id', $patron_1->borrowernumber, 'The right patron is embeded')
         ->json_has( '/0/requested_partners', 'requested_partners embedded' )
         ->json_has( '/0/capabilities', 'capabilities embedded' )
         ->json_has( '/0/library', 'library embedded'  )
@@ -128,7 +129,7 @@ subtest 'list() tests' => sub {
             value => {
                 backend        => 'Mock',
                 branchcode     => $library->branchcode,
-                borrowernumber => $patron->borrowernumber
+                borrowernumber => $patron_2->borrowernumber
             }
         }
     );
@@ -154,6 +155,13 @@ subtest 'list() tests' => sub {
         [{ path => '/query/request_blah', message => 'Malformed query string'}]
     );
 
+    # Test the borrowernumber parameter
+    $tx = $t->ua->build_tx( GET => '/api/v1/illrequests?borrowernumber=' .
+        $patron_2->borrowernumber );
+    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
+    $tx->req->env( { REMOTE_ADDR => $remote_address } );
+    $t->request_ok($tx)->status_is(200)->json_is( [ $response2 ] );
+
     $schema->storage->txn_rollback;
 };