Created API tests for errors when editing a short URL

This commit is contained in:
Alejandro Celaya 2019-11-20 20:31:18 +01:00
parent 98b6dba05d
commit ba6e8c4092
3 changed files with 38 additions and 2 deletions

View file

@ -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

View file

@ -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:

View 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);
}
}