Bugzilla – Attachment 184208 Details for
Bug 40424
Handling query-in-body relies on wrong data structure
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40424: Add missing tests for search in body
Bug-40424-Add-missing-tests-for-search-in-body.patch (text/plain), 3.86 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-07-17 15:01:27 UTC
(
hide
)
Description:
Bug 40424: Add missing tests for search in body
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-07-17 15:01:27 UTC
Size:
3.86 KB
patch
obsolete
>From c1c2c59bea8783ddc019b303c7e2e4616d3a7c49 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 17 Jul 2025 10:57:41 -0300 >Subject: [PATCH] Bug 40424: Add missing tests for search in body > >--- > t/db_dependent/api/v1/query.t | 70 ++++++++++++++++++++++++++++++++++- > 1 file changed, 68 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/api/v1/query.t b/t/db_dependent/api/v1/query.t >index d088995dd73..b2adc30075d 100755 >--- a/t/db_dependent/api/v1/query.t >+++ b/t/db_dependent/api/v1/query.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 4; >+use Test::More tests => 5; > use Test::Mojo; > > use t::lib::TestBuilder; >@@ -27,6 +27,8 @@ use t::lib::Mocks; > use Koha::Cities; > use Koha::Database; > >+use JSON qw(encode_json); >+ > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >@@ -97,6 +99,69 @@ subtest 'q handling tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'q in body handling tests' => sub { >+ >+ plan tests => 15; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**2 } # catalogue flag = 2 >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ # delete all cities >+ Koha::Cities->new->delete; >+ >+ # No cities, so empty array should be returned >+ $t->get_ok("//$userid:$password@/api/v1/cities")->status_is(200)->json_is( [] ); >+ >+ my $names = [ 'AA', 'BA', 'BA', 'CA', 'DA', 'EB', 'FB', 'GB', 'HB', 'IB', ]; >+ >+ # Add 10 cities >+ foreach my $i ( 0 .. 9 ) { >+ $builder->build_object( { class => 'Koha::Cities', value => { city_name => $names->[$i] } } ); >+ } >+ >+ t::lib::Mocks::mock_preference( 'RESTdefaultPageSize', 20 ); >+ >+ my $q_ends_with_a = { "name" => { "-like" => '%A' } }; >+ my $q_ends_with_a_str = encode_json($q_ends_with_a); >+ >+ my $cities = >+ $t->get_ok( "//$userid:$password@/api/v1/cities" => json => $q_ends_with_a )->status_is(200)->tx->res->json; >+ >+ is( scalar @{$cities}, 5, '5 cities retrieved' ); >+ >+ my $q_starts_with_a = { "name" => { "-like" => 'A%' } }; >+ my $q_starts_with_a_str = encode_json($q_starts_with_a); >+ >+ $cities = >+ $t->get_ok( "//$userid:$password@/api/v1/cities?q=$q_starts_with_a_str" => json => $q_ends_with_a ) >+ ->status_is(200)->tx->res->json; >+ >+ is( scalar @{$cities}, 1, 'Mixing query parameter and body, 1 city retrieved' ); >+ >+ $cities = >+ $t->get_ok( "//$userid:$password@/api/v1/cities?q=$q_ends_with_a_str" => json => $q_starts_with_a ) >+ ->status_is(200)->tx->res->json; >+ >+ is( scalar @{$cities}, 1, 'Mixing query parameter and body (flipped), 1 city retrieved' ); >+ >+ $cities = >+ $t->get_ok( "//$userid:$password@/api/v1/cities" => json => { "-and" => [ $q_ends_with_a, $q_starts_with_a ] } ) >+ ->status_is(200)->tx->res->json; >+ >+ is( scalar @{$cities}, 1, 'Body query is passed through, 1 city retrieved' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'x-koha-embed tests' => sub { > > plan tests => 8; >@@ -123,7 +188,8 @@ subtest 'x-koha-embed tests' => sub { > $res = $t->get_ok( "//$userid:$password@/api/v1/patrons?q={\"me.patron_id\":$patron_id}" => > { 'x-koha-embed' => 'extended_attributes,custom_bad_embed,another_bad_embed' } )->status_is(400); > >- $res = $t->get_ok( "//$userid:$password@/api/v1/cities" => { 'x-koha-embed' => 'any_embed' } )->status_is(400) >+ $res = >+ $t->get_ok( "//$userid:$password@/api/v1/cities" => { 'x-koha-embed' => 'any_embed' } )->status_is(400) > ->tx->res->json; > > is( $res, 'Embedding objects is not allowed on this endpoint.', 'Correct error message is returned' ); >-- >2.50.1
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 40424
:
184208
|
184209
|
184210
|
184218
|
184219
|
184220
|
184554
|
184555
|
184556