Bug 19893: Restore and fix removed tests

Sponsored-by: Gothenburg University Library
Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
David Gustafsson 2018-09-07 15:18:00 +02:00 committed by Nick Clemens
parent d6139eaad7
commit 1e1ca322d3
2 changed files with 36 additions and 20 deletions

View File

@ -243,6 +243,7 @@ sub drop_index {
my $conf = $self->get_elasticsearch_params();
my $elasticsearch = $self->get_elasticsearch();
$elasticsearch->indices->delete(index => $conf->{index_name});
$self->index_status_recreate_required(1);
}
}

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 3;
use Test::More tests => 2;
use Test::MockModule;
use t::lib::Mocks;
@ -29,26 +29,41 @@ my $schema = Koha::Database->schema();
use_ok('Koha::SearchEngine::Elasticsearch::Indexer');
my $indexer;
ok(
$indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblio' }),
'Creating new indexer object'
);
subtest 'create_index() tests' => sub {
plan tests => 4;
my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' );
$se->mock( 'get_elasticsearch_params', sub {
my ($self, $sub ) = @_;
my $method = $se->original( 'get_elasticsearch_params' );
my $params = $method->( $self );
$params->{index_name} .= '__test';
return $params;
});
my $marc_record = MARC::Record->new();
$marc_record->append_fields(
MARC::Field->new( '001', '1234567' ),
MARC::Field->new( '020', '', '', 'a' => '1234567890123' ),
MARC::Field->new( '245', '', '', 'a' => 'Title' )
);
my $records = [$marc_record];
my $indexer;
ok(
$indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }),
'Creating a new indexer object'
);
SKIP: {
is(
$indexer->create_index(),
Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_OK(),
'Creating an index'
);
eval { $indexer->get_elasticsearch_params; };
my $marc_record = MARC::Record->new();
$marc_record->append_fields(
MARC::Field->new('001', '1234567'),
MARC::Field->new('020', '', '', 'a' => '1234567890123'),
MARC::Field->new('245', '', '', 'a' => 'Title')
);
my $records = [$marc_record];
ok($indexer->update_index(undef, $records), 'Update Index');
skip 'Elasticsearch configuration not available', 1
if $@;
ok( $indexer->update_index(undef, $records), 'Update Index' );
}
is(
$indexer->drop_index(),
Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_RECREATE_REQUIRED(),
'Dropping the index'
);
};