From 2be0050f3d63486e24847e3e57098344ca967bfb Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 10 Jan 2021 10:17:27 +0100 Subject: [PATCH] Improved tag list api test to cover different API key cases --- .../test-api/Action/ListTagsActionTest.php | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/module/Rest/test-api/Action/ListTagsActionTest.php b/module/Rest/test-api/Action/ListTagsActionTest.php index 87b5b0c3..188e6bdf 100644 --- a/module/Rest/test-api/Action/ListTagsActionTest.php +++ b/module/Rest/test-api/Action/ListTagsActionTest.php @@ -13,9 +13,9 @@ class ListTagsActionTest extends ApiTestCase * @test * @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); self::assertEquals(['tags' => $expectedTags], $payload); @@ -23,10 +23,10 @@ class ListTagsActionTest extends ApiTestCase public function provideQueries(): iterable { - yield 'stats not requested' => [[], [ + yield 'admin API key without stats' => ['valid_api_key', [], [ 'data' => ['bar', 'baz', 'foo'], ]]; - yield 'stats requested' => [['withStats' => 'true'], [ + yield 'admin API key with stats' => ['valid_api_key', ['withStats' => 'true'], [ 'data' => ['bar', 'baz', 'foo'], '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, + ], + ], + ]]; } }