Bug 30275: Add unit tests for AddRenewal addition
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 28 Apr 2022 10:35:54 +0000 (11:35 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 5 Jul 2022 12:46:20 +0000 (09:46 -0300)
This patch adds a test for the AddRenewal addition that creates Renewal
lines.

Test plan
1) Run the unit tests and confirm it passes

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
t/db_dependent/Circulation.t

index a7d5eaa..e9c8bfa 100755 (executable)
@@ -4410,6 +4410,34 @@ subtest 'AddRenewal and AddIssuingCharge tests' => sub {
 
 };
 
+subtest 'AddRenewal() adds to renewals' => sub {
+    plan tests => 4;
+
+    my $library  = $builder->build_object({ class => 'Koha::Libraries' });
+    my $patron   = $builder->build_object({
+        class => 'Koha::Patrons',
+        value => { branchcode => $library->id }
+    });
+
+    my $item = $builder->build_sample_item();
+
+    set_userenv( $library->unblessed );
+
+    # Check the item out
+    my $issue = AddIssue( $patron->unblessed, $item->barcode );
+    is(ref($issue), 'Koha::Checkout', 'Issue added');
+
+    # Renew item
+    my $duedate = AddRenewal( $patron->id, $item->id, $library->id );
+
+    ok( $duedate, "Renewal added" );
+
+    my $renewals = Koha::Checkouts::Renewals->search({ checkout_id => $issue->issue_id });
+    is($renewals->count, 1, 'One renewal added');
+    my $THE_renewal = $renewals->next;
+    is( $THE_renewal->renewer_id, C4::Context->userenv->{'number'}, 'Renewer recorded from context' );
+};
+
 subtest 'ProcessOfflinePayment() tests' => sub {
 
     plan tests => 4;