Bug 16423: [QA Follow-up] Remove $opac
[koha.git] / t / db_dependent / Koha_ElasticSearch_Indexer.t
1 # Copyright 2015 Catalyst IT
2 #
3 #
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 use strict;
20 use warnings;
21
22 use Test::More tests => 5;    # last test to print
23 use MARC::Record;
24
25 use_ok('Koha::ElasticSearch::Indexer');
26
27 my $indexer;
28 ok(
29     $indexer = Koha::ElasticSearch::Indexer->new(
30         {
31             'nodes' => ['localhost:9200'],
32             'index' => 'mydb'
33         }
34     ),
35     'Creating new indexer object'
36 );
37
38 my $marc_record = MARC::Record->new();
39 my $field = MARC::Field->new( '001', '1234567' );
40 $marc_record->append_fields($field);
41 $field = MARC::Field->new( '020', '', '', 'a' => '1234567890123' );
42 $marc_record->append_fields($field);
43 $field = MARC::Field->new( '245', '', '', 'a' => 'Title' );
44 $marc_record->append_fields($field);
45
46 my $records = [$marc_record];
47 ok( my $converted = $indexer->_convert_marc_to_json($records),
48     'Convert some records' );
49
50 is( $converted->count, 1, 'One converted record' );
51
52 ok( $indexer->update_index(undef,$records), 'Update Index' );