From d3490f21795fd1e37972408f9f1be497e1e216b2 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Mon, 6 Oct 2025 16:46:57 +0200 Subject: [PATCH] Bug 40960: Fix unit tests Two unit tests have been moved/replaced to fit the desired behaviour - "patron notified when item set to waiting" -> does not fit the desired behaviour. The desired behaviour for mails/sms is already tested The desired behaviour for prints is changed to "patron not notified if no messaging preference is specified" - "patron not notified a second time (bug 11445)" -> Moved into _koha_notify_reserve tests --- t/db_dependent/Reserves.t | 56 +++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 22778875a2b..00c46e381b7 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 70; +use Test::More tests => 68; use Test::NoWarnings; use Test::MockModule; use Test::Warn; @@ -425,16 +425,7 @@ is( # End of tests for bug 9761 (ConfirmFutureHolds) -# test marking a hold as captured -my $hold_notice_count = count_hold_print_messages(); ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 0 ); -my $new_count = count_hold_print_messages(); -is( $new_count, $hold_notice_count + 1, 'patron notified when item set to waiting' ); - -# test that duplicate notices aren't generated -ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 0 ); -$new_count = count_hold_print_messages(); -is( $new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)' ); # avoiding the not_same_branch error t::lib::Mocks::mock_preference( 'IndependentBranches', 0 ); @@ -791,7 +782,7 @@ $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); subtest '_koha_notify_reserve() tests' => sub { - plan tests => 4; + plan tests => 6; my $branch = $builder->build_object( { @@ -809,6 +800,12 @@ subtest '_koha_notify_reserve() tests' => sub { holdingbranch => $branch->branchcode } ); + my $item2 = $builder->build_sample_item( + { + homebranch => $branch->branchcode, + holdingbranch => $branch->branchcode + } + ); my $wants_hold_and_email = { wants_digest => '0', @@ -851,6 +848,19 @@ subtest '_koha_notify_reserve() tests' => sub { } ); + my $print_hold_notice = $builder->build( + { + source => 'Letter', + value => { + message_transport_type => 'print', + branchcode => '', + code => 'HOLD', + module => 'reserves', + lang => 'default', + } + } + ); + my $hold_borrower = $builder->build( { source => 'Borrower', @@ -868,6 +878,13 @@ subtest '_koha_notify_reserve() tests' => sub { biblionumber => $item->biblionumber, } ); + C4::Reserves::AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $hold_borrower, + biblionumber => $item2->biblionumber, + } + ); ModReserveAffect( $item->itemnumber, $hold_borrower, 0 ); my $sms_message_address = $schema->resultset('MessageQueue')->search( @@ -896,6 +913,23 @@ subtest '_koha_notify_reserve() tests' => sub { my $email_reply_address = $email->reply_address(); is( $email_reply_address, 'branch@reply.to', "Library's reply address is used for reply" ); + $wants_hold_and_email = { + wants_digest => '0', + transports => {}, + letter_code => 'HOLD' + }; + $mp = Test::MockModule->new('C4::Members::Messaging'); + $mp->mock( "GetMessagingPreferences", $wants_hold_and_email ); + + my $hold_notice_count = count_hold_print_messages(); + ModReserveAffect( $item2->itemnumber, $hold_borrower ); + my $new_count = count_hold_print_messages(); + is( $new_count, $hold_notice_count, 'patron not notified if no messaging preference is specified' ); + + $hold_notice_count = count_hold_print_messages(); + ModReserveAffect( $item2->itemnumber, $hold_borrower, 0 ); + $new_count = count_hold_print_messages(); + is( $new_count, $hold_notice_count, 'patron not notified a second time (bug 11445)' ); }; subtest 'ReservesNeedReturns' => sub { -- 2.43.0