Bug 30642: Make renewal_type an enum in spec and add test
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 10 Feb 2023 12:35:01 +0000 (09:35 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 10 Feb 2023 14:08:00 +0000 (11:08 -0300)
This patch makes the renewal_type an enum, to match the change on the
DB. A test is added to account the fact the API is always setting
'Manual' request type.

Bonus: small portion of code gets a tidy, should've been asked by QA.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Circulation.pm
api/v1/swagger/definitions/renewal.yaml
t/db_dependent/api/v1/checkouts.t

index 1421c78..547c89d 100644 (file)
@@ -3208,11 +3208,11 @@ sub AddRenewal {
         # Add renewal record
         my $renewal = Koha::Checkouts::Renewal->new(
             {
-                checkout_id => $issue->issue_id,
-                renewer_id  => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef,
-                seen        => $seen,
-                interface   => C4::Context->interface,
-                renewal_type => $renewal_type
+                checkout_id  => $issue->issue_id,
+                interface    => C4::Context->interface,
+                renewal_type => $renewal_type,
+                renewer_id   => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef,
+                seen         => $seen,
             }
         )->store();
 
index 895fe48..0e27e23 100644 (file)
@@ -32,6 +32,9 @@ properties:
     type:
       - string
       - "null"
+    enum:
+      - Automatic
+      - Manual
   renewer:
     type:
       - object
index f95abf1..8c58dd2 100755 (executable)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 98;
+use Test::More tests => 99;
 use Test::MockModule;
 use Test::Mojo;
 use t::lib::Mocks;
@@ -182,11 +182,15 @@ my $expected_datedue = $date_due
     ->set_time_zone('local')
     ->add(days => 7)
     ->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 }) )
   ->header_is(Location => "/api/v1/checkouts/" . $issue1->issue_id . "/renewal");
 
+my $renewal = $issue1->renewals->last;
+is( $renewal->renewal_type, 'Manual', 'Manual renewal recorded' );
+
 $t->get_ok ( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id . "/renewals" )
   ->status_is(200)
   ->json_is('/0/checkout_id' => $issue1->issue_id)