mirror of
https://github.com/shlinkio/shlink.git
synced 2026-08-13 06:24:44 -05:00
Refactored short URL creation so that the long URL is part of the ShortUrlMeta
This commit is contained in:
@@ -212,10 +212,12 @@ class CreateShortUrlTest extends ApiTestCase
|
||||
yield ['http://téstb.shlink.io']; // Redirects to http://tést.shlink.io
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function failsToCreateShortUrlWithInvalidLongUrl(): void
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideInvalidUrls
|
||||
*/
|
||||
public function failsToCreateShortUrlWithInvalidLongUrl(string $url): void
|
||||
{
|
||||
$url = 'https://this-has-to-be-invalid.com';
|
||||
$expectedDetail = sprintf('Provided URL %s is invalid. Try with a different one.', $url);
|
||||
|
||||
[$statusCode, $payload] = $this->createShortUrl(['longUrl' => $url]);
|
||||
@@ -228,6 +230,25 @@ class CreateShortUrlTest extends ApiTestCase
|
||||
self::assertEquals($url, $payload['url']);
|
||||
}
|
||||
|
||||
public function provideInvalidUrls(): iterable
|
||||
{
|
||||
yield 'empty URL' => [''];
|
||||
yield 'non-reachable URL' => ['https://this-has-to-be-invalid.com'];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function failsToCreateShortUrlWithoutLongUrl(): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_POST, '/short-urls', [RequestOptions::JSON => []]);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
self::assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode());
|
||||
self::assertEquals(self::STATUS_BAD_REQUEST, $payload['status']);
|
||||
self::assertEquals('INVALID_ARGUMENT', $payload['type']);
|
||||
self::assertEquals('Provided data is not valid', $payload['detail']);
|
||||
self::assertEquals('Invalid data', $payload['title']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function defaultDomainIsDroppedIfProvided(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user