From 55e3080dadb749b2beec1c1498deab7493adcd69 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Mon, 22 Nov 2021 16:30:13 +0000
Subject: [PATCH] Bug 29495: Unit Tests

Test plan
1. Run updated tests prior to applying new patches.. pass
2. Run updated tests after applying new patches.. pass

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
---
 t/db_dependent/Koha/Checkouts/ReturnClaim.t | 33 +++++++++++++++------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/t/db_dependent/Koha/Checkouts/ReturnClaim.t b/t/db_dependent/Koha/Checkouts/ReturnClaim.t
index f614895f89..1353f3e8ce 100755
--- a/t/db_dependent/Koha/Checkouts/ReturnClaim.t
+++ b/t/db_dependent/Koha/Checkouts/ReturnClaim.t
@@ -31,7 +31,7 @@ my $builder = t::lib::TestBuilder->new;
 
 subtest "store() tests" => sub {
 
-    plan tests => 11;
+    plan tests => 13;
 
     $schema->storage->txn_begin;
 
@@ -60,23 +60,38 @@ subtest "store() tests" => sub {
             }
           )->store }
         'Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy',
-        'Exception thrown correctly';
+        'Exception thrown if no created_by passed on creation';
 
-    my $nullified_created_by = $builder->build_object(
+    my $old_checkout = $builder->build_object(
         {
-            class => 'Koha::Checkouts::ReturnClaims',
+            class => 'Koha::Old::Checkouts',
             value => {
-                created_by => undef
+                borrowernumber => $patron->borrowernumber,
+                itemnumber     => $item->itemnumber,
+                branchcode     => $patron->branchcode
             }
         }
     );
 
-    is( $nullified_created_by->created_by, undef, 'Is undef' );
-    ok( $nullified_created_by->in_storage, 'In storage' );
+    my $nullable_created_by = Koha::Checkouts::ReturnClaim->new(
+        {
+            issue_id       => $old_checkout->id,
+            itemnumber     => $old_checkout->itemnumber,
+            borrowernumber => $old_checkout->borrowernumber,
+            notes          => 'Some notes',
+            created_by     => $librarian->borrowernumber
+        }
+    )->store;
+    is( $nullable_created_by->created_by, $librarian->borrowernumber, 'Claim created with created_by set' );
+    ok( $nullable_created_by->in_storage, 'In storage' );
+
+    $nullable_created_by->created_by(undef)->store();
+    is( $nullable_created_by->created_by, undef, 'Deletion was deleted' );
+    ok( $nullable_created_by->in_storage, 'In storage' );
     is(
-        ref($nullified_created_by->notes('Some other note')->store),
+        ref($nullable_created_by->notes('Some other note')->store),
         'Koha::Checkouts::ReturnClaim',
-        'No exception, store success'
+        'Subsequent store succeeds after created_by has been unset'
     );
 
     is( Koha::Checkouts::ReturnClaims->search({ issue_id => $checkout->id })->count, 0, 'No claims stored' );
-- 
2.34.1