2019-11-20 22:38:19 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|
|
|
|
|
|
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
2020-02-02 15:15:08 +03:00
|
|
|
use ShlinkioApiTest\Shlink\Rest\Utils\NotFoundUrlHelpersTrait;
|
2019-11-20 22:38:19 +03:00
|
|
|
|
2022-08-13 18:48:55 +03:00
|
|
|
use function sprintf;
|
|
|
|
|
2021-01-24 11:25:36 +03:00
|
|
|
class DeleteShortUrlTest extends ApiTestCase
|
2019-11-20 22:38:19 +03:00
|
|
|
{
|
2020-02-02 15:15:08 +03:00
|
|
|
use NotFoundUrlHelpersTrait;
|
2019-11-27 22:48:35 +03:00
|
|
|
|
2020-02-02 15:15:08 +03:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideInvalidUrls
|
|
|
|
*/
|
|
|
|
public function notFoundErrorIsReturnWhenDeletingInvalidUrl(
|
|
|
|
string $shortCode,
|
|
|
|
?string $domain,
|
2021-01-10 11:02:05 +03:00
|
|
|
string $expectedDetail,
|
2021-05-23 13:31:10 +03:00
|
|
|
string $apiKey,
|
2020-02-02 15:15:08 +03:00
|
|
|
): void {
|
2021-01-10 11:02:05 +03:00
|
|
|
$resp = $this->callApiWithKey(self::METHOD_DELETE, $this->buildShortUrlPath($shortCode, $domain), [], $apiKey);
|
2019-11-27 22:48:35 +03:00
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
2019-11-20 22:38:19 +03:00
|
|
|
|
2020-10-04 01:35:14 +03:00
|
|
|
self::assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
|
|
|
|
self::assertEquals(self::STATUS_NOT_FOUND, $payload['status']);
|
|
|
|
self::assertEquals('INVALID_SHORTCODE', $payload['type']);
|
|
|
|
self::assertEquals($expectedDetail, $payload['detail']);
|
|
|
|
self::assertEquals('Short URL not found', $payload['title']);
|
|
|
|
self::assertEquals($shortCode, $payload['shortCode']);
|
|
|
|
self::assertEquals($domain, $payload['domain'] ?? null);
|
2019-11-20 22:38:19 +03:00
|
|
|
}
|
|
|
|
|
2022-08-13 18:48:55 +03:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideApiVersions
|
|
|
|
*/
|
|
|
|
public function expectedTypeIsReturnedBasedOnApiVersion(string $version, string $expectedType): void
|
|
|
|
{
|
|
|
|
$resp = $this->callApiWithKey(
|
|
|
|
self::METHOD_DELETE,
|
|
|
|
sprintf('/rest/v%s/short-urls/invalid-short-code', $version),
|
|
|
|
);
|
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
|
|
|
|
|
|
|
self::assertEquals($expectedType, $payload['type']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideApiVersions(): iterable
|
|
|
|
{
|
|
|
|
yield ['1', 'INVALID_SHORTCODE'];
|
|
|
|
yield ['2', 'INVALID_SHORTCODE'];
|
|
|
|
yield ['3', 'https://shlink.io/api/error/short-url-not-found'];
|
|
|
|
}
|
|
|
|
|
2020-02-02 12:28:10 +03:00
|
|
|
/** @test */
|
|
|
|
public function properShortUrlIsDeletedWhenDomainIsProvided(): void
|
|
|
|
{
|
2020-02-02 14:58:26 +03:00
|
|
|
$fetchWithDomainBefore = $this->callApiWithKey(self::METHOD_GET, '/short-urls/ghi789?domain=example.com');
|
|
|
|
$fetchWithoutDomainBefore = $this->callApiWithKey(self::METHOD_GET, '/short-urls/ghi789');
|
2020-02-02 12:28:10 +03:00
|
|
|
$deleteResp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/ghi789?domain=example.com');
|
2020-02-02 14:58:26 +03:00
|
|
|
$fetchWithDomainAfter = $this->callApiWithKey(self::METHOD_GET, '/short-urls/ghi789?domain=example.com');
|
|
|
|
$fetchWithoutDomainAfter = $this->callApiWithKey(self::METHOD_GET, '/short-urls/ghi789');
|
2020-02-02 12:28:10 +03:00
|
|
|
|
2020-10-04 01:35:14 +03:00
|
|
|
self::assertEquals(self::STATUS_OK, $fetchWithDomainBefore->getStatusCode());
|
|
|
|
self::assertEquals(self::STATUS_OK, $fetchWithoutDomainBefore->getStatusCode());
|
|
|
|
self::assertEquals(self::STATUS_NO_CONTENT, $deleteResp->getStatusCode());
|
|
|
|
self::assertEquals(self::STATUS_NOT_FOUND, $fetchWithDomainAfter->getStatusCode());
|
|
|
|
self::assertEquals(self::STATUS_OK, $fetchWithoutDomainAfter->getStatusCode());
|
2020-02-02 12:28:10 +03:00
|
|
|
}
|
2019-11-20 22:38:19 +03:00
|
|
|
}
|