mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Updated API tests so that fixture short URLs are created with matching short codes and different domains
This commit is contained in:
@@ -7,9 +7,10 @@ namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
use Cake\Chronos\Chronos;
|
||||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Laminas\Diactoros\Uri;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
use function Functional\first;
|
||||
use function GuzzleHttp\Psr7\build_query;
|
||||
use function sprintf;
|
||||
|
||||
class EditShortUrlActionTest extends ApiTestCase
|
||||
@@ -61,10 +62,9 @@ class EditShortUrlActionTest extends ApiTestCase
|
||||
|
||||
private function findShortUrlMetaByShortCode(string $shortCode): ?array
|
||||
{
|
||||
// FIXME Call GET /short-urls/{shortCode} once issue https://github.com/shlinkio/shlink/issues/628 is fixed
|
||||
$allShortUrls = $this->getJsonResponsePayload($this->callApiWithKey(self::METHOD_GET, '/short-urls'));
|
||||
$list = $allShortUrls['shortUrls']['data'] ?? [];
|
||||
$matchingShortUrl = first($list, fn (array $shortUrl) => $shortUrl['shortCode'] ?? '' === $shortCode);
|
||||
$matchingShortUrl = $this->getJsonResponsePayload(
|
||||
$this->callApiWithKey(self::METHOD_GET, '/short-urls/' . $shortCode),
|
||||
);
|
||||
|
||||
return $matchingShortUrl['meta'] ?? null;
|
||||
}
|
||||
@@ -101,4 +101,37 @@ class EditShortUrlActionTest extends ApiTestCase
|
||||
$this->assertEquals($expectedDetail, $payload['detail']);
|
||||
$this->assertEquals('Invalid data', $payload['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideDomains
|
||||
*/
|
||||
public function metadataIsEditedOnProperShortUrlBasedOnDomain(?string $domain, string $expectedUrl): void
|
||||
{
|
||||
$shortCode = 'ghi789';
|
||||
$url = new Uri(sprintf('/short-urls/%s', $shortCode));
|
||||
|
||||
if ($domain !== null) {
|
||||
$url = $url->withQuery(build_query(['domain' => $domain]));
|
||||
}
|
||||
|
||||
$editResp = $this->callApiWithKey(self::METHOD_PATCH, (string) $url, [RequestOptions::JSON => [
|
||||
'maxVisits' => 100,
|
||||
]]);
|
||||
$editedShortUrl = $this->getJsonResponsePayload($this->callApiWithKey(self::METHOD_GET, (string) $url));
|
||||
|
||||
$this->assertEquals(self::STATUS_NO_CONTENT, $editResp->getStatusCode());
|
||||
$this->assertEquals($domain, $editedShortUrl['domain']);
|
||||
$this->assertEquals($expectedUrl, $editedShortUrl['longUrl']);
|
||||
$this->assertEquals(100, $editedShortUrl['meta']['maxVisits'] ?? null);
|
||||
}
|
||||
|
||||
public function provideDomains(): iterable
|
||||
{
|
||||
yield 'domain' => [null, 'https://shlink.io/documentation/'];
|
||||
yield 'no domain' => [
|
||||
'example.com',
|
||||
'https://blog.alejandrocelaya.com/2019/04/27/considerations-to-properly-use-open-source-software-projects/',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user