From fe167c7177c2a03e77b0a71360d15ca2d491b663 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 24 Mar 2022 09:40:48 -0300 Subject: [PATCH] [OPTION 1] Bug 30165: (follow-up) Address OpenAPI vs. no-OpenAPI in the tests Our objects.search helper is written for being used in our API controllers, which get their query parameters processed by the OpenAPI plugin, using JSON::Validator. Particularly, the 'q' parameter is defined as 'multi' on our spec, which means objects.search always gets it as an arrayref. As the Objects.t tests are not using the OpenAPI plugin, a hashref is generated as only one q= is being passed. This patch adds an extra (empty) q param to the tests to overcome this. To test: 1. Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => FAIL: Tests fail! 2. Apply this patch 3. Repeat 1 => SUCCESS: Tests pass! 4. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/REST/Plugin/Objects.t | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t index 8deee9da7d..1e2d1dce2d 100755 --- a/t/db_dependent/Koha/REST/Plugin/Objects.t +++ b/t/db_dependent/Koha/REST/Plugin/Objects.t @@ -326,7 +326,7 @@ subtest 'objects.search helper, encoding' => sub { $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'B', city_country => '❤Argentina❤' } }); my $t = Test::Mojo->new; - $t->get_ok('/cities?q={"country": "❤Argentina❤"}') + $t->get_ok('/cities?q={"country": "❤Argentina❤"}&q=[]') ->status_is(200) ->json_has('/0') ->json_hasnt('/1') @@ -424,10 +424,10 @@ subtest 'object.search helper with q parameter' => sub { my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); my $t = Test::Mojo->new; - $t->get_ok('/biblios?q={"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}') + $t->get_ok('/biblios?q={"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}&q=[]') ->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); - $t->get_ok('/biblios?q={"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}') + $t->get_ok('/biblios?q={"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}&q=[]') ->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); $schema->storage->txn_rollback; @@ -472,13 +472,13 @@ subtest 'object.search helper with all query methods' => sub { my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); my $t = Test::Mojo->new; - $t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron1->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron1->cardnumber}) + $t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron1->firstname.'"}&q=[]' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron1->cardnumber}) ->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); - $t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron2->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron2->cardnumber}) + $t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron2->firstname.'"}&q=[]' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron2->cardnumber}) ->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); - $t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron1->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron2->cardnumber}) + $t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron1->firstname.'"}&q=[]' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron2->cardnumber}) ->json_is('/count' => 0, 'there shouldn\'t be biblios where suggester has patron1 fistname and patron2 id'); $schema->storage->txn_rollback; -- 2.32.0