From 8fd9ff1730b321dc80ae92a127aced3187b2f43e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Wed, 29 Jan 2020 14:06:00 +0000 Subject: [PATCH] Bug 18936: (follow-up) Fix checkouts endpoint and its tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Fixes a bug caused by the refactoring in Koha/REST/V1/Checkouts.pm (run the tests without this patch and you will see the tests fails because 'rule_name' parameter was forgotten). - Changes the tests to use the new Koha::CirculationRule objects instead of directly using issuingrules DB table Signed-off-by: Minna Kivinen Signed-off-by: Joonas Kylmälä Signed-off-by: Martin Renvoize --- Koha/REST/V1/Checkouts.pm | 3 ++- t/db_dependent/api/v1/checkouts.t | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm index 7fc6913f1e..c3ae141e67 100644 --- a/Koha/REST/V1/Checkouts.pm +++ b/Koha/REST/V1/Checkouts.pm @@ -213,13 +213,14 @@ sub allows_renewal { categorycode => $checkout->patron->categorycode, itemtype => $checkout->item->effective_itemtype, branchcode => $checkout->branchcode, + rule_name => 'renewalsallowed', } ); return $c->render( status => 200, openapi => { allows_renewal => $renewable, - max_renewals => $rule->renewalsallowed, + max_renewals => $rule->rule_value, current_renewals => $checkout->renewals, error => $error } diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t index 3a5c5deab9..79752b441c 100644 --- a/t/db_dependent/api/v1/checkouts.t +++ b/t/db_dependent/api/v1/checkouts.t @@ -71,11 +71,18 @@ $t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$notexisting_patron ->status_is(200) ->json_is([]); -$dbh->do('DELETE FROM issuingrules'); -$dbh->do(q{ - INSERT INTO issuingrules (categorycode, branchcode, itemtype, renewalperiod, renewalsallowed, issuelength) - VALUES (?, ?, ?, ?, ?, ?) -}, {}, '*', '*', '*', 7, 1, 5); +Koha::CirculationRules->set_rules( + { + categorycode => undef, + itemtype => undef, + branchcode => undef, + rules => { + renewalperiod => 7, + renewalsallowed => 1, + issuelength => 5, + } + } +); my $item1 = $builder->build_sample_item; my $item2 = $builder->build_sample_item; @@ -173,7 +180,6 @@ $t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id) ->status_is(200) ->json_is('/due_date' => output_pref( { dateformat => "rfc3339", dt => $date_due2 }) ); - my $expected_datedue = $date_due ->set_time_zone('local') ->add(days => 7) -- 2.11.4.GIT