mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Return deviceLongUrls as part of the short URL data and document API changes
This commit is contained in:
@@ -25,8 +25,10 @@ use Shlinkio\Shlink\Core\Visit\Model\VisitType;
|
||||
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
|
||||
use function array_fill_keys;
|
||||
use function count;
|
||||
use function Functional\map;
|
||||
use function Shlinkio\Shlink\Core\enumValues;
|
||||
use function Shlinkio\Shlink\Core\generateRandomShortCode;
|
||||
use function Shlinkio\Shlink\Core\normalizeDate;
|
||||
use function Shlinkio\Shlink\Core\normalizeOptionalDate;
|
||||
@@ -330,7 +332,7 @@ class ShortUrl extends AbstractEntity
|
||||
|
||||
public function deviceLongUrls(): array
|
||||
{
|
||||
$data = [];
|
||||
$data = array_fill_keys(enumValues(DeviceType::class), null);
|
||||
foreach ($this->deviceLongUrls as $deviceUrl) {
|
||||
$data[$deviceUrl->deviceType->value] = $deviceUrl->longUrl();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ class ShortUrlDataTransformer implements DataTransformerInterface
|
||||
'shortCode' => $shortUrl->getShortCode(),
|
||||
'shortUrl' => $this->stringifier->stringify($shortUrl),
|
||||
'longUrl' => $shortUrl->getLongUrl(),
|
||||
'deviceLongUrls' => $shortUrl->deviceLongUrls(),
|
||||
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
|
||||
'tags' => invoke($shortUrl->getTags(), '__toString'),
|
||||
'meta' => $this->buildMeta($shortUrl),
|
||||
|
||||
@@ -52,6 +52,7 @@ class PublishingUpdatesGeneratorTest extends TestCase
|
||||
'shortCode' => $shortUrl->getShortCode(),
|
||||
'shortUrl' => 'http:/' . $shortUrl->getShortCode(),
|
||||
'longUrl' => 'longUrl',
|
||||
'deviceLongUrls' => $shortUrl->deviceLongUrls(),
|
||||
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
|
||||
'visitsCount' => 0,
|
||||
'tags' => [],
|
||||
@@ -129,6 +130,7 @@ class PublishingUpdatesGeneratorTest extends TestCase
|
||||
'shortCode' => $shortUrl->getShortCode(),
|
||||
'shortUrl' => 'http:/' . $shortUrl->getShortCode(),
|
||||
'longUrl' => 'longUrl',
|
||||
'deviceLongUrls' => $shortUrl->deviceLongUrls(),
|
||||
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
|
||||
'visitsCount' => 0,
|
||||
'tags' => [],
|
||||
|
||||
@@ -20,6 +20,9 @@ use Shlinkio\Shlink\Core\ShortUrl\ShortUrlService;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use ShlinkioTest\Shlink\Core\Util\ApiKeyHelpersTrait;
|
||||
|
||||
use function array_fill_keys;
|
||||
use function Shlinkio\Shlink\Core\enumValues;
|
||||
|
||||
class ShortUrlServiceTest extends TestCase
|
||||
{
|
||||
use ApiKeyHelpersTrait;
|
||||
@@ -74,7 +77,7 @@ class ShortUrlServiceTest extends TestCase
|
||||
);
|
||||
|
||||
$resolveDeviceLongUrls = function () use ($shortUrlEdit): array {
|
||||
$result = [];
|
||||
$result = array_fill_keys(enumValues(DeviceType::class), null);
|
||||
foreach ($shortUrlEdit->deviceLongUrls ?? [] as $longUrl) {
|
||||
$result[$longUrl->deviceType->value] = $longUrl->longUrl;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Shlinkio\Shlink\Core\Model\DeviceType;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
use function count;
|
||||
@@ -169,109 +170,124 @@ class ListShortUrlsTest extends ApiTestCase
|
||||
|
||||
public function provideFilteredLists(): iterable
|
||||
{
|
||||
// FIXME Cannot use enums in constants in PHP 8.1. Change this once support for PHP 8.1 is dropped
|
||||
$withDeviceLongUrls = static fn (array $shortUrl, ?array $longUrls = null) => [
|
||||
...$shortUrl,
|
||||
'deviceLongUrls' => $longUrls ?? [
|
||||
DeviceType::ANDROID->value => null,
|
||||
DeviceType::IOS->value => null,
|
||||
DeviceType::DESKTOP->value => null,
|
||||
],
|
||||
];
|
||||
$shortUrlMeta = $withDeviceLongUrls(self::SHORT_URL_META, [
|
||||
DeviceType::ANDROID->value => 'https://blog.alejandrocelaya.com/android',
|
||||
DeviceType::IOS->value => 'https://blog.alejandrocelaya.com/ios',
|
||||
DeviceType::DESKTOP->value => null,
|
||||
]);
|
||||
|
||||
yield [[], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
self::SHORT_URL_DOCS,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
$withDeviceLongUrls(self::SHORT_URL_DOCS),
|
||||
], 'valid_api_key'];
|
||||
yield [['excludePastValidUntil' => 'true'], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'valid_api_key'];
|
||||
yield [['excludeMaxVisitsReached' => 'true'], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
|
||||
self::SHORT_URL_DOCS,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_DOCS),
|
||||
], 'valid_api_key'];
|
||||
yield [['orderBy' => 'shortCode'], [
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_DOCS,
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_DOCS),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
], 'valid_api_key'];
|
||||
yield [['orderBy' => 'shortCode-DESC'], [
|
||||
self::SHORT_URL_DOCS,
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$withDeviceLongUrls(self::SHORT_URL_DOCS),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'valid_api_key'];
|
||||
yield [['orderBy' => 'title-DESC'], [
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_DOCS,
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
|
||||
$withDeviceLongUrls(self::SHORT_URL_DOCS),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'valid_api_key'];
|
||||
yield [['startDate' => Chronos::parse('2018-12-01')->toAtomString()], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_META,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
|
||||
$shortUrlMeta,
|
||||
], 'valid_api_key'];
|
||||
yield [['endDate' => Chronos::parse('2018-12-01')->toAtomString()], [
|
||||
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
self::SHORT_URL_DOCS,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN),
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
$withDeviceLongUrls(self::SHORT_URL_DOCS),
|
||||
], 'valid_api_key'];
|
||||
yield [['tags' => ['foo']], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'valid_api_key'];
|
||||
yield [['tags' => ['bar']], [
|
||||
self::SHORT_URL_META,
|
||||
$shortUrlMeta,
|
||||
], 'valid_api_key'];
|
||||
yield [['tags' => ['foo', 'bar']], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'valid_api_key'];
|
||||
yield [['tags' => ['foo', 'bar'], 'tagsMode' => 'any'], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'valid_api_key'];
|
||||
yield [['tags' => ['foo', 'bar'], 'tagsMode' => 'all'], [
|
||||
self::SHORT_URL_META,
|
||||
$shortUrlMeta,
|
||||
], 'valid_api_key'];
|
||||
yield [['tags' => ['foo', 'bar', 'baz']], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'valid_api_key'];
|
||||
yield [['tags' => ['foo', 'bar', 'baz'], 'tagsMode' => 'all'], [], 'valid_api_key'];
|
||||
yield [['tags' => ['foo'], 'endDate' => Chronos::parse('2018-12-01')->toAtomString()], [
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'valid_api_key'];
|
||||
yield [['searchTerm' => 'alejandro'], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
self::SHORT_URL_META,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
$shortUrlMeta,
|
||||
], 'valid_api_key'];
|
||||
yield [['searchTerm' => 'cool'], [
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'valid_api_key'];
|
||||
yield [['searchTerm' => 'example.com'], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
], 'valid_api_key'];
|
||||
yield [[], [
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
|
||||
$shortUrlMeta,
|
||||
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
|
||||
], 'author_api_key'];
|
||||
yield [[], [
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
|
||||
], 'domain_api_key'];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user