From bb36641339361c2c6746593b296f048837d8b2ce Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 13 Nov 2025 10:36:12 -0500 Subject: [PATCH] Bug 41248: Add unit tests --- .../BatchUpdateBiblioHoldsQueue.t | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.t b/t/db_dependent/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.t index 1669e4fd328..bf0900d74ea 100755 --- a/t/db_dependent/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.t +++ b/t/db_dependent/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.t @@ -18,7 +18,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Exception; use Koha::Database; @@ -61,3 +61,24 @@ subtest 'enqueue() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'prevent duplicate jobs tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); + + Koha::BackgroundJobs->search()->delete(); + + my $job_id = Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [1] } ); + isnt( $job_id, undef, "Job id was returned for background job with no duplicate" ); + is( Koha::BackgroundJobs->search()->count(), 1, "Found one enqueued background job" ); + + $job_id = Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [1] } ); + is( $job_id, undef, "No job id was returned for background job with duplicate" ); + is( Koha::BackgroundJobs->search()->count(), 1, "Still found one enqueued background job" ); + + $schema->storage->txn_rollback; +}; -- 2.50.1 (Apple Git-155)