mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-09 16:53:11 +08:00
Created new service to resolve short URLs
This commit is contained in:
@@ -4,10 +4,42 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class ResolveShortUrlActionTest extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideDisabledMeta
|
||||
*/
|
||||
public function shortUrlIsProperlyResolvedEvenWhenNotEnabled(array $disabledMeta): void
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$url = sprintf('/short-urls/%s', $shortCode);
|
||||
$this->callShortUrl($shortCode);
|
||||
|
||||
$editResp = $this->callApiWithKey(self::METHOD_PATCH, $url, [RequestOptions::JSON => $disabledMeta]);
|
||||
$visitResp = $this->callShortUrl($shortCode);
|
||||
$fetchResp = $this->callApiWithKey(self::METHOD_GET, $url);
|
||||
|
||||
$this->assertEquals(self::STATUS_NO_CONTENT, $editResp->getStatusCode());
|
||||
$this->assertEquals(self::STATUS_NOT_FOUND, $visitResp->getStatusCode());
|
||||
$this->assertEquals(self::STATUS_OK, $fetchResp->getStatusCode());
|
||||
}
|
||||
|
||||
public function provideDisabledMeta(): iterable
|
||||
{
|
||||
$now = Chronos::now();
|
||||
|
||||
yield 'future validSince' => [['validSince' => $now->addMonth()->toAtomString()]];
|
||||
yield 'past validUntil' => [['validUntil' => $now->subMonth()->toAtomString()]];
|
||||
yield 'maxVisits reached' => [['maxVisits' => 1]];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function tryingToResolveInvalidUrlReturnsNotFoundError(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user