Remove device long URLs support

This commit is contained in:
Alejandro Celaya
2024-02-27 18:46:49 +01:00
parent 4ad3dc0bc7
commit 36749658da
35 changed files with 118 additions and 747 deletions

View File

@@ -250,18 +250,6 @@ class CreateShortUrlTest extends ApiTestCase
yield 'empty long url v3' => [['longUrl' => ' '], '3', 'https://shlink.io/api/error/invalid-data'];
yield 'missing url schema v2' => [['longUrl' => 'foo.com'], '2', 'https://shlink.io/api/error/invalid-data'];
yield 'missing url schema v3' => [['longUrl' => 'foo.com'], '3', 'https://shlink.io/api/error/invalid-data'];
yield 'empty device long url v2' => [[
'longUrl' => 'foo',
'deviceLongUrls' => [
'android' => null,
],
], '2', 'https://shlink.io/api/error/invalid-data'];
yield 'empty device long url v3' => [[
'longUrl' => 'foo',
'deviceLongUrls' => [
'ios' => ' ',
],
], '3', 'https://shlink.io/api/error/invalid-data'];
}
#[Test]
@@ -313,22 +301,6 @@ class CreateShortUrlTest extends ApiTestCase
self::assertEquals('http://s.test/🦣🦣🦣', $payload['shortUrl']);
}
#[Test]
public function canCreateShortUrlsWithDeviceLongUrls(): void
{
[$statusCode, $payload] = $this->createShortUrl([
'longUrl' => 'https://github.com/shlinkio/shlink/issues/1557',
'deviceLongUrls' => [
'ios' => 'https://github.com/shlinkio/shlink/ios',
'android' => 'https://github.com/shlinkio/shlink/android',
],
]);
self::assertEquals(self::STATUS_OK, $statusCode);
self::assertEquals('https://github.com/shlinkio/shlink/ios', $payload['deviceLongUrls']['ios'] ?? null);
self::assertEquals('https://github.com/shlinkio/shlink/android', $payload['deviceLongUrls']['android'] ?? null);
}
#[Test]
public function titleIsIgnoredIfLongUrlTimesOut(): void
{

View File

@@ -153,27 +153,4 @@ class EditShortUrlTest extends ApiTestCase
];
yield 'no domain' => [null, 'https://shlink.io/documentation/'];
}
#[Test]
public function deviceLongUrlsCanBeEdited(): void
{
$shortCode = 'def456';
$url = new Uri(sprintf('/short-urls/%s', $shortCode));
$editResp = $this->callApiWithKey(self::METHOD_PATCH, (string) $url, [RequestOptions::JSON => [
'deviceLongUrls' => [
'android' => null, // This one will get removed
'ios' => 'https://blog.alejandrocelaya.com/ios/edited', // This one will be edited
'desktop' => 'https://blog.alejandrocelaya.com/desktop', // This one is new and will be created
],
]]);
$deviceLongUrls = $this->getJsonResponsePayload($editResp)['deviceLongUrls'] ?? [];
self::assertEquals(self::STATUS_OK, $editResp->getStatusCode());
self::assertArrayHasKey('ios', $deviceLongUrls);
self::assertEquals('https://blog.alejandrocelaya.com/ios/edited', $deviceLongUrls['ios']);
self::assertArrayHasKey('desktop', $deviceLongUrls);
self::assertEquals('https://blog.alejandrocelaya.com/desktop', $deviceLongUrls['desktop']);
self::assertArrayHasKey('android', $deviceLongUrls);
self::assertNull($deviceLongUrls['android']);
}
}

View File

@@ -8,7 +8,6 @@ use Cake\Chronos\Chronos;
use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\Core\Model\DeviceType;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
use function count;
@@ -163,123 +162,109 @@ class ListShortUrlsTest extends ApiTestCase
public static function provideFilteredLists(): iterable
{
$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 [[], [
$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),
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,
], 'valid_api_key'];
yield [['excludePastValidUntil' => 'true'], [
$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),
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,
], 'valid_api_key'];
yield [['excludeMaxVisitsReached' => 'true'], [
$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),
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,
], 'valid_api_key'];
yield [['orderBy' => 'shortCode'], [
$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),
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,
], 'valid_api_key'];
yield [['orderBy' => 'shortCode-DESC'], [
$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),
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,
], 'valid_api_key'];
yield [['orderBy' => 'title-DESC'], [
$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),
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,
], 'valid_api_key'];
yield [['startDate' => Chronos::parse('2018-12-01')->toAtomString()], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
$shortUrlMeta,
self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_CUSTOM_SLUG,
self::SHORT_URL_META,
], 'valid_api_key'];
yield [['endDate' => Chronos::parse('2018-12-01')->toAtomString()], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN),
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
$withDeviceLongUrls(self::SHORT_URL_DOCS),
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
self::SHORT_URL_SHLINK_WITH_TITLE,
self::SHORT_URL_DOCS,
], 'valid_api_key'];
yield [['tags' => ['foo']], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
$shortUrlMeta,
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key'];
yield [['tags' => ['bar']], [
$shortUrlMeta,
self::SHORT_URL_META,
], 'valid_api_key'];
yield [['tags' => ['foo', 'bar']], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
$shortUrlMeta,
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key'];
yield [['tags' => ['foo', 'bar'], 'tagsMode' => 'any'], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
$shortUrlMeta,
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key'];
yield [['tags' => ['foo', 'bar'], 'tagsMode' => 'all'], [
$shortUrlMeta,
self::SHORT_URL_META,
], 'valid_api_key'];
yield [['tags' => ['foo', 'bar', 'baz']], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
$shortUrlMeta,
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
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()], [
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key'];
yield [['searchTerm' => 'alejandro'], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
$shortUrlMeta,
self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
], 'valid_api_key'];
yield [['searchTerm' => 'cool'], [
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key'];
yield [['searchTerm' => 'example.com'], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
self::SHORT_URL_CUSTOM_DOMAIN,
], 'valid_api_key'];
yield [[], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_SLUG),
$shortUrlMeta,
$withDeviceLongUrls(self::SHORT_URL_SHLINK_WITH_TITLE),
self::SHORT_URL_CUSTOM_SLUG,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'author_api_key'];
yield [[], [
$withDeviceLongUrls(self::SHORT_URL_CUSTOM_DOMAIN),
self::SHORT_URL_CUSTOM_DOMAIN,
], 'domain_api_key'];
}

View File

@@ -8,6 +8,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Shlinkio\Shlink\Core\Model\DeviceType;
use Shlinkio\Shlink\Core\RedirectRule\Entity\RedirectCondition;
use Shlinkio\Shlink\Core\RedirectRule\Entity\ShortUrlRedirectRule;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
@@ -33,6 +34,12 @@ class ShortUrlRedirectRulesFixture extends AbstractFixture implements DependentF
$helloQueryCondition = RedirectCondition::forQueryParam('hello', 'world');
$manager->persist($helloQueryCondition);
$androidCondition = RedirectCondition::forDevice(DeviceType::ANDROID);
$manager->persist($androidCondition);
$iosCondition = RedirectCondition::forDevice(DeviceType::IOS);
$manager->persist($iosCondition);
$englishAndFooQueryRule = new ShortUrlRedirectRule(
$defShortUrl,
1,
@@ -57,6 +64,22 @@ class ShortUrlRedirectRulesFixture extends AbstractFixture implements DependentF
);
$manager->persist($onlyEnglishRule);
$androidRule = new ShortUrlRedirectRule(
$defShortUrl,
4,
'https://blog.alejandrocelaya.com/android',
new ArrayCollection([$androidCondition]),
);
$manager->persist($androidRule);
$iosRule = new ShortUrlRedirectRule(
$defShortUrl,
5,
'https://blog.alejandrocelaya.com/ios',
new ArrayCollection([$iosCondition]),
);
$manager->persist($iosRule);
$manager->flush();
}
}

View File

@@ -9,7 +9,6 @@ use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use ReflectionObject;
use Shlinkio\Shlink\Core\Model\DeviceType;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
use Shlinkio\Shlink\Core\ShortUrl\Resolver\PersistenceShortUrlRelationResolver;
@@ -49,10 +48,6 @@ class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterf
'apiKey' => $authorApiKey,
'longUrl' =>
'https://blog.alejandrocelaya.com/2017/12/09/acmailer-7-0-the-most-important-release-in-a-long-time/',
'deviceLongUrls' => [
DeviceType::ANDROID->value => 'https://blog.alejandrocelaya.com/android',
DeviceType::IOS->value => 'https://blog.alejandrocelaya.com/ios',
],
'tags' => ['foo', 'bar'],
]), $relationResolver), '2019-01-01 00:00:10');
$manager->persist($defShortUrl);