From b3e9a97b3dadb1e397733eaae4abd645234964e1 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Thu, 24 Nov 2022 13:06:55 +0200 Subject: [PATCH 1/2] Bug 32306: Add unit tests In ModReserves logging changes actually happens before we store any of made changes. To test: 1. Run prove t/db_dependent/Reserves.t => Tests should fail. Sponsored-by: Koha-Suomi Oy --- t/db_dependent/Reserves.t | 97 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 9c8c85d473..991f3234a1 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 77; +use Test::More tests => 78; use Test::MockModule; use Test::Warn; @@ -1406,6 +1406,101 @@ subtest 'ModReserveAffect logging' => sub { like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); }; +subtest 'ModReserve logging' => sub { + + plan tests => 2; + + t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); + + my $item = $builder->build_sample_item; + my $patron = $builder->build_object( + { + class => "Koha::Patrons", + value => { branchcode => $item->homebranch } + } + ); + + my $hold1 = $builder->build_object( + { + class => "Koha::Holds", + value => { + found => "W", + priority => 0, + itemnumber => undef, + biblionumber => $item->biblionumber, + waitingdate => undef, + cancellationdate => undef, + item_level_hold => 0, + lowestPriority => 0, + expirationdate => '2022-12-24', + suspend_until => undef, + suspend => 0, + itemtype => undef, + borrowernumber => $patron->borrowernumber + } + } + ); + + my $other_branch = $builder->build_object( { class => "Koha::Libraries" } ); + + # Test changing expiration date + my $params = { + rank => $hold1->priority, + reserve_id => $hold1->reserve_id, + biblionumber => $item->biblionumber, + borrowernumber => $patron->borrowernumber, + branchcode => $hold1->branchcode, + expirationdate => "2022-12-31", + }; + + ModReserve($params); + my $log = Koha::ActionLogs->search( + { module => 'HOLDS', action => 'MODIFY', object => $hold1->reserve_id } + )->next; + my $expected = sprintf q{'expirationdate' => '%s'}, + $params->{expirationdate}; + like( $log->info, qr{$expected}, + 'Expiration date should have changed in logs' ); + + # Test making other changes + my $hold2 = $builder->build_object( + { + class => "Koha::Holds", + value => { + found => undef, + priority => 1, + itemnumber => undef, + biblionumber => $item->biblionumber, + waitingdate => undef, + cancellationdate => undef, + item_level_hold => 0, + lowestPriority => 0, + expirationdate => '2022-12-24', + suspend_until => undef, + suspend => 0, + itemtype => undef, + borrowernumber => $patron->borrowernumber + } + } + ); + + $params = { + rank => $hold2->priority, + reserve_id => $hold2->reserve_id, + biblionumber => $item->biblionumber, + borrowernumber => $patron->borrowernumber, + branchcode => $other_branch->branchcode, + }; + + ModReserve($params); + $log = Koha::ActionLogs->search( + { module => 'HOLDS', action => 'MODIFY', object => $hold2->reserve_id } + )->next; + $expected = sprintf q{'branchcode' => '%s'}, $other_branch->branchcode; + like( $log->info, qr{$expected}, 'Branchcode should have changed in logs' ); + +}; + sub count_hold_print_messages { my $message_count = $dbh->selectall_arrayref(q{ SELECT COUNT(*) -- 2.34.1