Bug 41983: (QA follow-up): Rebuild the holds queue when groups are edited
Test plan (ktd) 0) Update the database (ktd, ignore if sandbox): $ updatedatabase 1) Enable 'RealTimeHoldsQueue' and 'DisplayAddHoldGroups' system preferences 2) restart_all # This is required or the worker won't pick up the new sys pref values 3) Place at least 2 holds for a patron on different items/biblios, without grouping them: <staff_url>/cgi-bin/koha/members/moremember.pl?borrowernumber=19 4) Build the holds queue once to get a baseline: $ perl misc/cronjobs/holds/build_holds_queue.pl --force 5) Visit the holds queue and confirm the holds appear without a group indicator: <staff_url>/cgi-bin/koha/circ/view_holdsqueue.pl?branchlimit=&itemtypeslimit=&run_report=1 6) Create a hold group for those holds via the patron page <staff_url>/cgi-bin/koha/circ/circulation.pl?borrowernumber=<patron_borrowernumber> 7) Without running build_holds_queue.pl, refresh the holds queue, confirm the 'part of a hold group' indicator now appears 8) Ungroup the holds, refresh the holds queue, confirm the 'part of a hold group' is no longer showing 9) Run the unit tests: $ prove t/db_dependent/Reserves/HoldGroup.t Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
af95e03c08
commit
2ed777a854
|
|
@ -22,6 +22,8 @@ use Modern::Perl;
|
|||
use C4::Context;
|
||||
use C4::Log qw( logaction );
|
||||
|
||||
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
|
||||
|
||||
use base qw(Koha::Object);
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -77,6 +79,11 @@ sub store {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $result && @$associated_holds && C4::Context->preference('RealTimeHoldsQueue') ) {
|
||||
my @biblio_ids = map { $_->biblionumber } @$associated_holds;
|
||||
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@biblio_ids } );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
@ -114,6 +121,11 @@ sub delete {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $result && @associated_holds && C4::Context->preference('RealTimeHoldsQueue') ) {
|
||||
my @biblio_ids = map { $_->biblionumber } @associated_holds;
|
||||
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@biblio_ids } );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,11 +20,13 @@
|
|||
use Modern::Perl;
|
||||
|
||||
use Test::NoWarnings;
|
||||
use Test::More tests => 3;
|
||||
use Test::More tests => 4;
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
use t::lib::Mocks;
|
||||
|
||||
use Test::MockModule;
|
||||
|
||||
use C4::Reserves qw( AddReserve ModReserveAffect );
|
||||
use C4::Circulation qw( AddReturn );
|
||||
|
||||
|
|
@ -130,6 +132,89 @@ subtest "target_hold_id tests" => sub {
|
|||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'RealTimeHoldsQueue tests' => sub {
|
||||
|
||||
plan tests => 2;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
|
||||
my $item_1 = $builder->build_sample_item;
|
||||
my $item_2 = $builder->build_sample_item;
|
||||
|
||||
my $hold_1 = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Holds',
|
||||
value => {
|
||||
borrowernumber => $patron->borrowernumber,
|
||||
biblionumber => $item_1->biblionumber,
|
||||
hold_group_id => undef,
|
||||
found => undef,
|
||||
}
|
||||
}
|
||||
);
|
||||
my $hold_2 = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Holds',
|
||||
value => {
|
||||
borrowernumber => $patron->borrowernumber,
|
||||
biblionumber => $item_2->biblionumber,
|
||||
hold_group_id => undef,
|
||||
found => undef,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
|
||||
$mock->mock(
|
||||
'enqueue',
|
||||
sub {
|
||||
my ( $self, $args ) = @_;
|
||||
is_deeply(
|
||||
[ sort @{ $args->{biblio_ids} } ],
|
||||
[ sort( $item_1->biblionumber, $item_2->biblionumber ) ],
|
||||
'store/delete with RealTimeHoldsQueue triggers a holds queue update for the related biblios'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
|
||||
|
||||
my $hold_group = $patron->create_hold_group( [ $hold_1->id, $hold_2->id ] );
|
||||
|
||||
$hold_group->delete;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
|
||||
|
||||
my $hold_3 = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Holds',
|
||||
value => {
|
||||
borrowernumber => $patron->borrowernumber,
|
||||
biblionumber => $item_1->biblionumber,
|
||||
hold_group_id => undef,
|
||||
found => undef,
|
||||
}
|
||||
}
|
||||
);
|
||||
my $hold_4 = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Holds',
|
||||
value => {
|
||||
borrowernumber => $patron->borrowernumber,
|
||||
biblionumber => $item_2->biblionumber,
|
||||
hold_group_id => undef,
|
||||
found => undef,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
my $hold_group_2 = $patron->create_hold_group( [ $hold_3->id, $hold_4->id ] );
|
||||
$hold_group_2->delete;
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
sub set_userenv {
|
||||
my ($library) = @_;
|
||||
my $staff = $builder->build_object( { class => "Koha::Patrons" } );
|
||||
|
|
|
|||
Loading…
Reference in New Issue