mirror of
https://github.com/shlinkio/shlink.git
synced 2026-10-12 21:31:58 -05:00
Created API tests for errors when editing a short URL
This commit is contained in:
1 parent
98b6dba05d
commit
ba6e8c4092
3 files changed
+38
-2
No files matched your search
@@ -9,7 +9,7 @@ echo 'Starting server...'
|
|||||||
vendor/bin/zend-expressive-swoole start -d
|
vendor/bin/zend-expressive-swoole start -d
|
||||||
sleep 2
|
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=$?
|
testsExitCode=$?
|
||||||
|
|
||||||
vendor/bin/zend-expressive-swoole stop
|
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 Shlinkio\Shlink\Rest\Exception as Rest;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
class RestUtils
|
class RestUtils
|
||||||
{
|
{
|
||||||
public const INVALID_SHORTCODE_ERROR = 'INVALID_SHORTCODE';
|
public const INVALID_SHORTCODE_ERROR = 'INVALID_SHORTCODE';
|
||||||
@@ -24,7 +25,8 @@ class RestUtils
|
|||||||
public const NOT_FOUND_ERROR = 'NOT_FOUND';
|
public const NOT_FOUND_ERROR = 'NOT_FOUND';
|
||||||
public const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
|
public const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
|
||||||
|
|
||||||
public static function getRestErrorCodeFromException(Throwable $e)
|
/** @deprecated */
|
||||||
|
public static function getRestErrorCodeFromException(Throwable $e): string
|
||||||
{
|
{
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case $e instanceof Core\InvalidShortCodeException:
|
case $e instanceof Core\InvalidShortCodeException:
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user