mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Allowed to provide the domain when creating a short URL
This commit is contained in:
parent
a892f72425
commit
f067d0e831
4 changed files with 50 additions and 6 deletions
|
@ -36,7 +36,8 @@ class CreateShortUrlAction extends AbstractCreateShortUrlAction
|
|||
$this->getOptionalDate($postData, 'validUntil'),
|
||||
$postData['customSlug'] ?? null,
|
||||
$postData['maxVisits'] ?? null,
|
||||
$postData['findIfExists'] ?? null
|
||||
$postData['findIfExists'] ?? null,
|
||||
$postData['domain'] ?? null
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|||
|
||||
use Cake\Chronos\Chronos;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
use function Functional\map;
|
||||
|
@ -33,6 +34,18 @@ class CreateShortUrlActionTest extends ApiTestCase
|
|||
$this->assertEquals('my-cool-slug', $payload['shortCode']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideConflictingSlugs
|
||||
*/
|
||||
public function failsToCreateShortUrlWithDuplicatedSlug(string $slug, ?string $domain): void
|
||||
{
|
||||
[$statusCode, $payload] = $this->createShortUrl(['customSlug' => $slug, 'domain' => $domain]);
|
||||
|
||||
$this->assertEquals(self::STATUS_BAD_REQUEST, $statusCode);
|
||||
$this->assertEquals(RestUtils::INVALID_SLUG_ERROR, $payload['error']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function createsNewShortUrlWithTags(): void
|
||||
{
|
||||
|
@ -126,22 +139,32 @@ class CreateShortUrlActionTest extends ApiTestCase
|
|||
]];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function returnsErrorWhenRequestingReturnExistingButCustomSlugIsInUse(): void
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideConflictingSlugs
|
||||
*/
|
||||
public function returnsErrorWhenRequestingReturnExistingButCustomSlugIsInUse(string $slug, ?string $domain): void
|
||||
{
|
||||
$longUrl = 'https://www.alejandrocelaya.com';
|
||||
|
||||
[$firstStatusCode] = $this->createShortUrl(['longUrl' => $longUrl]);
|
||||
[$secondStatusCode] = $this->createShortUrl([
|
||||
'longUrl' => $longUrl,
|
||||
'customSlug' => 'custom',
|
||||
'customSlug' => $slug,
|
||||
'findIfExists' => true,
|
||||
'domain' => $domain,
|
||||
]);
|
||||
|
||||
$this->assertEquals(self::STATUS_OK, $firstStatusCode);
|
||||
$this->assertEquals(self::STATUS_BAD_REQUEST, $secondStatusCode);
|
||||
}
|
||||
|
||||
public function provideConflictingSlugs(): iterable
|
||||
{
|
||||
yield 'without domain' => ['custom', null];
|
||||
yield 'with domain' => ['custom-with-domain', 'some-domain.com'];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function createsNewShortUrlIfRequestedToFindButThereIsNoMatch(): void
|
||||
{
|
||||
|
|
|
@ -81,13 +81,27 @@ class ListShortUrlsTest extends ApiTestCase
|
|||
'https://blog.alejandrocelaya.com/2019/04/27'
|
||||
. '/considerations-to-properly-use-open-source-software-projects/',
|
||||
],
|
||||
[
|
||||
'shortCode' => 'custom-with-domain',
|
||||
'shortUrl' => 'http://some-domain.com/custom-with-domain',
|
||||
'longUrl' => 'https://google.com',
|
||||
'dateCreated' => '2019-01-01T00:00:00+00:00',
|
||||
'visitsCount' => 0,
|
||||
'tags' => [],
|
||||
'meta' => [
|
||||
'validSince' => null,
|
||||
'validUntil' => null,
|
||||
'maxVisits' => null,
|
||||
],
|
||||
'originalUrl' => 'https://google.com',
|
||||
],
|
||||
],
|
||||
'pagination' => [
|
||||
'currentPage' => 1,
|
||||
'pagesCount' => 1,
|
||||
'itemsPerPage' => 10,
|
||||
'itemsInCurrentPage' => 4,
|
||||
'totalItems' => 4,
|
||||
'itemsInCurrentPage' => 5,
|
||||
'totalItems' => 5,
|
||||
],
|
||||
],
|
||||
], $respPayload);
|
||||
|
|
|
@ -40,6 +40,12 @@ class ShortUrlsFixture extends AbstractFixture
|
|||
))->setShortCode('ghi789');
|
||||
$manager->persist($withDomainShortUrl);
|
||||
|
||||
$withDomainAndSlugShortUrl = $this->setShortUrlDate(new ShortUrl(
|
||||
'https://google.com',
|
||||
ShortUrlMeta::createFromRawData(['domain' => 'some-domain.com'])
|
||||
))->setShortCode('custom-with-domain');
|
||||
$manager->persist($withDomainAndSlugShortUrl);
|
||||
|
||||
$manager->flush();
|
||||
|
||||
$this->addReference('abc123_short_url', $abcShortUrl);
|
||||
|
|
Loading…
Add table
Reference in a new issue