Bug 23154: Add pagination to /api/v1/checkouts
authorJulian Maurice <julian.maurice@biblibre.com>
Wed, 19 Jun 2019 09:10:14 +0000 (11:10 +0200)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 24 Jun 2019 15:14:42 +0000 (16:14 +0100)
Allow to use _page and _per_page query parameters for
/api/v1/checkouts
Also fix a timezone problem in t/db_dependent/api/v1/checkouts.t

Test plan:
1. With your favorite REST tester tool, or directly in the browser,
   fetch http://koha/api/v1/checkouts and check that you have results
2. Fetch /api/v1/checkouts?_per_page=1&_page=1 and check that only the
   first result is returned. Check that response contains headers
   X-Total-Count and Link
3. Fetch /api/v1/checkouts?_per_page=1&_page=2 and check that only the
   second result is returned. Check that response contains headers
   X-Total-Count and Link
4. prove t/db_dependent/api/v1/checkouts.t

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

api/v1/swagger/paths/checkouts.json
t/db_dependent/api/v1/checkouts.t

index 6293401..3cb15c4 100644 (file)
@@ -6,6 +6,10 @@
       "tags": ["patrons", "checkouts"],
       "parameters": [{
         "$ref": "../parameters.json#/patron_id_qp"
+      }, {
+        "$ref": "../parameters.json#/page"
+      }, {
+        "$ref": "../parameters.json#/per_page"
       }],
       "produces": [
         "application/json"
index 170bf2b..c4da746 100644 (file)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 53;
+use Test::More tests => 73;
 use Test::MockModule;
 use Test::Mojo;
 use t::lib::Mocks;
@@ -110,6 +110,28 @@ $t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id")
   ->json_is('/1/due_date' => output_pref({ dateformat => "rfc3339", dt => $date_due2 }) )
   ->json_hasnt('/2');
 
+$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id&_per_page=1&_page=1")
+  ->status_is(200)
+  ->header_is('X-Total-Count', '2')
+  ->header_like('Link', qr|rel="next"|)
+  ->header_like('Link', qr|rel="first"|)
+  ->header_like('Link', qr|rel="last"|)
+  ->json_is('/0/patron_id' => $patron_id)
+  ->json_is('/0/item_id' => $item1->itemnumber)
+  ->json_is('/0/due_date' => output_pref({ dateformat => "rfc3339", dt => $date_due1 }) )
+  ->json_hasnt('/1');
+
+$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id&_per_page=1&_page=2")
+  ->status_is(200)
+  ->header_is('X-Total-Count', '2')
+  ->header_like('Link', qr|rel="prev"|)
+  ->header_like('Link', qr|rel="first"|)
+  ->header_like('Link', qr|rel="last"|)
+  ->json_is('/0/patron_id' => $patron_id)
+  ->json_is('/0/item_id' => $item2->itemnumber)
+  ->json_is('/0/due_date' => output_pref({ dateformat => "rfc3339", dt => $date_due2 }) )
+  ->json_hasnt('/1');
+
 $t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id)
   ->status_is(200)
   ->json_is('/patron_id' => $patron_id)
@@ -132,7 +154,10 @@ $dbh->do(q{
     VALUES (?, ?, ?, ?, ?)
 }, {}, '*', '*', '*', 7, 1);
 
-my $expected_datedue = DateTime->now->add(days => 14)->set(hour => 23, minute => 59, second => 0);
+my $expected_datedue = DateTime->now
+    ->set_time_zone('local')
+    ->add(days => 14)
+    ->set(hour => 23, minute => 59, second => 0);
 $t->post_ok ( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id . "/renewal" )
   ->status_is(201)
   ->json_is('/due_date' => output_pref( { dateformat => "rfc3339", dt => $expected_datedue }) )