|
Lines 14-28
Link Here
|
| 14 |
|
14 |
|
| 15 |
use Modern::Perl; |
15 |
use Modern::Perl; |
| 16 |
|
16 |
|
| 17 |
use Test::More tests => 6; |
17 |
use Test::More tests => 8; |
|
|
18 |
use Test::NoWarnings; |
| 18 |
|
19 |
|
| 19 |
use Test::Mojo; |
20 |
use Test::Mojo; |
| 20 |
use Data::Dumper; |
21 |
use Data::Dumper; |
|
|
22 |
use Koha::Database; |
| 21 |
|
23 |
|
| 22 |
use FindBin(); |
24 |
use FindBin(); |
| 23 |
use IPC::Cmd qw(can_run); |
25 |
use IPC::Cmd qw(can_run); |
| 24 |
use List::MoreUtils qw(any); |
26 |
use List::MoreUtils qw(any); |
| 25 |
use File::Slurp qw(read_file); |
27 |
use File::Slurp qw(read_file); |
|
|
28 |
use YAML::XS qw(LoadFile); |
| 26 |
|
29 |
|
| 27 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
30 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 28 |
my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json; |
31 |
my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json; |
|
Lines 194-196
subtest 'POST (201) have location header' => sub {
Link Here
|
| 194 |
} |
197 |
} |
| 195 |
} |
198 |
} |
| 196 |
}; |
199 |
}; |
| 197 |
- |
200 |
|
|
|
201 |
subtest 'maxlength + enum' => sub { |
| 202 |
my $def_map = { |
| 203 |
|
| 204 |
# api def => schema |
| 205 |
item => 'Item', |
| 206 |
}; |
| 207 |
plan tests => scalar keys %$def_map; |
| 208 |
my $schema = Koha::Database->new->schema; |
| 209 |
while ( my ( $def, $dbic_src ) = each %$def_map ) { |
| 210 |
my @failures; |
| 211 |
my $definition = LoadFile("api/v1/swagger/definitions/$def.yaml"); |
| 212 |
my $source = $schema->source($dbic_src); |
| 213 |
my $object_class = Koha::Object::_get_object_class( $source->result_class ); |
| 214 |
eval "require $object_class"; |
| 215 |
my $koha_object = $object_class->new; |
| 216 |
my $api_mapping = $koha_object->to_api_mapping; |
| 217 |
my $reversed_api_mapping = |
| 218 |
{ reverse map { defined $api_mapping->{$_} ? ( $_ => $api_mapping->{$_} ) : () } keys %$api_mapping }; |
| 219 |
|
| 220 |
while ( my ( $attr, $properties ) = each %{ $definition->{properties} } ) { |
| 221 |
my $db_col = $reversed_api_mapping->{$attr}; |
| 222 |
next unless $db_col; |
| 223 |
my $column_info = $koha_object->_result->column_info($db_col); |
| 224 |
next unless $column_info->{size}; |
| 225 |
|
| 226 |
next if ref( $column_info->{size} ) eq 'ARRAY'; # decimal # FIXME Could have a test for this as well |
| 227 |
|
| 228 |
next |
| 229 |
if $properties->{enum} |
| 230 |
; # 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 |
| 231 |
|
| 232 |
if ( !exists $properties->{maxLength} || $column_info->{size} != $properties->{maxLength} ) { |
| 233 |
push @failures, sprintf "%s.%s should have maxLength=%s in api spec", $def, $attr, $column_info->{size}; |
| 234 |
} |
| 235 |
} |
| 236 |
is( scalar(@failures), 0, "maxLength tests for $def" ) or diag Dumper @failures; |
| 237 |
} |
| 238 |
}; |