Bugzilla – Attachment 168874 Details for
Bug 36641
Add an endpoint to list circulation rules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36641: Introduce render_invalid_parameter_value helper
Bug-36641-Introduce-renderinvalidparametervalue-he.patch (text/plain), 3.93 KB, created by
Martin Renvoize (ashimema)
on 2024-07-12 10:27:16 UTC
(
hide
)
Description:
Bug 36641: Introduce render_invalid_parameter_value helper
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-07-12 10:27:16 UTC
Size:
3.93 KB
patch
obsolete
>From 957ebac93e44ba8efc95f507be7e888dc96f5c70 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 24 Jun 2024 16:04:01 +0100 >Subject: [PATCH] Bug 36641: Introduce render_invalid_parameter_value helper > >This patch introduces a new 'render_invalid_parameter_value' helper >method that accepts 'path' and 'values' parameters to denote which field >has failed validation and where the end user can get valid options. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/REST/Plugin/Responses.pm | 30 +++++++++++++++++ > t/db_dependent/api/v1/responses.t | 55 ++++++++++++++++++++++++++++++- > 2 files changed, 84 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/Plugin/Responses.pm b/Koha/REST/Plugin/Responses.pm >index ed3f7673629..3b39ac13797 100644 >--- a/Koha/REST/Plugin/Responses.pm >+++ b/Koha/REST/Plugin/Responses.pm >@@ -77,6 +77,36 @@ Provides a generic method rendering the standard response for resource not found > ); > } > ); >+ >+=head3 render_invalid_parameter_value >+ >+ $c->render_invalid_parameter_value >+ >+Provides a generic method rendering the standard response for invalid parameter value passed. >+ >+=cut >+ >+ $app->helper( >+ 'render_invalid_parameter_value' => sub { >+ my ( $c, $opts ) = @_; >+ my $path = $opts->{path}; >+ my $values = $opts->{values}; >+ >+ $c->render( >+ status => 400, >+ openapi => { >+ error => "Invalid parameter value", >+ error_code => 'invalid_parameter_value', >+ path => $path, >+ ( >+ $values >+ ? ( values => { uri => $values->{uri}, field => $values->{field} } ) >+ : () >+ ) >+ }, >+ ); >+ } >+ ); > } > > 1; >diff --git a/t/db_dependent/api/v1/responses.t b/t/db_dependent/api/v1/responses.t >index 5acf2340b4e..575fc33a0cf 100755 >--- a/t/db_dependent/api/v1/responses.t >+++ b/t/db_dependent/api/v1/responses.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; > use Test::MockModule; > use Test::Mojo; > >@@ -115,3 +115,56 @@ subtest 'render_resource_deleted() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'render_invalid_parameter_value() tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $authorized_patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 1 }, >+ } >+ ); >+ my $password = 'thePassword123'; >+ $authorized_patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $authorized_patron->userid; >+ >+ my $path = '/query/library'; >+ my $uri = '/api/v1/libraries'; >+ my $field = 'library_id'; >+ my $mock_cities = Test::MockModule->new('Koha::REST::V1::CirculationRules'); >+ $mock_cities->mock( >+ 'list_effective_rules', >+ sub { >+ my $c = shift->openapi->valid_input or return; >+ return $c->render_invalid_parameter_value( >+ { >+ path => $path, >+ values => { >+ uri => $uri, >+ field => $field >+ } >+ } >+ ); >+ } >+ ); >+ >+ my $t = Test::Mojo->new('Koha::REST::V1'); >+ >+ $t->get_ok("//$userid:$password@/api/v1/circulation_rules?library=SOMETHING")->status_is('400')->json_is( >+ { >+ error => 'Invalid parameter value', >+ error_code => 'invalid_parameter_value', >+ path => $path, >+ values => { >+ uri => $uri, >+ field => $field >+ } >+ } >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.45.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36641
:
165086
|
167937
|
167938
|
167946
|
167947
|
168018
|
168019
|
168020
|
168023
|
168024
|
168025
|
168365
|
168366
|
168367
|
168368
|
168369
|
168370
|
168378
|
168379
|
168395
|
168396
|
168397
|
168398
|
168399
|
168400
|
168401
|
168841
|
168874
|
168875
|
168876
|
168877
|
168878
|
168879
|
168880
|
168881
|
168882
|
168883
|
168884
|
168905
|
168906
|
168907
|
168908
|
168909
|
168910
|
168911
|
168912
|
168913
|
168914
|
168915
|
168916
|
168926
|
168927
|
168928
|
168929
|
168930
|
168931
|
168932
|
168933
|
168934
|
168935
|
168936
|
168937
|
168938
|
168940
|
169013
|
169014
|
169015
|
169016
|
169017
|
169018
|
169019
|
169020
|
169021
|
169022
|
169023
|
169024
|
169025
|
169026