Added more tags to more fixture short URLs in API keys

This commit is contained in:
Alejandro Celaya 2021-01-10 09:54:19 +01:00
parent fa5934b8b6
commit 13cc70e6d4
5 changed files with 22 additions and 6 deletions

View File

@ -92,7 +92,7 @@ class ListShortUrlsTest extends ApiTestCase
. '/considerations-to-properly-use-open-source-software-projects/',
'dateCreated' => '2019-01-01T00:00:30+00:00',
'visitsCount' => 0,
'tags' => [],
'tags' => ['foo'],
'meta' => [
'validSince' => null,
'validUntil' => null,
@ -166,6 +166,7 @@ class ListShortUrlsTest extends ApiTestCase
yield [['tags' => ['foo']], [
self::SHORT_URL_SHLINK,
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_DOMAIN,
], 'valid_api_key'];
yield [['tags' => ['bar']], [
self::SHORT_URL_META,

View File

@ -41,7 +41,7 @@ class ListTagsActionTest extends ApiTestCase
],
[
'tag' => 'foo',
'shortUrlsCount' => 2,
'shortUrlsCount' => 3,
'visitsCount' => 5,
],
],

View File

@ -31,16 +31,26 @@ class TagVisitsActionTest extends ApiTestCase
yield 'baz' => ['baz', 0];
}
/** @test */
public function notFoundErrorIsReturnedForInvalidTags(): void
/**
* @test
* @dataProvider provideApiKeysAndTags
*/
public function notFoundErrorIsReturnedForInvalidTags(string $apiKey, string $tag): void
{
$resp = $this->callApiWithKey(self::METHOD_GET, '/tags/invalid_tag/visits');
$resp = $this->callApiWithKey(self::METHOD_GET, sprintf('/tags/%s/visits', $tag), [], $apiKey);
$payload = $this->getJsonResponsePayload($resp);
self::assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
self::assertEquals(self::STATUS_NOT_FOUND, $payload['status']);
self::assertEquals('TAG_NOT_FOUND', $payload['type']);
self::assertEquals('Tag with name "invalid_tag" could not be found', $payload['detail']);
self::assertEquals(sprintf('Tag with name "%s" could not be found', $tag), $payload['detail']);
self::assertEquals('Tag not found', $payload['title']);
}
public function provideApiKeysAndTags(): iterable
{
yield 'admin API key with invalid tag' => ['valid_api_key', 'invalid_tag'];
yield 'domain API key with valid tag not used' => ['domain_api_key', 'bar'];
yield 'author API key with valid tag not used' => ['author_api_key', 'baz'];
}
}

View File

@ -72,6 +72,7 @@ class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterf
$this->addReference('abc123_short_url', $abcShortUrl);
$this->addReference('def456_short_url', $defShortUrl);
$this->addReference('ghi789_short_url', $ghiShortUrl);
$this->addReference('example_short_url', $withDomainDuplicatingShortCode);
}
private function setShortUrlDate(ShortUrl $shortUrl, string $date): ShortUrl

View File

@ -34,6 +34,10 @@ class TagsFixture extends AbstractFixture implements DependentFixtureInterface
$defShortUrl = $this->getReference('def456_short_url');
$defShortUrl->setTags(new ArrayCollection([$fooTag, $barTag]));
/** @var ShortUrl $exampleShortUrl */
$exampleShortUrl = $this->getReference('example_short_url');
$exampleShortUrl->setTags(new ArrayCollection([$fooTag]));
$manager->flush();
}
}