Created rest test for list tags action

This commit is contained in:
Alejandro Celaya 2020-05-08 11:48:31 +02:00
parent 91aaffc6db
commit 00cac4ba72
4 changed files with 53 additions and 0 deletions

View File

@ -60,6 +60,7 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
->setJoinTable(determineTableName('short_urls_in_tags', $emConfig))
->addInverseJoinColumn('tag_id', 'id', true, false, 'CASCADE')
->addJoinColumn('short_url_id', 'id', true, false, 'CASCADE')
->setOrderBy(['name' => 'ASC'])
->build();
$builder->createManyToOne('domain', Entity\Domain::class)

View File

@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\Action;
use GuzzleHttp\RequestOptions;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
class ListTagsActionTest extends ApiTestCase
{
/**
* @test
* @dataProvider provideQueries
*/
public function expectedListOfTagsIsReturned(array $query, array $expectedTags): void
{
$resp = $this->callApiWithKey(self::METHOD_GET, '/tags', [RequestOptions::QUERY => $query]);
$payload = $this->getJsonResponsePayload($resp);
$this->assertEquals(['tags' => $expectedTags], $payload);
}
public function provideQueries(): iterable
{
yield 'stats not requested' => [[], [
'data' => ['bar', 'baz', 'foo'],
]];
yield 'stats requested' => [['withStats' => 'true'], [
'data' => ['bar', 'baz', 'foo'],
'stats' => [
[
'tag' => 'bar',
'shortUrlsCount' => 1,
'visitsCount' => 2,
],
[
'tag' => 'baz',
'shortUrlsCount' => 0,
'visitsCount' => 0,
],
[
'tag' => 'foo',
'shortUrlsCount' => 2,
'visitsCount' => 5,
],
],
]];
}
}

View File

@ -24,6 +24,7 @@ class TagsFixture extends AbstractFixture implements DependentFixtureInterface
$manager->persist($fooTag);
$barTag = new Tag('bar');
$manager->persist($barTag);
$manager->persist(new Tag('baz'));
/** @var ShortUrl $abcShortUrl */
$abcShortUrl = $this->getReference('abc123_short_url');

View File

@ -4,3 +4,4 @@ parameters:
ignoreErrors:
- '#AbstractQuery::setParameters()#'
- '#mustRun()#'
- '#AssociationBuilder::setOrderBy#'