mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-23 15:40:33 -06:00
45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|
|
|
use GuzzleHttp\RequestOptions;
|
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
|
|
|
class EditShortUrlActionTest extends ApiTestCase
|
|
{
|
|
/** @test */
|
|
public function tryingToEditInvalidUrlReturnsNotFoundError(): void
|
|
{
|
|
$expectedDetail = 'No URL found with short code "invalid"';
|
|
|
|
$resp = $this->callApiWithKey(self::METHOD_PATCH, '/short-urls/invalid', [RequestOptions::JSON => []]);
|
|
$payload = $this->getJsonResponsePayload($resp);
|
|
|
|
$this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
|
|
$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']);
|
|
}
|
|
|
|
/** @test */
|
|
public function providingInvalidDataReturnsBadRequest(): void
|
|
{
|
|
$expectedDetail = 'Provided data is not valid';
|
|
|
|
$resp = $this->callApiWithKey(self::METHOD_PATCH, '/short-urls/invalid', [RequestOptions::JSON => [
|
|
'maxVisits' => 'not_a_number',
|
|
]]);
|
|
$payload = $this->getJsonResponsePayload($resp);
|
|
|
|
$this->assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode());
|
|
$this->assertEquals(self::STATUS_BAD_REQUEST, $payload['status']);
|
|
$this->assertEquals('INVALID_ARGUMENT', $payload['type']);
|
|
$this->assertEquals($expectedDetail, $payload['detail']);
|
|
$this->assertEquals('Invalid data', $payload['title']);
|
|
}
|
|
}
|