Bug 32394: Regression tests
[koha.git] / t / db_dependent / Koha / BackgroundJob / BatchUpdateBiblioHoldsQueue.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 1;
21 use Test::Exception;
22
23 use Koha::Database;
24 use Koha::BackgroundJobs;
25 use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
26
27 use t::lib::Mocks;
28 use t::lib::TestBuilder;
29
30 my $schema  = Koha::Database->new->schema;
31 my $builder = t::lib::TestBuilder->new;
32
33 subtest 'enqueue() tests' => sub {
34
35     plan tests => 5;
36
37     $schema->storage->txn_begin;
38
39     my $biblio_ids = [ 1, 2 ];
40
41     throws_ok
42         { Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue() }
43         'Koha::Exceptions::MissingParameter',
44         "Exception thrown if 'biblio_ids' param is missing";
45
46     like( "$@", qr/Missing biblio_ids parameter is mandatory/, 'Expected exception message' );
47
48     my $job_id = Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => $biblio_ids } );
49     my $job    = Koha::BackgroundJobs->find($job_id)->_derived_class;
50
51     is( $job->size,   scalar @{$biblio_ids}, 'Size is correct' );
52     is( $job->status, 'new',                 'Initial status set correctly' );
53     is( $job->queue,  'default',             'BatchUpdateItem should use the default queue' );
54
55     $schema->storage->txn_rollback;
56 };