Bug 38929: Add xt test to enforce REST3.4.1 POST

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jonathan Druart 2025-01-22 11:54:46 +01:00 committed by Katrin Fischer
parent d597123789
commit a5f3859c5c
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 18 additions and 1 deletions

View File

@ -14,7 +14,7 @@
use Modern::Perl;
use Test::More tests => 5;
use Test::More tests => 6;
use Test::Mojo;
use Data::Dumper;
@ -22,6 +22,7 @@ use Data::Dumper;
use FindBin();
use IPC::Cmd qw(can_run);
use List::MoreUtils qw(any);
use File::Slurp qw(read_file);
my $t = Test::Mojo->new('Koha::REST::V1');
my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json;
@ -170,3 +171,19 @@ subtest '400 response tests' => sub {
print STDERR "$error\n";
}
};
subtest 'POST (201) have location header' => sub {
my @files = `git ls-files 'Koha/REST/V1/**/*.pm'`;
plan tests => scalar @files;
foreach my $file (@files) {
chomp $file;
my $content = read_file($file);
if ( $content !~ /status\s*=>\s*201/s ) {
pass("$file does not seem to have a POST endpoint");
} elsif ( $content =~ /\$c->res->headers->location\(.*?\);\s*return\s+\$c->render\s*\(\s*status\s*=>\s*201,/s ) {
pass("$file contains the location header");
} else {
fail("$file does not contain the location header");
}
}
};