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 );
25 use C4::Reserves qw(AddReserve);
28 use Koha::BackgroundJob::BatchDeleteBiblio;
29 use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
32 use t::lib::TestBuilder;
34 my $schema = Koha::Database->new->schema;
35 my $builder = t::lib::TestBuilder->new;
37 subtest "process() tests" => sub {
41 $schema->storage->txn_begin;
43 t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch');
45 my $biblio = $builder->build_sample_biblio;
46 my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id });
47 my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id });
49 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
52 borrowernumber => $patron->id,
53 biblionumber => $biblio->id,
54 itemnumber => $item_1->id,
55 branchcode => $patron->branchcode
59 my $update_biblio_counter = 0;
61 my $mock_holds_queue_job = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
62 $mock_holds_queue_job->mock( 'enqueue', sub {
63 $update_biblio_counter++;
66 my $index_biblio_counter = 0;
68 my $mock_index = Test::MockModule->new("Koha::SearchEngine::Elasticsearch::Indexer");
69 $mock_index->mock( 'index_records', sub {
70 $index_biblio_counter++;
73 my $job = Koha::BackgroundJob::BatchDeleteBiblio->new(
77 borrowernumber => undef,
78 type => 'batch_biblio_record_deletion',
80 record_ids => [ $biblio->id ],
85 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
89 record_ids => [ $biblio->id ],
93 is( $update_biblio_counter, 1, 'Holds queue update is enqueued only once' );
94 is( $index_biblio_counter, 1, 'Index update is enqueued only once' );
96 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
98 $biblio = $builder->build_sample_biblio;
100 $job = Koha::BackgroundJob::BatchDeleteBiblio->new(
104 borrowernumber => undef,
105 type => 'batch_biblio_record_deletion',
106 data => encode_json {
107 record_ids => [ $biblio->id ],
114 record_ids => [ $biblio->id ],
118 is( $update_biblio_counter, 1, 'Counter untouched with RealTimeHoldsQueue disabled' );
120 $schema->storage->txn_rollback;