2019-11-20 22:31:18 +03:00
|
|
|
<?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
|
|
|
|
{
|
2019-11-27 22:48:35 +03:00
|
|
|
$expectedDetail = 'No URL found with short code "invalid"';
|
|
|
|
|
2019-11-20 22:31:18 +03:00
|
|
|
$resp = $this->callApiWithKey(self::METHOD_PATCH, '/short-urls/invalid', [RequestOptions::JSON => []]);
|
2019-11-27 22:48:35 +03:00
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
2019-11-20 22:31:18 +03:00
|
|
|
|
|
|
|
$this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
|
2019-11-27 22:48:35 +03:00
|
|
|
$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']);
|
2019-11-20 22:31:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function providingInvalidDataReturnsBadRequest(): void
|
|
|
|
{
|
2019-11-27 22:48:35 +03:00
|
|
|
$expectedDetail = 'Provided data is not valid';
|
|
|
|
|
2019-11-20 22:31:18 +03:00
|
|
|
$resp = $this->callApiWithKey(self::METHOD_PATCH, '/short-urls/invalid', [RequestOptions::JSON => [
|
|
|
|
'maxVisits' => 'not_a_number',
|
|
|
|
]]);
|
2019-11-27 22:48:35 +03:00
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
2019-11-20 22:31:18 +03:00
|
|
|
|
|
|
|
$this->assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode());
|
2019-11-27 22:48:35 +03:00
|
|
|
$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']);
|
2019-11-20 22:31:18 +03:00
|
|
|
}
|
|
|
|
}
|