From 81429cd23d653398a6200edb5594551659ba7f4e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 25 Jan 2024 12:31:46 +0000 Subject: [PATCH] Bug 32565: Unit tests Signed-off-by: Pedro Amorim --- t/db_dependent/HoldsQueue.t | 80 ++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index d0c9a74642a..531f9edb80a 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -8,7 +8,7 @@ use Modern::Perl; -use Test::More tests => 63; +use Test::More tests => 64; use Data::Dumper; use C4::Calendar qw( new insert_single_holiday ); @@ -2211,3 +2211,81 @@ subtest "Canceled holds should be removed from the holds queue" => sub { $schema->storage->txn_rollback; }; + +subtest "Test unallocated option" => sub { + + plan tests => 6; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( + { + class => "Koha::Patrons", + } + ); + my $patron_2 = $builder->build_object( + { + class => "Koha::Patrons", + } + ); + + my $item1 = $builder->build_sample_item( {} )->store(); + + my $item2 = $builder->build_sample_item( {} )->store(); + + my $reserve_id = AddReserve( + { + branchcode => $patron->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item1->biblionumber, + priority => 1, + } + ); + + C4::HoldsQueue::CreateQueue(); + + my $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item1->biblionumber } ); + my $hold = $queue_rs->next; + is( + $hold->itemnumber->itemnumber, + $item1->itemnumber, + "Picked the item" + ); + + my $timestamp = $hold->timestamp; + + sleep 2; + C4::HoldsQueue::CreateQueue(); + $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item1->biblionumber } ); + $hold = $queue_rs->next; + isnt( $hold->timestamp, $timestamp, "Hold was reallocated when queue fully rebuilt" ); + $timestamp = $hold->timestamp; + + C4::HoldsQueue::CreateQueue( { unallocated => 1 } ); + $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item1->biblionumber } ); + $hold = $queue_rs->next; + is( $hold->timestamp, $timestamp, "Previously allocated hold not updated when unallocated passed" ); + + my $reserve_id_2 = AddReserve( + { + branchcode => $patron_2->branchcode, + borrowernumber => $patron_2->borrowernumber, + biblionumber => $item2->biblionumber, + priority => 1, + } + ); + $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item2->biblionumber } ); + $hold = $queue_rs->next; + ok( !$hold, "New hold is not allocated to queue before run" ); + C4::HoldsQueue::CreateQueue( { unallocated => 1 } ); + $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item2->biblionumber } ); + $hold = $queue_rs->next; + ok( $hold, "New hold is allocated to queue when run for unallocated holds" ); + + $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item1->biblionumber } ); + $hold = $queue_rs->next; + is( + $hold->timestamp, $timestamp, + "Previously allocated hold not updated when unallocated passed and others are allocated" + ); +}; -- 2.44.0