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 <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Martin Renvoize 2024-07-13 13:12:09 +01:00 committed by Katrin Fischer
parent 0990a6d66b
commit a0f7c4c33b
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 11 additions and 7 deletions

View File

@ -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');

View File

@ -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

View File

@ -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' } ] );