test: accept async validation

This commit is contained in:
2026-01-05 07:22:20 +01:00
parent 385084afc5
commit c398ff843d

View File

@@ -134,27 +134,15 @@ subtest 'POST /api/v1/urls - Real validator blocked domains' => sub {
} }
}; };
subtest 'POST /api/v1/urls - Real validator network errors (422)' => sub { subtest 'POST /api/v1/urls - Real validator network errors (async)' => sub {
for my $case ( for
{ my $url ( 'http://nonexistent-domain-12345.invalid', 'http://192.0.2.1' )
url => 'http://nonexistent-domain-12345.invalid',
error => qr/Cannot reach URL|DNS resolution failed/,
},
{
url => 'http://192.0.2.1',
error => qr/Cannot reach URL|Connection refused/,
}
)
{ {
my $res = post_shorten( $case->{url} ); my $res = post_shorten($url);
if ( $res->{code} == 422 ) { ok(
like( $res->{error}, $case->{error}, $res->{code} == 200 || $res->{code} == 400,
"Network error: $case->{url}" ); "Network URL accepted or rejected by format: $url"
} );
else {
diag( "Network error test skipped for $case->{url}: "
. $res->{error} );
}
} }
}; };
@@ -183,12 +171,9 @@ subtest 'POST /api/v1/urls - Real validator invalid URL format' => sub {
} }
my $res = post_shorten('not-a-url'); my $res = post_shorten('not-a-url');
is( $res->{code}, 422, 'Unreachable host rejected: not-a-url' ); is( $res->{code}, 200, 'Bare hostname accepted: not-a-url' );
like( like( $res->{json}->{original_url},
$res->{error}, qr{^http://not-a-url$}, 'Bare hostname normalized with scheme' );
qr/Cannot reach URL|DNS resolution failed|URL validation failed/,
'Correct error for: not-a-url'
);
}; };
subtest 'POST /api/v1/urls - Real validator URL length validation' => sub { subtest 'POST /api/v1/urls - Real validator URL length validation' => sub {