2019-11-20 22:38:19 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|
|
|
|
|
|
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
|
|
|
|
|
|
|
class DeleteShortUrlActionTest extends ApiTestCase
|
|
|
|
{
|
|
|
|
/** @test */
|
|
|
|
public function notFoundErrorIsReturnWhenDeletingInvalidUrl(): void
|
|
|
|
{
|
2019-11-27 22:48:35 +03:00
|
|
|
$expectedDetail = 'No URL found with short code "invalid"';
|
|
|
|
|
2019-11-20 22:38:19 +03:00
|
|
|
$resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/invalid');
|
2019-11-27 22:48:35 +03:00
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
2019-11-20 22:38:19 +03:00
|
|
|
|
|
|
|
$this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
|
2019-11-27 22:48:35 +03:00
|
|
|
$this->assertEquals(self::STATUS_NOT_FOUND, $payload['status']);
|
|
|
|
$this->assertEquals('INVALID_SHORTCODE', $payload['type']);
|
|
|
|
$this->assertEquals($expectedDetail, $payload['detail']);
|
|
|
|
$this->assertEquals('Short URL not found', $payload['title']);
|
|
|
|
$this->assertEquals('invalid', $payload['shortCode']);
|
2019-11-20 22:38:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
2019-11-25 01:56:02 +03:00
|
|
|
public function unprocessableEntityIsReturnedWhenTryingToDeleteUrlWithTooManyVisits(): void
|
2019-11-20 22:38:19 +03:00
|
|
|
{
|
|
|
|
// Generate visits first
|
|
|
|
for ($i = 0; $i < 20; $i++) {
|
|
|
|
$this->assertEquals(self::STATUS_FOUND, $this->callShortUrl('abc123')->getStatusCode());
|
|
|
|
}
|
2019-11-27 22:48:35 +03:00
|
|
|
$expectedDetail = 'Impossible to delete short URL with short code "abc123" since it has more than "15" visits.';
|
2019-11-20 22:38:19 +03:00
|
|
|
|
|
|
|
$resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/abc123');
|
2019-11-27 22:48:35 +03:00
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
2019-11-20 22:38:19 +03:00
|
|
|
|
2019-11-25 01:56:02 +03:00
|
|
|
$this->assertEquals(self::STATUS_UNPROCESSABLE_ENTITY, $resp->getStatusCode());
|
2019-11-27 22:48:35 +03:00
|
|
|
$this->assertEquals(self::STATUS_UNPROCESSABLE_ENTITY, $payload['status']);
|
|
|
|
$this->assertEquals('INVALID_SHORTCODE_DELETION', $payload['type']);
|
|
|
|
$this->assertEquals($expectedDetail, $payload['detail']);
|
|
|
|
$this->assertEquals('Cannot delete short URL', $payload['title']);
|
2019-11-20 22:38:19 +03:00
|
|
|
}
|
|
|
|
}
|