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;
23 use JSON qw( encode_json );
26 use Koha::BackgroundJob::BatchDeleteItem;
29 use t::lib::TestBuilder;
31 my $schema = Koha::Database->new->schema;
32 my $builder = t::lib::TestBuilder->new;
34 subtest "process() tests" => sub {
38 $schema->storage->txn_begin;
40 my $biblio = $builder->build_sample_biblio;
41 my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id });
42 my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id });
46 my $mock_holds_queue_job = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
47 $mock_holds_queue_job->mock( 'enqueue', sub {
51 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
53 my $job = Koha::BackgroundJob::BatchDeleteItem->new(
57 borrowernumber => undef,
58 type => 'batch_item_record_deletion',
60 record_ids => [ $item_1->id, $item_2->id ],
68 record_ids => [ $item_1->id, $item_2->id ],
73 is( $counter, 1, 'Holds queue update is enqueued only once' );
75 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
77 $biblio = $builder->build_sample_biblio;
78 my $item = $builder->build_sample_item({ biblionumber => $biblio->id });
80 $job = Koha::BackgroundJob::BatchDeleteItem->new(
84 borrowernumber => undef,
85 type => 'batch_item_record_deletion',
87 record_ids => [ $item->id ],
95 record_ids => [ $item->id ],
100 is( $counter, 1, 'Counter untouched with RealTimeHoldsQueue disabled' );
102 $schema->storage->txn_rollback;