Bug 20607: Make Koha::SearchEngine::Elasticsearch::reset_elasticsearch_mappings take...
[koha.git] / t / db_dependent / Koha / SearchEngine / Elasticsearch / Reset.t
1 #!/usr/bin/perl
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 => 4;
21 use Test::MockModule;
22
23 use Koha::Database;
24
25 my $indexes = {
26     'authorities' => {
27         'Match' => {
28             'label' => 'Match',
29             'type' => '',
30             'weight' => 15,
31             'mappings' => []
32         }
33     },
34     'biblios' => {
35         'title' => {
36             'label' => 'title',
37             'type' => '',
38             'weight' => 20,
39             'mapping' => []
40         }
41     }
42 };
43
44 my $yaml = Test::MockModule->new('YAML::Syck');
45 $yaml->mock( 'LoadFile', sub { return $indexes; } );
46
47 use_ok('Koha::SearchEngine::Elasticsearch');
48
49 my $schema = Koha::Database->new->schema;
50
51 Koha::SearchFields->search->delete;
52 Koha::SearchMarcMaps->search->delete;
53 $schema->resultset('SearchMarcToField')->search->delete;
54
55 Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
56
57 my $search_fields = Koha::SearchFields->search({});
58 is($search_fields->count, 2, 'There is 2 search fields after reset');
59
60 my $match_sf = Koha::SearchFields->search({ name => 'Match' })->next;
61 is($match_sf->weight, '15.00', 'Match search field is weighted with 15');
62
63 my $title_sf = Koha::SearchFields->search({ name => 'title' })->next;
64 is($title_sf->weight, '20.00', 'Title search field is weighted with 20');
65
66 $schema->storage->txn_begin;