From 5518f9183054a49c672c94c6d98081da41571668 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 7 May 2020 13:08:14 +0000 Subject: [PATCH] Bug 25342: Unit test Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Joy Nelson --- .../Koha/SearchEngine/Elasticsearch/Indexer.t | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t index 4ce73d8875..3b34c80d39 100644 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::MockModule; use t::lib::Mocks; @@ -70,3 +70,29 @@ subtest 'create_index() tests' => sub { 'Dropping the index' ); }; + + +subtest 'update_index() tests' => sub { + plan tests => 2; + my $kse = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); + $kse->mock( 'marc_records_to_documents', sub { + my ($self, $params ) = @_; + return [1]; + }); + + my $indexer; + ok( + $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }), + 'Creating a new indexer object' + ); + + my $searcher = $indexer->get_elasticsearch(); + my $se = Test::MockModule->new( ref $searcher ); + $se->mock( 'bulk', sub { + my ($self, %params ) = @_; + return $params{body}; + }); + + my $bibnumber_array = $indexer->update_index([13],["faked"]); + is( $bibnumber_array->[0]->{index}->{_id},"13", "We should get a string matching the bibnumber"); +}; -- 2.20.1