From c90f60adfcb3aeba3dd81122cce96db2c8d1fc1d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 10 Feb 2023 09:35:01 -0300 Subject: [PATCH] Bug 30642: Make renewal_type an enum in spec and add test 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 --- C4/Circulation.pm | 10 +++++----- api/v1/swagger/definitions/renewal.yaml | 3 +++ t/db_dependent/api/v1/checkouts.t | 6 +++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 1421c7869b..547c89df48 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -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(); diff --git a/api/v1/swagger/definitions/renewal.yaml b/api/v1/swagger/definitions/renewal.yaml index 895fe4811e..0e27e238ce 100644 --- a/api/v1/swagger/definitions/renewal.yaml +++ b/api/v1/swagger/definitions/renewal.yaml @@ -32,6 +32,9 @@ properties: type: - string - "null" + enum: + - Automatic + - Manual renewer: type: - object diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t index f95abf10f3..8c58dd217c 100755 --- a/t/db_dependent/api/v1/checkouts.t +++ b/t/db_dependent/api/v1/checkouts.t @@ -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) -- 2.39.5