3 # This file is part of Koha
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 1;
24 use Koha::BackgroundJobs;
25 use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
28 use t::lib::TestBuilder;
30 my $schema = Koha::Database->new->schema;
31 my $builder = t::lib::TestBuilder->new;
33 subtest 'enqueue() tests' => sub {
37 $schema->storage->txn_begin;
39 my $biblio_ids = [ 1, 2 ];
41 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
43 Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => $biblio_ids } ),
44 undef, 'No result when pref is off'
46 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
49 { Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue() }
50 'Koha::Exceptions::MissingParameter',
51 "Exception thrown if 'biblio_ids' param is missing";
53 like( "$@", qr/Missing biblio_ids parameter is mandatory/, 'Expected exception message' );
55 my $job_id = Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => $biblio_ids } );
56 my $job = Koha::BackgroundJobs->find($job_id)->_derived_class;
58 is( $job->size, scalar @{$biblio_ids}, 'Size is correct' );
59 is( $job->status, 'new', 'Initial status set correctly' );
60 is( $job->queue, 'default', 'BatchUpdateItem should use the default queue' );
62 $schema->storage->txn_rollback;