From 201f25e0ad698d3f760787c82e46e80a1b785f3d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 11 Dec 2022 13:38:11 +0100 Subject: [PATCH] Improved API tests to cover exlucding disabled URLs from lists --- CHANGELOG.md | 7 +++++++ .../Rest/test-api/Action/ListShortUrlsTest.php | 18 ++++++++++++++++-- .../test-api/Fixtures/ShortUrlsFixture.php | 9 ++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cbab421..31cd05d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this ## [Unreleased] ### Added +* [#1612](https://github.com/shlinkio/shlink/issues/1612) Allowed to filter short URLs out of lists, when `validUntil` date is in the past or have reached their maximum amount of visits. + + This can be done by: + + * Providing `excludeMaxVisitsReached=true` and/or `excludePastValidUntil=true` to the `GET /short-urls` endpoint. + * Providing `--exclude-max-visits-reached` and/or `--exclude-past-valid-until` to the `short-urls:list` command. + * [#1616](https://github.com/shlinkio/shlink/issues/1616) Added support to import orphan visits when importing short URLs from another Shlink instance. * [#1519](https://github.com/shlinkio/shlink/issues/1519) Allowing to search short URLs by default domain. * [#1555](https://github.com/shlinkio/shlink/issues/1555) Added full support for PHP 8.2, pdating the dockr image to this version. diff --git a/module/Rest/test-api/Action/ListShortUrlsTest.php b/module/Rest/test-api/Action/ListShortUrlsTest.php index b28a0b5d..63664a6d 100644 --- a/module/Rest/test-api/Action/ListShortUrlsTest.php +++ b/module/Rest/test-api/Action/ListShortUrlsTest.php @@ -22,7 +22,7 @@ class ListShortUrlsTest extends ApiTestCase 'meta' => [ 'validSince' => null, 'validUntil' => null, - 'maxVisits' => null, + 'maxVisits' => 2, ], 'domain' => null, 'title' => 'My cool title', @@ -38,7 +38,7 @@ class ListShortUrlsTest extends ApiTestCase 'tags' => [], 'meta' => [ 'validSince' => null, - 'validUntil' => null, + 'validUntil' => '2020-05-01T00:00:00+00:00', 'maxVisits' => null, ], 'domain' => null, @@ -147,6 +147,20 @@ class ListShortUrlsTest extends ApiTestCase self::SHORT_URL_SHLINK_WITH_TITLE, 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, + ], '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, + ], 'valid_api_key']; yield [['orderBy' => 'shortCode'], [ self::SHORT_URL_SHLINK_WITH_TITLE, self::SHORT_URL_CUSTOM_SLUG, diff --git a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php index eadf60ee..432e5cad 100644 --- a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php +++ b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php @@ -36,6 +36,7 @@ class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterf 'tags' => ['foo'], 'title' => 'My cool title', 'crawlable' => true, + 'maxVisits' => 2, ]), $relationResolver), '2018-05-01', ); @@ -61,9 +62,11 @@ class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterf $manager->persist($customShortUrl); $ghiShortUrl = $this->setShortUrlDate( - ShortUrl::fromMeta(ShortUrlCreation::fromRawData( - ['customSlug' => 'ghi789', 'longUrl' => 'https://shlink.io/documentation/'], - )), + ShortUrl::fromMeta(ShortUrlCreation::fromRawData([ + 'customSlug' => 'ghi789', + 'longUrl' => 'https://shlink.io/documentation/', + 'validUntil' => Chronos::parse('2020-05-01'), // In the past + ])), '2018-05-01', ); $manager->persist($ghiShortUrl);