From 317685e8968d9b5ac023ae77195ac11bcd1e7b99 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 14 Dec 2022 13:46:24 +0000 Subject: [PATCH] Bug 32455: Unit tests Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Holds/ExpireReservesAutoFill.t | 27 ++++++++++++++++--- t/db_dependent/Reserves.t | 24 ++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Holds/ExpireReservesAutoFill.t b/t/db_dependent/Holds/ExpireReservesAutoFill.t index ab1eaf3c0f..b05a8a2e75 100755 --- a/t/db_dependent/Holds/ExpireReservesAutoFill.t +++ b/t/db_dependent/Holds/ExpireReservesAutoFill.t @@ -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; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 1f368e36b6..3371c9539d 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -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"); }; -- 2.39.5