mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Created API tests for errors when deleting short URLs
This commit is contained in:
parent
ba6e8c4092
commit
9096318968
@ -9,7 +9,6 @@ use Shlinkio\Shlink\Core\Exception as Core;
|
||||
use Shlinkio\Shlink\Rest\Exception as Rest;
|
||||
use Throwable;
|
||||
|
||||
/** @deprecated */
|
||||
class RestUtils
|
||||
{
|
||||
public const INVALID_SHORTCODE_ERROR = 'INVALID_SHORTCODE';
|
||||
|
37
module/Rest/test-api/Action/DeleteShortUrlActionTest.php
Normal file
37
module/Rest/test-api/Action/DeleteShortUrlActionTest.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
class DeleteShortUrlActionTest extends ApiTestCase
|
||||
{
|
||||
/** @test */
|
||||
public function notFoundErrorIsReturnWhenDeletingInvalidUrl(): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/invalid');
|
||||
['error' => $error] = $this->getJsonResponsePayload($resp);
|
||||
|
||||
$this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
|
||||
$this->assertEquals(RestUtils::INVALID_SHORTCODE_ERROR, $error);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function badRequestIsReturnedWhenTryingToDeleteUrlWithTooManyVisits(): void
|
||||
{
|
||||
// Generate visits first
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$this->assertEquals(self::STATUS_FOUND, $this->callShortUrl('abc123')->getStatusCode());
|
||||
}
|
||||
|
||||
$resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/abc123');
|
||||
['error' => $error] = $this->getJsonResponsePayload($resp);
|
||||
|
||||
$this->assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode());
|
||||
$this->assertEquals(RestUtils::INVALID_SHORTCODE_DELETION_ERROR, $error);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user