Bug 24680: Fix end_date returned from api/v1/holds/{hold_id}/suspension endpoint
authorEre Maijala <ere.maijala@helsinki.fi>
Wed, 19 Feb 2020 09:45:04 +0000 (11:45 +0200)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 26 Feb 2020 20:40:27 +0000 (20:40 +0000)
Before this patch the response would return current date as the suspension end date for a hold that is suspended with no end date.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/REST/V1/Holds.pm
t/db_dependent/api/v1/holds.t

index dcc4679..a806d67 100644 (file)
@@ -309,15 +309,19 @@ sub suspend {
         $hold->suspend_hold($date);
         $hold->discard_changes;
         $c->res->headers->location( $c->req->url->to_string );
+        my $suspend_end_date;
+        if ($hold->suspend_until) {
+            $suspend_end_date = output_pref({
+                dt         => dt_from_string( $hold->suspend_until ),
+                dateformat => 'rfc3339',
+                dateonly   => 1
+                }
+            );
+        }
         return $c->render(
             status  => 201,
             openapi => {
-                end_date => output_pref(
-                    {   dt         => dt_from_string( $hold->suspend_until ),
-                        dateformat => 'rfc3339',
-                        dateonly   => 1
-                    }
-                )
+                end_date => $suspend_end_date
             }
         );
     }
index bb98700..df10cbc 100644 (file)
@@ -375,7 +375,7 @@ $schema->storage->txn_rollback;
 
 subtest 'suspend and resume tests' => sub {
 
-    plan tests => 21;
+    plan tests => 24;
 
     $schema->storage->txn_begin;
 
@@ -403,14 +403,27 @@ subtest 'suspend and resume tests' => sub {
     $hold->discard_changes;    # refresh object
 
     ok( $hold->is_suspended, 'Hold is suspended' );
+    $t->json_is('/end_date', undef, 'Hold suspension has no end date');
+
+    my $end_date = output_pref({
+      dt         => dt_from_string( undef ),
+      dateformat => 'rfc3339',
+      dateonly   => 1
+    });
+
+    $t->post_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" => json => { end_date => $end_date } );
+
+    $hold->discard_changes;    # refresh object
+
+    ok( $hold->is_suspended, 'Hold is suspended' );
     $t->json_is(
-        '/end_date',
-        output_pref(
-            {   dt         => dt_from_string( $hold->suspend_until ),
-                dateformat => 'rfc3339',
-                dateonly   => 1
-            }
-        )
+      '/end_date',
+      output_pref({
+        dt         => dt_from_string( $hold->suspend_until ),
+        dateformat => 'rfc3339',
+        dateonly   => 1
+      }),
+      'Hold suspension has correct end date'
     );
 
     $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )