Improved tag list api test to cover different API key cases

This commit is contained in:
Alejandro Celaya 2021-01-10 10:17:27 +01:00
parent ff1af82ffd
commit 2be0050f3d

View file

@ -13,9 +13,9 @@ class ListTagsActionTest extends ApiTestCase
* @test * @test
* @dataProvider provideQueries * @dataProvider provideQueries
*/ */
public function expectedListOfTagsIsReturned(array $query, array $expectedTags): void public function expectedListOfTagsIsReturned(string $apiKey, array $query, array $expectedTags): void
{ {
$resp = $this->callApiWithKey(self::METHOD_GET, '/tags', [RequestOptions::QUERY => $query]); $resp = $this->callApiWithKey(self::METHOD_GET, '/tags', [RequestOptions::QUERY => $query], $apiKey);
$payload = $this->getJsonResponsePayload($resp); $payload = $this->getJsonResponsePayload($resp);
self::assertEquals(['tags' => $expectedTags], $payload); self::assertEquals(['tags' => $expectedTags], $payload);
@ -23,10 +23,10 @@ class ListTagsActionTest extends ApiTestCase
public function provideQueries(): iterable public function provideQueries(): iterable
{ {
yield 'stats not requested' => [[], [ yield 'admin API key without stats' => ['valid_api_key', [], [
'data' => ['bar', 'baz', 'foo'], 'data' => ['bar', 'baz', 'foo'],
]]; ]];
yield 'stats requested' => [['withStats' => 'true'], [ yield 'admin API key with stats' => ['valid_api_key', ['withStats' => 'true'], [
'data' => ['bar', 'baz', 'foo'], 'data' => ['bar', 'baz', 'foo'],
'stats' => [ 'stats' => [
[ [
@ -46,5 +46,38 @@ class ListTagsActionTest extends ApiTestCase
], ],
], ],
]]; ]];
yield 'author API key without stats' => ['author_api_key', [], [
'data' => ['bar', 'foo'],
]];
yield 'author API key with stats' => ['author_api_key', ['withStats' => 'true'], [
'data' => ['bar', 'foo'],
'stats' => [
[
'tag' => 'bar',
'shortUrlsCount' => 1,
'visitsCount' => 2,
],
[
'tag' => 'foo',
'shortUrlsCount' => 2,
'visitsCount' => 5,
],
],
]];
yield 'domain API key without stats' => ['domain_api_key', [], [
'data' => ['foo'],
]];
yield 'domain API key with stats' => ['domain_api_key', ['withStats' => 'true'], [
'data' => ['foo'],
'stats' => [
[
'tag' => 'foo',
'shortUrlsCount' => 1,
'visitsCount' => 0,
],
],
]];
} }
} }