From f214721785ded9bd9a4833420a1a5143b81cd477 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 23 Mar 2022 15:47:24 -0300 Subject: [PATCH] Bug 30345: Regression tests Signed-off-by: Tomas Cohen Arazi Signed-off-by: Arthur Suzuki --- t/db_dependent/Koha/BackgroundJob.t | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/BackgroundJob.t b/t/db_dependent/Koha/BackgroundJob.t index 7dcabcbcda..632a615483 100755 --- a/t/db_dependent/Koha/BackgroundJob.t +++ b/t/db_dependent/Koha/BackgroundJob.t @@ -17,11 +17,13 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Koha::Database; use Koha::BackgroundJobs; +use Koha::BackgroundJob::BatchUpdateItem; +use t::lib::Mocks; use t::lib::TestBuilder; my $schema = Koha::Database->new->schema; @@ -56,3 +58,30 @@ subtest '_derived_class() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'enqueue() tests' => sub { + + plan tests => 6; + + $schema->storage->txn_begin; + + # FIXME: This all feels we need to do it better... + my $job_id = Koha::BackgroundJob::BatchUpdateItem->new->enqueue( { record_ids => [ 1, 2 ] } ); + my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; + + is( $job->size, 2, 'Two steps' ); + is( $job->status, 'new', 'Initial status set correctly' ); + is( $job->borrowernumber, undef, 'No userenv, borrowernumber undef' ); + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + t::lib::Mocks::mock_userenv( { patron => $patron } ); + + $job_id = Koha::BackgroundJob::BatchUpdateItem->new->enqueue( { record_ids => [ 1, 2, 3 ] } ); + $job = Koha::BackgroundJobs->find($job_id)->_derived_class; + + is( $job->size, 3, 'Three steps' ); + is( $job->status, 'new', 'Initial status set correctly' ); + is( $job->borrowernumber, $patron->id, 'No userenv, borrowernumber undef' ); + + $schema->storage->txn_rollback; +}; -- 2.30.2