From c0f3f2141648d72ae49b5f407d82b9220cc06acc Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 29 Apr 2022 00:56:25 +0000 Subject: [PATCH] Bug 29346: (follow-up) Build holds queue when AlterPriority or RevertWaitingStatus is called To test: 1 - Place 3 holds on a bib with a single item 2 - Confirm bib shows in holds queue 3 - Check in item and cnofirm hold 4 - Bib is no longer in queue 5 - Revert the waiting status 6 - The hold is in the queue again 7 - Move top hold to bottom 8 - Confirm queue selects hold for new top priorty patron Signed-off-by: Nick Clemens Signed-off-by: Fridolin Somers --- C4/Reserves.pm | 12 +++++++ t/db_dependent/Reserves.t | 70 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index caf210b1d0..a86a063906 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1442,6 +1442,11 @@ sub AlterPriority { _FixPriority({ reserve_id => $reserve_id, rank => $last_priority }); } + Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( + { + biblio_ids => [ $hold->biblionumber ] + } + ); # FIXME Should return the new priority } @@ -2090,6 +2095,13 @@ sub RevertWaitingStatus { _FixPriority( { biblionumber => $hold->biblionumber } ); + Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( + { + biblio_ids => [ $hold->biblionumber ] + } + ); + + return $hold; } diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index c93987e17a..cfac978aeb 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 => 71; use Test::MockModule; use Test::Warn; @@ -31,7 +31,7 @@ use C4::Circulation qw( AddReturn AddIssue ); use C4::Items; use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField ModBiblio ); use C4::Members; -use C4::Reserves qw( AddReserve CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds ); +use C4::Reserves qw( AddReserve AlterPriority CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds ); use Koha::ActionLogs; use Koha::Caches; use Koha::DateUtils qw( dt_from_string output_pref ); @@ -934,7 +934,7 @@ subtest 'reserves.item_level_hold' => sub { ); subtest 'item level hold' => sub { - plan tests => 2; + plan tests => 3; my $reserve_id = AddReserve( { branchcode => $item->homebranch, @@ -951,6 +951,16 @@ subtest 'reserves.item_level_hold' => sub { # Mark it waiting ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 1 ); + my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); + $mock->mock( 'enqueue', sub { + my ( $self, $args ) = @_; + is_deeply( + $args->{biblio_ids}, + [ $hold->biblionumber ], + "AlterPriority triggers a holds queue update for the related biblio" + ); + } ); + # Revert the waiting status C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); @@ -1428,3 +1438,57 @@ subtest 'AddReserve() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'AlterPriorty() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); + my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); + my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' }); + my $biblio = $builder->build_sample_biblio; + + my $reserve_id = AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron_1->id, + biblionumber => $biblio->id, + } + ); + AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron_2->id, + biblionumber => $biblio->id, + } + ); + AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron_3->id, + biblionumber => $biblio->id, + } + ); + + my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); + $mock->mock( 'enqueue', sub { + my ( $self, $args ) = @_; + is_deeply( + $args->{biblio_ids}, + [ $biblio->id ], + "AlterPriority triggers a holds queue update for the related biblio" + ); + } ); + + + AlterPriority( "bottom", $reserve_id, 1, 2, 1, 3 ); + + my $hold = Koha::Holds->find($reserve_id); + + is($hold->priority,3,'Successfully altered priority to bottom'); + + $schema->storage->txn_rollback; +}; -- 2.39.5