From 071fbf9be9a5b6a05fef981c6f9bb4f1226c79a2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 22 Jan 2025 11:54:46 +0100 Subject: [PATCH] Bug 38929: Add xt test to enforce REST3.4.1 POST --- xt/api.t | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/xt/api.t b/xt/api.t index 6dd35af3b2d..47e00460db2 100755 --- a/xt/api.t +++ b/xt/api.t @@ -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"); + } + } +}; -- 2.34.1