Bug 24807: (QA follow-up) Remove uneccessary tests
[koha.git] / t / db_dependent / Koha / SearchEngine / 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 => 2;
21 use Test::MockModule;
22 use t::lib::Mocks;
23
24 use MARC::Record;
25
26 use Koha::Database;
27
28 my $schema = Koha::Database->schema();
29
30 use_ok('Koha::SearchEngine::Elasticsearch::Indexer');
31
32 subtest 'create_index() tests' => sub {
33     plan tests => 6;
34     my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' );
35     $se->mock( '_read_configuration', sub {
36             my ($self, $sub ) = @_;
37             my $method = $se->original( '_read_configuration' );
38             my $conf = $method->( $self );
39             $conf->{index_name} .= '__test';
40             return $conf;
41         });
42
43     my $indexer;
44     ok(
45         $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }),
46         'Creating a new indexer object'
47     );
48
49     is(
50         $indexer->create_index(),
51         Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_OK(),
52         'Creating an index'
53     );
54
55     my $marc_record = MARC::Record->new();
56     $marc_record->append_fields(
57         MARC::Field->new('001', '1234567'),
58         MARC::Field->new('020', '', '', 'a' => '1234567890123'),
59         MARC::Field->new('245', '', '', 'a' => 'Title')
60     );
61     my $records = [$marc_record];
62
63     my $response = $indexer->update_index([1], $records);
64     is( $response->{errors}, 0, "no error on update_index" );
65     is( scalar(@{$response->{items}}), 1, "1 item indexed" );
66     is( $response->{items}[0]->{index}->{_id},"1", "We should get a string matching the bibnumber passed in");
67
68     is(
69         $indexer->drop_index(),
70         Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_RECREATE_REQUIRED(),
71         'Dropping the index'
72     );
73 };