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 <tomascohen@theke.io>
(cherry picked from commit c90f60adfc)
Signed-off-by: Jacob O'Mara <jacob.omara@ptfs-europe.com>
This commit is contained in:
Tomás Cohen Arazi 2023-02-10 09:35:01 -03:00 committed by Jacob O'Mara
parent 2b116771f1
commit e84421e9e8
3 changed files with 13 additions and 6 deletions

View 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();

View file

@ -32,6 +32,9 @@ properties:
type:
- string
- "null"
enum:
- Automatic
- Manual
renewer:
type:
- object

View file

@ -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)