Bug 32455: Unit tests
authorNick Clemens <nick@bywatersolutions.com>
Wed, 14 Dec 2022 13:46:24 +0000 (13:46 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 7 Feb 2023 13:26:03 +0000 (10:26 -0300)
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
t/db_dependent/Holds/ExpireReservesAutoFill.t
t/db_dependent/Reserves.t

index ab1eaf3..b05a8a2 100755 (executable)
@@ -29,8 +29,22 @@ my $builder = t::lib::TestBuilder->new();
 my $dbh     = C4::Context->dbh;
 
 # Create two random branches
-my $library_1 = $builder->build({ source => 'Branch' })->{ branchcode };
-my $library_2 = $builder->build({ source => 'Branch' })->{ branchcode };
+my $branch_1  = $builder->build_object({
+    class => 'Koha::Libraries',
+    value => {
+        branchemail => 'branch1@e.mail',
+        branchreplyto => 'branch1@reply.to'
+    }
+});
+my $library_1 = $branch_1->branchcode;
+my $branch_2  = $builder->build_object({
+    class => 'Koha::Libraries',
+    value => {
+        branchemail => 'branch2@e.mail',
+        branchreplyto => 'branch2@reply.to'
+    }
+});
+my $library_2 = $branch_2->branchcode;
 
 my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
 my $biblionumber = $biblio->id;
@@ -132,7 +146,7 @@ subtest 'Test automatically canceled expired waiting holds to fill the next hold
 };
 
 subtest 'Test automatically canceled expired waiting holds to fill the next hold, with a transfer' => sub {
-    plan tests => 5;
+    plan tests => 6;
 
     $dbh->do('DELETE FROM reserves');
     $dbh->do('DELETE FROM message_queue');
@@ -187,5 +201,10 @@ subtest 'Test automatically canceled expired waiting holds to fill the next hold
 
     my @messages = $schema->resultset('MessageQueue')
       ->search( { letter_code => 'HOLD_CHANGED' } );
-    is( @messages, 1, 'Nessage is generated in the message queue when generating transfer' );
+    is( @messages, 1, 'Message is generated in the message queue when generating transfer' );
+
+    my $email = $messages[0];
+    is( $email->from_address, $branch_2->branchemail, "Message is sent from library's email");
 };
+
+$schema->storage->txn_rollback;
index 1f368e3..3371c95 100755 (executable)
@@ -789,7 +789,20 @@ $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
 
 subtest '_koha_notify_reserve() tests' => sub {
 
-    plan tests => 2;
+    plan tests => 3;
+
+    my $branch = $builder->build_object({
+        class => 'Koha::Libraries',
+        value => {
+            branchemail => 'branch@e.mail',
+            branchreplyto => 'branch@reply.to',
+            pickup_location => 1
+        }
+    });
+    my $item = $builder->build_sample_item({
+        homebranch => $branch->branchcode,
+        holdingbranch => $branch->branchcode
+    });
 
     my $wants_hold_and_email = {
         wants_digest => '0',
@@ -852,12 +865,15 @@ subtest '_koha_notify_reserve() tests' => sub {
         })->next()->to_address();
     is($sms_message_address, undef ,"We should not populate the sms message with the sms number, sending will do so");
 
-    my $email_message_address = $schema->resultset('MessageQueue')->search({
+    my $email = $schema->resultset('MessageQueue')->search({
             letter_code     => 'HOLD',
             message_transport_type => 'email',
             borrowernumber => $hold_borrower,
-        })->next()->to_address();
-    is($email_message_address, undef ,"We should not populate the hold message with the email address, sending will do so");
+        })->next();
+    my $email_to_address = $email->to_address();
+    is($email_to_address, undef ,"We should not populate the hold message with the email address, sending will do so");
+    my $email_from_address = $email->from_address();
+    is($email_from_address,'branch@e.mail',"Library's from address is used for sending");
 
 };