Lines 19-32
use Test::NoWarnings;
Link Here
|
19 |
|
19 |
|
20 |
use Test::Mojo; |
20 |
use Test::Mojo; |
21 |
use Data::Dumper; |
21 |
use Data::Dumper; |
22 |
use Koha::Database; |
22 |
use PPI; |
23 |
|
|
|
24 |
use FindBin(); |
23 |
use FindBin(); |
25 |
use IPC::Cmd qw(can_run); |
24 |
use IPC::Cmd qw(can_run); |
26 |
use List::MoreUtils qw(any); |
25 |
use List::MoreUtils qw(any); |
27 |
use File::Slurp qw(read_file); |
26 |
use File::Slurp qw(read_file); |
28 |
use YAML::XS qw(LoadFile); |
27 |
use YAML::XS qw(LoadFile); |
29 |
|
28 |
|
|
|
29 |
use Koha::Database; |
30 |
|
30 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
31 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
31 |
my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json; |
32 |
my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json; |
32 |
|
33 |
|
Lines 176-199
subtest '400 response tests' => sub {
Link Here
|
176 |
}; |
177 |
}; |
177 |
|
178 |
|
178 |
subtest 'POST (201) have location header' => sub { |
179 |
subtest 'POST (201) have location header' => sub { |
179 |
my @files = `git ls-files 'Koha/REST/V1/**/*.pm'`; |
180 |
my @files = `git ls-files 'Koha/REST/V1/**/*.pm'`; |
180 |
plan tests => scalar @files; |
181 |
my $exceptions = { |
181 |
my @exceptions = qw( |
182 |
'Koha/REST/V1/Auth/Password.pm' => [qw(validate)], |
182 |
Koha/REST/V1/Auth/Password.pm |
183 |
'Koha/REST/V1/ERM/EHoldings/Titles/Local.pm' => [qw(import_from_list import_from_kbart_file)], |
183 |
Koha/REST/V1/Preservation/WaitingList.pm |
184 |
'Koha/REST/V1/Preservation/Trains.pm' => [qw(add_item add_items copy_item)], |
184 |
); |
185 |
'Koha/REST/V1/Preservation/WaitingList.pm' => [qw(add_items)], |
|
|
186 |
}; |
185 |
foreach my $file (@files) { |
187 |
foreach my $file (@files) { |
186 |
chomp $file; |
188 |
chomp $file; |
187 |
my $content = read_file($file); |
189 |
my $doc = PPI::Document->new($file); |
188 |
if ( grep { $file eq $_ } @exceptions ) { |
190 |
my $subs = $doc->find( sub { $_[1]->isa('PPI::Statement::Sub') } ); |
189 |
pass("$file is skipped - exception"); |
191 |
|
190 |
} elsif ( $content !~ /status\s*=>\s*201/s ) { |
192 |
foreach my $sub (@$subs) { |
191 |
pass("$file does not seem to have a POST endpoint"); |
193 |
my $name = $sub->name; |
192 |
} elsif ( $content =~ /\$c->res->headers->location\(.*?\);\s*return\s+\$c->render\s*\(\s*status\s*=>\s*201,/s ) |
194 |
if ( exists $exceptions->{$file} && grep { $name eq $_ } @{ $exceptions->{$file} } ) { |
193 |
{ |
195 |
pass("$file:$name is skipped - exception"); |
194 |
pass("$file contains the location header"); |
196 |
next; |
195 |
} else { |
197 |
} |
196 |
fail("$file does not contain the location header"); |
198 |
|
|
|
199 |
my $content = $sub->content; |
200 |
|
201 |
if ( $content =~ /\$c->res->headers->location\(.*?\);\s*return\s+\$c->render\s*\(\s*status\s*=>\s*201,/s ) { |
202 |
pass("$file:$name contains the location header"); |
203 |
} elsif ( $content =~ /\$c->res->headers->location\(.*?\);/ ) { |
204 |
if ( $content !~ /return\s+\$c->render\s*\(\s*status\s*=>\s*201,/ ) { |
205 |
fail("$file:$name has the location header without 201"); |
206 |
} else { |
207 |
fail("$file:$name has the location header and 201, but other statements should be between them"); |
208 |
} |
209 |
} elsif ( $content !~ /status\s*=>\s*201/s ) { |
210 |
pass("$file:$name does not seem to have a POST endpoint"); |
211 |
} else { |
212 |
fail("$file:$name does not contain the location header"); |
213 |
} |
197 |
} |
214 |
} |
198 |
} |
215 |
} |
199 |
}; |
216 |
}; |
200 |
- |
|
|