From c9548a849cb94eafb2035db81df92b520858a529 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 1 Feb 2023 14:28:23 +0100 Subject: [PATCH] Bug 32779: Add tests --- .../CreateEHoldingsFromBiblios.t | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/t/db_dependent/Koha/BackgroundJob/CreateEHoldingsFromBiblios.t b/t/db_dependent/Koha/BackgroundJob/CreateEHoldingsFromBiblios.t index 36d64d86880..b18a3bfb6ef 100755 --- a/t/db_dependent/Koha/BackgroundJob/CreateEHoldingsFromBiblios.t +++ b/t/db_dependent/Koha/BackgroundJob/CreateEHoldingsFromBiblios.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Koha::Database; use Koha::BackgroundJobs; @@ -29,28 +29,50 @@ use t::lib::TestBuilder; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; -subtest 'enqueue() tests' => sub { +subtest 'enqueue' => sub { - plan tests => 5; + plan tests => 2; $schema->storage->txn_begin; # FIXME: Should be an exception - my $job_id = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue(); + my $job_id = + Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue(); is( $job_id, undef, 'Nothing enqueued if missing params' ); # FIXME: Should be an exception - $job_id = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue( { record_ids => undef } ); + $job_id = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue( + { record_ids => undef } ); is( $job_id, undef, "Nothing enqueued if missing 'package_id' param" ); - my $record_ids = [ 1, 2 ]; + $schema->storage->txn_rollback; +}; + +subtest 'process' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio; - $job_id = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue( { record_ids => $record_ids, package_id => 'thing' } ); - my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; + my $package = + Koha::ERM::EHoldings::Package->new( { name => 'a package' } )->store; - is( $job->size, scalar @{$record_ids}, 'Size is correct' ); - is( $job->status, 'new', 'Initial status set correctly' ); - is( $job->queue, 'long_tasks', 'BatchUpdateItem should use the long_tasks queue' ); + my $job = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new( + { + status => 'new', + type => 'create_eholdings_from_biblios', + } + )->store; + $job = Koha::BackgroundJobs->find( $job->id ); + my $data = { + record_ids => [ $biblio->biblionumber ], + package_id => $package->package_id, + }; + my $json = $job->json->encode($data); + $job->data($json)->store; + $job->process($data); + is( $job->report->{total_success}, 1 ); $schema->storage->txn_rollback; }; -- 2.25.1