mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Moved InvalidShortCode exception handling to problem details
This commit is contained in:
@@ -8,7 +8,6 @@ use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
|
||||
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlAction;
|
||||
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||
@@ -29,7 +28,7 @@ class EditShortUrlActionTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function invalidDataReturnsError()
|
||||
public function invalidDataReturnsError(): void
|
||||
{
|
||||
$request = (new ServerRequest())->withParsedBody([
|
||||
'maxVisits' => 'invalid',
|
||||
@@ -45,28 +44,7 @@ class EditShortUrlActionTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function incorrectShortCodeReturnsError()
|
||||
{
|
||||
$request = (new ServerRequest())->withAttribute('shortCode', 'abc123')
|
||||
->withParsedBody([
|
||||
'maxVisits' => 5,
|
||||
]);
|
||||
$updateMeta = $this->shortUrlService->updateMetadataByShortCode(Argument::cetera())->willThrow(
|
||||
InvalidShortCodeException::class
|
||||
);
|
||||
|
||||
/** @var JsonResponse $resp */
|
||||
$resp = $this->action->handle($request);
|
||||
$payload = $resp->getPayload();
|
||||
|
||||
$this->assertEquals(404, $resp->getStatusCode());
|
||||
$this->assertEquals(RestUtils::INVALID_SHORTCODE_ERROR, $payload['error']);
|
||||
$this->assertEquals('No URL found for short code "abc123"', $payload['message']);
|
||||
$updateMeta->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function correctShortCodeReturnsSuccess()
|
||||
public function correctShortCodeReturnsSuccess(): void
|
||||
{
|
||||
$request = (new ServerRequest())->withAttribute('shortCode', 'abc123')
|
||||
->withParsedBody([
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
|
||||
use Shlinkio\Shlink\Core\Service\ShortUrlService;
|
||||
use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlTagsAction;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
@@ -26,28 +25,14 @@ class EditShortUrlTagsActionTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function notProvidingTagsReturnsError()
|
||||
public function notProvidingTagsReturnsError(): void
|
||||
{
|
||||
$response = $this->action->handle((new ServerRequest())->withAttribute('shortCode', 'abc123'));
|
||||
$this->assertEquals(400, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function anInvalidShortCodeReturnsNotFound()
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willThrow(InvalidShortCodeException::class)
|
||||
->shouldBeCalledOnce();
|
||||
|
||||
$response = $this->action->handle(
|
||||
(new ServerRequest())->withAttribute('shortCode', 'abc123')
|
||||
->withParsedBody(['tags' => []])
|
||||
);
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function tagsListIsReturnedIfCorrectShortCodeIsProvided()
|
||||
public function tagsListIsReturnedIfCorrectShortCodeIsProvided(): void
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl(''))
|
||||
|
||||
Reference in New Issue
Block a user