Bugzilla – Attachment 183364 Details for
Bug 40176
Add maxLength to the item definition
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40176: Add tests
Bug-40176-Add-tests.patch (text/plain), 2.90 KB, created by
Jonathan Druart
on 2025-06-19 09:20:23 UTC
(
hide
)
Description:
Bug 40176: Add tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-06-19 09:20:23 UTC
Size:
2.90 KB
patch
obsolete
>From f132eaf00af6c7ecc805306ab1210042bd63d3de Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 19 Jun 2025 11:10:47 +0200 >Subject: [PATCH] Bug 40176: Add tests > >This patch adds a new subtest to xt/api.t >It ensures that maxLength will appear in the rest api spec file when >there is a size constraint at the DB level >--- > xt/api.t | 44 +++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 43 insertions(+), 1 deletion(-) > >diff --git a/xt/api.t b/xt/api.t >index 78cf588c245..7a51a298e7a 100755 >--- a/xt/api.t >+++ b/xt/api.t >@@ -14,15 +14,18 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >+use Test::More tests => 8; >+use Test::NoWarnings; > > use Test::Mojo; > use Data::Dumper; >+use Koha::Database; > > use FindBin(); > use IPC::Cmd qw(can_run); > use List::MoreUtils qw(any); > use File::Slurp qw(read_file); >+use YAML::XS qw(LoadFile); > > my $t = Test::Mojo->new('Koha::REST::V1'); > my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json; >@@ -194,3 +197,42 @@ subtest 'POST (201) have location header' => sub { > } > } > }; >+ >+subtest 'maxlength + enum' => sub { >+ my $def_map = { >+ >+ # api def => schema >+ item => 'Item', >+ }; >+ plan tests => scalar keys %$def_map; >+ my $schema = Koha::Database->new->schema; >+ while ( my ( $def, $dbic_src ) = each %$def_map ) { >+ my @failures; >+ my $definition = LoadFile("api/v1/swagger/definitions/$def.yaml"); >+ my $source = $schema->source($dbic_src); >+ my $object_class = Koha::Object::_get_object_class( $source->result_class ); >+ eval "require $object_class"; >+ my $koha_object = $object_class->new; >+ my $api_mapping = $koha_object->to_api_mapping; >+ my $reversed_api_mapping = >+ { reverse map { defined $api_mapping->{$_} ? ( $_ => $api_mapping->{$_} ) : () } keys %$api_mapping }; >+ >+ while ( my ( $attr, $properties ) = each %{ $definition->{properties} } ) { >+ my $db_col = $reversed_api_mapping->{$attr}; >+ next unless $db_col; >+ my $column_info = $koha_object->_result->column_info($db_col); >+ next unless $column_info->{size}; >+ >+ next if ref( $column_info->{size} ) eq 'ARRAY'; # decimal # FIXME Could have a test for this as well >+ >+ next >+ if $properties->{enum} >+ ; # FIXME This is not fully correct, we might want to make sure enum is set for both DB and spec. eg. now checkprevcheckout is enum only for the api spec >+ >+ if ( !exists $properties->{maxLength} || $column_info->{size} != $properties->{maxLength} ) { >+ push @failures, sprintf "%s.%s should have maxLength=%s in api spec", $def, $attr, $column_info->{size}; >+ } >+ } >+ is( scalar(@failures), 0, "maxLength tests for $def" ) or diag Dumper @failures; >+ } >+}; >-- >2.34.1
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 40176
: 183364 |
183365