From 6ad34787f661a9c059f6236233ea0f87faad2af8 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 1 Mar 2021 15:41:21 -0300 Subject: [PATCH] Bug 24359: (QA follow-up) Fix tests This patch fixes a rebase issue, and also makes sure the tests do not rely on any prior data. The query on tmp_holdsqueue is done against the actual reserve_id so no need to delete all the data from the tmp_holdsqueue and hold_fill_targets table. I also noticed the previous subtest wasn't run inside a transaction even if the code was designed to not depend on prior data as well. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/HoldsQueue.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- t/db_dependent/HoldsQueue.t | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index 20936fb5d4..358555e94b 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -8,7 +8,7 @@ use Modern::Perl; -use Test::More tests => 56; +use Test::More tests => 57; use Data::Dumper; use C4::Calendar; @@ -1524,8 +1524,11 @@ sub test_queue { } subtest "Test _checkHoldPolicy" => sub { + plan tests => 25; + $schema->storage->txn_begin; + my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); my $library_nongroup = $builder->build_object( { class => 'Koha::Libraries' } ); @@ -1652,6 +1655,8 @@ subtest "Test _checkHoldPolicy" => sub { $item->{borrowerbranch} = $library2->id; is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is part of hold group with hfp = holdgroup" ); $item->{borrowerbranch} = $library1->id; + + $schema->storage->txn_rollback; }; sub dump_records { @@ -1660,13 +1665,11 @@ sub dump_records { } subtest 'Remove holds on check-in match' => sub { + plan tests => 2; $schema->storage->txn_begin; - $dbh->do('DELETE FROM tmp_holdsqueue'); - $dbh->do('DELETE FROM hold_fill_targets'); - my $lib = $builder->build_object( { class => 'Koha::Libraries' } ); my $patron1 = $builder->build_object( @@ -1705,8 +1708,18 @@ subtest 'Remove holds on check-in match' => sub { C4::HoldsQueue::CreateQueue(); - my $sth = $dbh->prepare("SELECT count(*) FROM tmp_holdsqueue"); - $sth->execute(); + my $sth = $dbh->prepare(q{ + SELECT COUNT(*) + FROM tmp_holdsqueue q + INNER JOIN hold_fill_targets t + ON q.borrowernumber = t.borrowernumber + AND q.biblionumber = t.biblionumber + AND q.itemnumber = t.itemnumber + AND q.item_level_request = t.item_level_request + AND q.holdingbranch = t.source_branchcode + WHERE t.reserve_id = ? + }); + $sth->execute($hold->reserve_id); my ($count_1) = $sth->fetchrow_array; is( $count_1, 1, "Holds queue has one element" ); @@ -1716,7 +1729,7 @@ subtest 'Remove holds on check-in match' => sub { ModReserveAffect( $item->itemnumber, $hold->borrowernumber, 0, $hold->reserve_id ); - $sth->execute(); + $sth->execute($hold->reserve_id); my ($count_2) = $sth->fetchrow_array; is( $count_2, 0, -- 2.24.1 (Apple Git-126)