From a0f7c4c33b8d5781ad3f5a4ea35bee867dcd7913 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) Signed-off-by: Tomas Cohen Arazi Signed-off-by: Katrin Fischer --- Koha/REST/V1/CirculationRules.pm | 5 ++++- api/v1/swagger/paths/circulation_rules.yaml | 5 +---- t/db_dependent/api/v1/circulation_rules.t | 8 ++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Koha/REST/V1/CirculationRules.pm b/Koha/REST/V1/CirculationRules.pm index 320be88961..41cb1cdf06 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 1c14668220..eeba8a20b4 100644 --- a/api/v1/swagger/paths/circulation_rules.yaml +++ b/api/v1/swagger/paths/circulation_rules.yaml @@ -33,10 +33,7 @@ in: query description: A comma-separated list of rule kinds required: false - type: array - items: - type: string - collectionFormat: multi + type: string 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 da9913bb6c..8be6e47fa4 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.39.5