mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 15:13:59 -06:00
Created API tests for errors when editing a short URL
This commit is contained in:
parent
98b6dba05d
commit
ba6e8c4092
@ -9,7 +9,7 @@ echo 'Starting server...'
|
||||
vendor/bin/zend-expressive-swoole start -d
|
||||
sleep 2
|
||||
|
||||
vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox --colors=always
|
||||
vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox --colors=always $*
|
||||
testsExitCode=$?
|
||||
|
||||
vendor/bin/zend-expressive-swoole stop
|
||||
|
@ -9,6 +9,7 @@ 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';
|
||||
@ -24,7 +25,8 @@ class RestUtils
|
||||
public const NOT_FOUND_ERROR = 'NOT_FOUND';
|
||||
public const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
|
||||
|
||||
public static function getRestErrorCodeFromException(Throwable $e)
|
||||
/** @deprecated */
|
||||
public static function getRestErrorCodeFromException(Throwable $e): string
|
||||
{
|
||||
switch (true) {
|
||||
case $e instanceof Core\InvalidShortCodeException:
|
||||
|
34
module/Rest/test-api/Action/EditShortUrlActionTest.php
Normal file
34
module/Rest/test-api/Action/EditShortUrlActionTest.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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 EditShortUrlActionTest extends ApiTestCase
|
||||
{
|
||||
/** @test */
|
||||
public function tryingToEditInvalidUrlReturnsNotFoundError(): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_PATCH, '/short-urls/invalid', [RequestOptions::JSON => []]);
|
||||
['error' => $error] = $this->getJsonResponsePayload($resp);
|
||||
|
||||
$this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
|
||||
$this->assertEquals(RestUtils::INVALID_SHORTCODE_ERROR, $error);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function providingInvalidDataReturnsBadRequest(): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_PATCH, '/short-urls/invalid', [RequestOptions::JSON => [
|
||||
'maxVisits' => 'not_a_number',
|
||||
]]);
|
||||
['error' => $error] = $this->getJsonResponsePayload($resp);
|
||||
|
||||
$this->assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode());
|
||||
$this->assertEquals(RestUtils::INVALID_ARGUMENT_ERROR, $error);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user