Fixed ordering in tags supporting more fields

This commit is contained in:
Alejandro Celaya
2023-01-02 19:49:54 +01:00
parent 961178fd82
commit ce9ec0d738
4 changed files with 45 additions and 23 deletions
@@ -10,6 +10,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
use Shlinkio\Shlink\Core\ShortUrl\Resolver\PersistenceShortUrlRelationResolver;
use Shlinkio\Shlink\Core\Tag\Entity\Tag;
use Shlinkio\Shlink\Core\Tag\Model\OrderableField;
use Shlinkio\Shlink\Core\Tag\Model\TagsListFiltering;
use Shlinkio\Shlink\Core\Tag\Repository\TagRepository;
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
@@ -135,17 +136,21 @@ class TagRepositoryTest extends DatabaseTestCase
['baz', 1, 3, 2],
]];
yield 'ASC ordering' => [
new TagsListFiltering(null, null, null, Ordering::fromTuple(['tag', 'ASC'])),
new TagsListFiltering(null, null, null, Ordering::fromTuple([OrderableField::TAG->value, 'ASC'])),
$defaultList,
];
yield 'DESC ordering' => [new TagsListFiltering(null, null, null, Ordering::fromTuple(['tag', 'DESC'])), [
yield 'DESC ordering' => [new TagsListFiltering(null, null, null, Ordering::fromTuple(
[OrderableField::TAG->value, 'DESC'],
)), [
['foo', 2, 4, 3],
['baz', 1, 3, 2],
['bar', 3, 3, 2],
['another', 0, 0, 0],
]];
yield 'short URLs count ASC ordering' => [
new TagsListFiltering(null, null, null, Ordering::fromTuple(['shortUrlsCount', 'ASC'])),
new TagsListFiltering(null, null, null, Ordering::fromTuple(
[OrderableField::SHORT_URLS_COUNT->value, 'ASC'],
)),
[
['another', 0, 0, 0],
['baz', 1, 3, 2],
@@ -154,7 +159,9 @@ class TagRepositoryTest extends DatabaseTestCase
],
];
yield 'short URLs count DESC ordering' => [
new TagsListFiltering(null, null, null, Ordering::fromTuple(['shortUrlsCount', 'DESC'])),
new TagsListFiltering(null, null, null, Ordering::fromTuple(
[OrderableField::SHORT_URLS_COUNT->value, 'DESC'],
)),
[
['bar', 3, 3, 2],
['foo', 2, 4, 3],
@@ -163,7 +170,18 @@ class TagRepositoryTest extends DatabaseTestCase
],
];
yield 'visits count ASC ordering' => [
new TagsListFiltering(null, null, null, Ordering::fromTuple(['visitsCount', 'ASC'])),
new TagsListFiltering(null, null, null, Ordering::fromTuple([OrderableField::VISITS->value, 'ASC'])),
[
['another', 0, 0, 0],
['bar', 3, 3, 2],
['baz', 1, 3, 2],
['foo', 2, 4, 3],
],
];
yield 'non-bot visits count ASC ordering' => [
new TagsListFiltering(null, null, null, Ordering::fromTuple(
[OrderableField::NON_BOT_VISITS->value, 'ASC'],
)),
[
['another', 0, 0, 0],
['bar', 3, 3, 2],
@@ -172,7 +190,7 @@ class TagRepositoryTest extends DatabaseTestCase
],
];
yield 'visits count DESC ordering' => [
new TagsListFiltering(null, null, null, Ordering::fromTuple(['visitsCount', 'DESC'])),
new TagsListFiltering(null, null, null, Ordering::fromTuple([OrderableField::VISITS->value, 'DESC'])),
[
['foo', 2, 4, 3],
['bar', 3, 3, 2],
@@ -181,7 +199,7 @@ class TagRepositoryTest extends DatabaseTestCase
],
];
yield 'visits count DESC ordering and limit' => [
new TagsListFiltering(2, null, null, Ordering::fromTuple(['visitsCount', 'DESC'])),
new TagsListFiltering(2, null, null, Ordering::fromTuple([OrderableField::VISITS_COUNT->value, 'DESC'])),
[
['foo', 2, 4, 3],
['bar', 3, 3, 2],
@@ -195,11 +213,11 @@ class TagRepositoryTest extends DatabaseTestCase
['foo', 1, 3, 2],
]];
yield 'combined' => [new TagsListFiltering(1, null, null, Ordering::fromTuple(
['shortUrls', 'DESC'],
[OrderableField::SHORT_URLS_COUNT->value, 'DESC'],
), ApiKey::fromMeta(
ApiKeyMeta::withRoles(RoleDefinition::forAuthoredShortUrls()),
)), [
['foo', 1, 3, 2],
['bar', 2, 3, 2],
]];
}