Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 3; |
20 |
use Test::More tests => 2; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use t::lib::Mocks; |
22 |
use t::lib::Mocks; |
23 |
|
23 |
|
Lines 29-54
my $schema = Koha::Database->schema();
Link Here
|
29 |
|
29 |
|
30 |
use_ok('Koha::SearchEngine::Elasticsearch::Indexer'); |
30 |
use_ok('Koha::SearchEngine::Elasticsearch::Indexer'); |
31 |
|
31 |
|
32 |
my $indexer; |
32 |
subtest 'create_index() tests' => sub { |
33 |
ok( |
33 |
plan tests => 4; |
34 |
$indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblio' }), |
34 |
my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); |
35 |
'Creating new indexer object' |
35 |
$se->mock( 'get_elasticsearch_params', sub { |
36 |
); |
36 |
my ($self, $sub ) = @_; |
|
|
37 |
my $method = $se->original( 'get_elasticsearch_params' ); |
38 |
my $params = $method->( $self ); |
39 |
$params->{index_name} .= '__test'; |
40 |
return $params; |
41 |
}); |
37 |
|
42 |
|
38 |
my $marc_record = MARC::Record->new(); |
43 |
my $indexer; |
39 |
$marc_record->append_fields( |
44 |
ok( |
40 |
MARC::Field->new( '001', '1234567' ), |
45 |
$indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }), |
41 |
MARC::Field->new( '020', '', '', 'a' => '1234567890123' ), |
46 |
'Creating a new indexer object' |
42 |
MARC::Field->new( '245', '', '', 'a' => 'Title' ) |
47 |
); |
43 |
); |
|
|
44 |
my $records = [$marc_record]; |
45 |
|
48 |
|
46 |
SKIP: { |
49 |
is( |
|
|
50 |
$indexer->create_index(), |
51 |
Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_OK(), |
52 |
'Creating an index' |
53 |
); |
47 |
|
54 |
|
48 |
eval { $indexer->get_elasticsearch_params; }; |
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 |
ok($indexer->update_index(undef, $records), 'Update Index'); |
49 |
|
63 |
|
50 |
skip 'Elasticsearch configuration not available', 1 |
64 |
is( |
51 |
if $@; |
65 |
$indexer->drop_index(), |
52 |
|
66 |
Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_RECREATE_REQUIRED(), |
53 |
ok( $indexer->update_index(undef, $records), 'Update Index' ); |
67 |
'Dropping the index' |
54 |
} |
68 |
); |
|
|
69 |
}; |
55 |
- |
|
|