From d7b1e62730cdf81e6de08d6625f75b77bc595bee Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Sat, 13 Jul 2024 13:12:09 +0100 Subject: [PATCH] Bug 36641: (follow-up) Ensure limited return works We have a ?rules=a,b parameter available for specifying a subset of rules in the set to return. This patch adds a test to confirm that works (and fixes the controller and specification as the test proved it wasn't working) --- Koha/REST/V1/CirculationRules.pm | 5 ++++- api/v1/swagger/paths/circulation_rules.yaml | 2 +- t/db_dependent/api/v1/circulation_rules.t | 8 ++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Koha/REST/V1/CirculationRules.pm b/Koha/REST/V1/CirculationRules.pm index 320be889611..41cb1cdf06a 100644 --- a/Koha/REST/V1/CirculationRules.pm +++ b/Koha/REST/V1/CirculationRules.pm @@ -51,7 +51,10 @@ sub list_rules { return try { my $effective = $c->param('effective') // 1; - my $kinds = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ]; + my $kinds = + defined( $c->param('rules') ) + ? [ split /\s*,\s*/, $c->param('rules') ] + : [ keys %{ Koha::CirculationRules->rule_kinds } ]; my $item_type = $c->param('item_type_id'); my $branchcode = $c->param('library_id'); my $patron_category = $c->param('patron_category_id'); diff --git a/api/v1/swagger/paths/circulation_rules.yaml b/api/v1/swagger/paths/circulation_rules.yaml index 1c146682201..76bf33b7d15 100644 --- a/api/v1/swagger/paths/circulation_rules.yaml +++ b/api/v1/swagger/paths/circulation_rules.yaml @@ -36,7 +36,7 @@ type: array items: type: string - collectionFormat: multi + collectionFormat: csv responses: "200": description: A list of rules for this item type, library and patron category combination diff --git a/t/db_dependent/api/v1/circulation_rules.t b/t/db_dependent/api/v1/circulation_rules.t index da9913bb6cb..8be6e47fa4d 100755 --- a/t/db_dependent/api/v1/circulation_rules.t +++ b/t/db_dependent/api/v1/circulation_rules.t @@ -36,7 +36,7 @@ subtest 'list_rules() tests' => sub { my $expected_rules = [ keys %{ Koha::CirculationRules->rule_kinds } ]; - plan tests => ( scalar( @{$expected_rules} ) * 2 ) + 36; + plan tests => ( scalar( @{$expected_rules} ) * 2 ) + 39; $schema->storage->txn_begin; @@ -139,9 +139,13 @@ subtest 'list_rules() tests' => sub { ); $t->get_ok("//$userid:$password@/api/v1/circulation_rules")->status_is(200) - ->json_is( '/0/fine' => 2, "Defaul fine rule returned when no library is added to request query" ) + ->json_is( '/0/fine' => 2, "Default fine rule returned when no library is added to request query" ) ->json_is( '/0/finedays' => 5, "Default finedays rule returned when no library is added to request query" ); + # Limit to only rules we're interested in + $t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules=fine,finedays")->status_is(200) + ->json_is( '/0' => { fine => 2, finedays => 5 }, "Only the two rules we asked for are returned" ); + # Warn on unsupported query parameter $t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules_blah=blah")->status_is(400) ->json_is( [ { path => '/query/rules_blah', message => 'Malformed query string' } ] ); -- 2.45.2