Bug 14757: Add tests for new modules
[koha.git] / t / db_dependent / Koha_ElasticSearch_Indexer.t
1 # Copyright 2015 Catalyst IT
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 => 5;
21
22 use MARC::Record;
23
24 use_ok('Koha::ElasticSearch::Indexer');
25
26 my $indexer;
27 ok(
28     $indexer = Koha::ElasticSearch::Indexer->new({ 'index' => 'biblio' }),
29     'Creating new indexer object'
30 );
31
32 my $marc_record = MARC::Record->new();
33 $marc_record->append_fields(
34     MARC::Field->new( '001', '1234567' ),
35     MARC::Field->new( '020', '', '', 'a' => '1234567890123' ),
36     MARC::Field->new( '245', '', '', 'a' => 'Title' )
37 );
38
39 my $records = [$marc_record];
40 ok( my $converted = $indexer->_convert_marc_to_json($records),
41     'Convert some records' );
42
43 is( $converted->count, 1, 'One converted record' );
44
45 SKIP: {
46
47     eval { $indexer->get_elasticsearch_params; };
48
49     skip 'ElasticSeatch configuration not available', 1
50         if $@;
51
52     ok( $indexer->update_index(undef,$records), 'Update Index' );
53 }
54
55 1;