From 328fc5ee548241471b9724ea09dda5205f0dea83 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 12 Feb 2021 14:05:13 +0000 Subject: [PATCH] Bug 27680: Add tests for various ways of passing multi-params --- t/db_dependent/Koha/REST/Plugin/Objects.t | 52 +++++++++++++++++++---- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t index 60c9f81192..9d682620a0 100755 --- a/t/db_dependent/Koha/REST/Plugin/Objects.t +++ b/t/db_dependent/Koha/REST/Plugin/Objects.t @@ -196,7 +196,7 @@ subtest 'objects.search helper' => sub { subtest 'objects.search helper, sorting on mapped column' => sub { - plan tests => 14; + plan tests => 31; $schema->storage->txn_begin; @@ -205,23 +205,59 @@ subtest 'objects.search helper, sorting on mapped column' => sub { $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'A', city_country => 'Argentina' } }); $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'B', city_country => 'Argentina' } }); + $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'C', city_country => 'Argentina' } }); + $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'C', city_country => 'Belarus' } }); my $t = Test::Mojo->new; - $t->get_ok('/cities?_order_by=%2Bname&_order_by=+country') + diag("Multi-param: traditional"); + $t->get_ok('/cities?_order_by=+name&_order_by=-country') ->status_is(200) ->json_has('/0') ->json_has('/1') - ->json_hasnt('/2') ->json_is('/0/name' => 'A') - ->json_is('/1/name' => 'B'); - + ->json_is('/1/name' => 'B') + ->json_is('/2/name' => 'C') + ->json_is('/2/country' => 'Belarus') + ->json_is('/3/name' => 'C') + ->json_is('/3/country' => 'Argentina') + ->json_hasnt('/4'); + + diag("Multi-param: with []"); + $t->get_ok('/cities?_order_by[]=+name&_order_by[]=-country') + ->status_is(200) + ->json_has('/0') + ->json_has('/1') + ->json_is('/0/name' => 'A') + ->json_is('/1/name' => 'B') + ->json_is('/2/name' => 'C') + ->json_is('/2/country' => 'Belarus') + ->json_is('/3/name' => 'C') + ->json_is('/3/country' => 'Argentina') + ->json_hasnt('/4'); + + diag("CSV-param"); + $t->get_ok('/cities?_order_by=+name,-country') + ->status_is(200) + ->json_has('/0') + ->json_has('/1') + ->json_is('/0/name' => 'A') + ->json_is('/1/name' => 'B') + ->json_is('/2/name' => 'C') + ->json_is('/2/country' => 'Belarus') + ->json_is('/3/name' => 'C') + ->json_is('/3/country' => 'Argentina') + ->json_hasnt('/4'); + + diag("Single-param"); $t->get_ok('/cities?_order_by=-name') ->status_is(200) ->json_has('/0') ->json_has('/1') - ->json_hasnt('/2') - ->json_is('/0/name' => 'B') - ->json_is('/1/name' => 'A'); + ->json_is('/0/name' => 'C') + ->json_is('/1/name' => 'C') + ->json_is('/2/name' => 'B') + ->json_is('/3/name' => 'A') + ->json_hasnt('/4'); $schema->storage->txn_rollback; }; -- 2.20.1