Remove support to validate long URLs during short URL creation/edition

This commit is contained in:
Alejandro Celaya
2024-02-17 12:02:57 +01:00
parent 5c1ab02753
commit e3de403c6c
28 changed files with 198 additions and 619 deletions

View File

@@ -224,27 +224,6 @@ class CreateShortUrlTest extends ApiTestCase
yield ['http://téstb.shlink.io']; // Redirects to http://tést.shlink.io
}
#[Test, DataProvider('provideInvalidUrls')]
public function failsToCreateShortUrlWithInvalidLongUrl(string $url, string $version, string $expectedType): void
{
$expectedDetail = sprintf('Provided URL %s is invalid. Try with a different one.', $url);
[$statusCode, $payload] = $this->createShortUrl(['longUrl' => $url, 'validateUrl' => true], version: $version);
self::assertEquals(self::STATUS_BAD_REQUEST, $statusCode);
self::assertEquals(self::STATUS_BAD_REQUEST, $payload['status']);
self::assertEquals($expectedType, $payload['type']);
self::assertEquals($expectedDetail, $payload['detail']);
self::assertEquals('Invalid URL', $payload['title']);
self::assertEquals($url, $payload['url']);
}
public static function provideInvalidUrls(): iterable
{
yield 'API version 2' => ['https://this-has-to-be-invalid.com', '2', 'https://shlink.io/api/error/invalid-url'];
yield 'API version 3' => ['https://this-has-to-be-invalid.com', '3', 'https://shlink.io/api/error/invalid-url'];
}
#[Test, DataProvider('provideInvalidArgumentApiVersions')]
public function failsToCreateShortUrlWithoutLongUrl(array $payload, string $version, string $expectedType): void
{

View File

@@ -75,28 +75,16 @@ class EditShortUrlTest extends ApiTestCase
return $matchingShortUrl['meta'] ?? [];
}
#[Test, DataProvider('provideLongUrls')]
public function longUrlCanBeEditedIfItIsValid(string $longUrl, int $expectedStatus, ?string $expectedError): void
public function longUrlCanBeEdited(): void
{
$shortCode = 'abc123';
$url = sprintf('/short-urls/%s', $shortCode);
$resp = $this->callApiWithKey(self::METHOD_PATCH, $url, [RequestOptions::JSON => [
'longUrl' => $longUrl,
'validateUrl' => true,
'longUrl' => 'https://shlink.io',
]]);
self::assertEquals($expectedStatus, $resp->getStatusCode());
if ($expectedError !== null) {
$payload = $this->getJsonResponsePayload($resp);
self::assertEquals($expectedError, $payload['type']);
}
}
public static function provideLongUrls(): iterable
{
yield 'valid URL' => ['https://shlink.io', self::STATUS_OK, null];
yield 'invalid URL' => ['http://foo', self::STATUS_BAD_REQUEST, 'https://shlink.io/api/error/invalid-url'];
self::assertEquals(self::STATUS_OK, $resp->getStatusCode());
}
#[Test, DataProviderExternal(ApiTestDataProviders::class, 'invalidUrlsProvider')]