Bugzilla – Attachment 155198 Details for
Bug 33406
Searching for authority with hyphen surrounded by spaces causes error 500 (with ES)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33406: Add tests
Bug-33406-Add-tests.patch (text/plain), 4.27 KB, created by
Pedro Amorim
on 2023-09-04 12:40:48 UTC
(
hide
)
Description:
Bug 33406: Add tests
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2023-09-04 12:40:48 UTC
Size:
4.27 KB
patch
obsolete
>From f96b1d8e644bc96243fa1ad2bd4e120e0e7dfe27 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Mon, 4 Sep 2023 12:28:29 +0000 >Subject: [PATCH] Bug 33406: Add tests > >Test plan: >1) Apply this tests patch only >2) Run: prove t/Koha/SearchEngine/ElasticSearch/Search.t >3) Notice it fails with nasty ES "Failed to parse query" error >4) Apply the other patches >5) Repeat 2) - notice theres no nasty error >--- > t/Koha/SearchEngine/Elasticsearch/Search.t | 76 ++++++++++++++-------- > 1 file changed, 50 insertions(+), 26 deletions(-) > >diff --git a/t/Koha/SearchEngine/Elasticsearch/Search.t b/t/Koha/SearchEngine/Elasticsearch/Search.t >index a6ffd42069..046767cf01 100755 >--- a/t/Koha/SearchEngine/Elasticsearch/Search.t >+++ b/t/Koha/SearchEngine/Elasticsearch/Search.t >@@ -24,41 +24,65 @@ use t::lib::Mocks; > use_ok('Koha::SearchEngine::Elasticsearch::Search'); > > subtest 'search_auth_compat' => sub { >- plan tests => 2; >+ plan tests => 4; > >- t::lib::Mocks::mock_preference('QueryRegexEscapeOptions', 'dont_escape'); >+ t::lib::Mocks::mock_preference( 'QueryRegexEscapeOptions', 'dont_escape' ); > >- my $module = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search'); >- $module->mock('count_auth_use', sub { return 1 }); >- $module->mock('search', sub { >- # While the 001 and the authid should be the same, it is not always the case >- # The _id is always the authid and so should be our source of trutch >- my $marc_record = MARC::Record->new(); >- $marc_record->append_fields( >- MARC::Field->new('001', 'Wrong001Number'), >- ); >- return { >- hits => { >- hits => [{ >- '_id' => 8675309, >- '_source' => { >- 'local-number' => ['Wrong001Number'], >- 'marc_data' => $marc_record, >- 'marc_format' => 'base64ISO2709', >- }, >- }] >- } >- }; >- }); > my $search; > ok( >- $search = Koha::SearchEngine::Elasticsearch::Search->new({ 'index' => $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX }), >+ $search = Koha::SearchEngine::Elasticsearch::Search->new( >+ { index => $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX } >+ ), > 'Creating a new Search object' > ); > >+ my $builder; >+ ok( >+ $builder = >+ Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX } ), >+ 'Creating a new Builder object' >+ ); >+ >+ my $search_query = $builder->build_authorities_query_compat( >+ ['mainmainentry'], ['and'], [''], ['contains'], >+ ['Donald - Duck'], '', 'HeadingAsc' >+ ); >+ >+ my ( $bad_results, undef ) = $search->search_auth_compat( $search_query, 0, 20, undef ); >+ >+ is( @$bad_results[0], undef, 'We expect no record because it doesnt exist' ); >+ >+ my $module = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search'); >+ $module->mock( 'count_auth_use', sub { return 1 } ); >+ $module->mock( >+ 'search', >+ sub { >+ # While the 001 and the authid should be the same, it is not always the case >+ # The _id is always the authid and so should be our source of trutch >+ my $marc_record = MARC::Record->new(); >+ $marc_record->append_fields( >+ MARC::Field->new( '001', 'Wrong001Number' ), >+ ); >+ return { >+ hits => { >+ hits => [ >+ { >+ '_id' => 8675309, >+ '_source' => { >+ 'local-number' => ['Wrong001Number'], >+ 'marc_data' => $marc_record, >+ 'marc_format' => 'base64ISO2709', >+ }, >+ } >+ ] >+ } >+ }; >+ } >+ ); >+ > my ( $results, undef ) = $search->search_auth_compat('faked'); > >- is( @$results[0]->{authid}, '8675309', 'We get the expected record _id and not the 001'); >+ is( @$results[0]->{authid}, '8675309', 'We get the expected record _id and not the 001' ); > > }; > >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33406
:
151067
|
154313
|
154314
|
155198
|
155199
|
155200
|
155611
|
155612
|
155613
|
155614
|
155818