Bug 29561: Unit test
authorNick Clemens <nick@bywatersolutions.com>
Thu, 22 Sep 2022 19:51:46 +0000 (19:51 +0000)
committerArthur Suzuki <arthur.suzuki@biblibre.com>
Wed, 14 Dec 2022 14:33:27 +0000 (15:33 +0100)
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit c473480d4e93d0506f7057db1eef34e66b8ddc73)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 5b6b095f1f32cf41aef3e12a2e6374c8f29dbe33)
Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
t/db_dependent/Koha/SearchEngine/Elasticsearch/Search.t

index bb11422..d5fae60 100755 (executable)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 13;
+use Test::More tests => 14;
 use t::lib::Mocks;
 
 use Koha::SearchEngine::Elasticsearch::QueryBuilder;
@@ -86,7 +86,7 @@ SKIP: {
 
     eval { $builder->get_elasticsearch_params; };
 
-    skip 'Elasticsearch configuration not available', 8
+    skip 'Elasticsearch configuration not available', 9
         if $@;
 
     Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'mydb' })->drop_index;
@@ -123,4 +123,33 @@ SKIP: {
         }
     );
     is ($searcher->max_result_window, 12000, 'max_result_window returns the correct value');
+
+    subtest "_convert_facets" => sub {
+        plan tests => 2;
+
+        my $es_facets = {
+            'ln' => {
+                    'sum_other_doc_count' => 0,
+                    'buckets' => [
+                        {
+                            'doc_count' => 2,
+                            'key' => 'eng'
+                        },
+                        {
+                            'doc_count' => 12,
+                            'key' => ''
+                        }
+                    ],
+                    'doc_count_error_upper_bound' => 0
+            }
+        };
+
+        my $koha_facets = $searcher->_convert_facets($es_facets);
+        is(@{$koha_facets->[0]->{facets}},1,"We only get one facet, blank is removed");
+
+        $es_facets->{ln}->{buckets}->[1]->{key} = '0';
+        $koha_facets = $searcher->_convert_facets($es_facets);
+        is(@{$koha_facets->[0]->{facets}},2,"We get two facets, '0' is not removed");
+
+    };
 }