diff --git a/module/Rest/test-api/Action/ListTagsTest.php b/module/Rest/test-api/Action/ListTagsTest.php index a1dade87..4c627e7c 100644 --- a/module/Rest/test-api/Action/ListTagsTest.php +++ b/module/Rest/test-api/Action/ListTagsTest.php @@ -23,7 +23,7 @@ class ListTagsTest extends ApiTestCase public function provideQueries(): iterable { - yield 'admin API key without stats' => ['valid_api_key', [], [ + yield 'admin API key' => ['valid_api_key', [], [ 'data' => ['bar', 'baz', 'foo'], 'pagination' => [ 'currentPage' => 1, @@ -43,61 +43,7 @@ class ListTagsTest extends ApiTestCase 'totalItems' => 3, ], ]]; - yield 'admin API key with stats' => ['valid_api_key', ['withStats' => 'true'], [ - 'data' => ['bar', 'baz', 'foo'], - 'stats' => [ - [ - 'tag' => 'bar', - 'shortUrlsCount' => 1, - 'visitsCount' => 2, - ], - [ - 'tag' => 'baz', - 'shortUrlsCount' => 0, - 'visitsCount' => 0, - ], - [ - 'tag' => 'foo', - 'shortUrlsCount' => 3, - 'visitsCount' => 5, - ], - ], - 'pagination' => [ - 'currentPage' => 1, - 'pagesCount' => 1, - 'itemsPerPage' => 3, - 'itemsInCurrentPage' => 3, - 'totalItems' => 3, - ], - ]]; - yield 'admin API key with pagination and stats' => ['valid_api_key', [ - 'withStats' => 'true', - 'page' => 1, - 'itemsPerPage' => 2, - ], [ - 'data' => ['bar', 'baz'], - 'stats' => [ - [ - 'tag' => 'bar', - 'shortUrlsCount' => 1, - 'visitsCount' => 2, - ], - [ - 'tag' => 'baz', - 'shortUrlsCount' => 0, - 'visitsCount' => 0, - ], - ], - 'pagination' => [ - 'currentPage' => 1, - 'pagesCount' => 2, - 'itemsPerPage' => 2, - 'itemsInCurrentPage' => 2, - 'totalItems' => 3, - ], - ]]; - - yield 'author API key without stats' => ['author_api_key', [], [ + yield 'author API key' => ['author_api_key', [], [ 'data' => ['bar', 'foo'], 'pagination' => [ 'currentPage' => 1, @@ -107,30 +53,7 @@ class ListTagsTest extends ApiTestCase 'totalItems' => 2, ], ]]; - 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, - ], - ], - 'pagination' => [ - 'currentPage' => 1, - 'pagesCount' => 1, - 'itemsPerPage' => 2, - 'itemsInCurrentPage' => 2, - 'totalItems' => 2, - ], - ]]; - - yield 'domain API key without stats' => ['domain_api_key', [], [ + yield 'domain API key' => ['domain_api_key', [], [ 'data' => ['foo'], 'pagination' => [ 'currentPage' => 1, @@ -140,22 +63,5 @@ class ListTagsTest extends ApiTestCase 'totalItems' => 1, ], ]]; - yield 'domain API key with stats' => ['domain_api_key', ['withStats' => 'true'], [ - 'data' => ['foo'], - 'stats' => [ - [ - 'tag' => 'foo', - 'shortUrlsCount' => 1, - 'visitsCount' => 0, - ], - ], - 'pagination' => [ - 'currentPage' => 1, - 'pagesCount' => 1, - 'itemsPerPage' => 1, - 'itemsInCurrentPage' => 1, - 'totalItems' => 1, - ], - ]]; } } diff --git a/module/Rest/test-api/Action/TagsStatsTest.php b/module/Rest/test-api/Action/TagsStatsTest.php index a97a5974..3b91cbf0 100644 --- a/module/Rest/test-api/Action/TagsStatsTest.php +++ b/module/Rest/test-api/Action/TagsStatsTest.php @@ -13,115 +13,124 @@ class TagsStatsTest extends ApiTestCase * @test * @dataProvider provideQueries */ - public function expectedListOfTagsIsReturned(string $apiKey, array $query, array $expectedTags): void - { + public function expectedListOfTagsIsReturned( + string $apiKey, + array $query, + array $expectedStats, + array $expectedPagination, + ): void { $resp = $this->callApiWithKey(self::METHOD_GET, '/tags/stats', [RequestOptions::QUERY => $query], $apiKey); - $payload = $this->getJsonResponsePayload($resp); + ['tags' => $tags] = $this->getJsonResponsePayload($resp); - self::assertEquals(['tags' => $expectedTags], $payload); + self::assertEquals($expectedStats, $tags['data']); + self::assertEquals($expectedPagination, $tags['pagination']); + } + + /** + * @test + * @dataProvider provideQueries + */ + public function expectedListOfTagsIsReturnedForDeprecatedApproach( + string $apiKey, + array $query, + array $expectedStats, + array $expectedPagination, + ): void { + $query['withStats'] = 'true'; + $resp = $this->callApiWithKey(self::METHOD_GET, '/tags', [RequestOptions::QUERY => $query], $apiKey); + ['tags' => $tags] = $this->getJsonResponsePayload($resp); + + self::assertEquals($expectedStats, $tags['stats']); + self::assertEquals($expectedPagination, $tags['pagination']); + self::assertArrayHasKey('data', $tags); } public function provideQueries(): iterable { yield 'admin API key' => ['valid_api_key', [], [ - 'data' => [ - [ - 'tag' => 'bar', - 'shortUrlsCount' => 1, - 'visitsCount' => 2, - ], - [ - 'tag' => 'baz', - 'shortUrlsCount' => 0, - 'visitsCount' => 0, - ], - [ - 'tag' => 'foo', - 'shortUrlsCount' => 3, - 'visitsCount' => 5, - ], + [ + 'tag' => 'bar', + 'shortUrlsCount' => 1, + 'visitsCount' => 2, ], - 'pagination' => [ - 'currentPage' => 1, - 'pagesCount' => 1, - 'itemsPerPage' => 3, - 'itemsInCurrentPage' => 3, - 'totalItems' => 3, + [ + 'tag' => 'baz', + 'shortUrlsCount' => 0, + 'visitsCount' => 0, ], + [ + 'tag' => 'foo', + 'shortUrlsCount' => 3, + 'visitsCount' => 5, + ], + ], [ + 'currentPage' => 1, + 'pagesCount' => 1, + 'itemsPerPage' => 3, + 'itemsInCurrentPage' => 3, + 'totalItems' => 3, ]]; yield 'admin API key with pagination' => ['valid_api_key', ['page' => 1, 'itemsPerPage' => 2], [ - 'data' => [ - [ - 'tag' => 'bar', - 'shortUrlsCount' => 1, - 'visitsCount' => 2, - ], - [ - 'tag' => 'baz', - 'shortUrlsCount' => 0, - 'visitsCount' => 0, - ], + [ + 'tag' => 'bar', + 'shortUrlsCount' => 1, + 'visitsCount' => 2, ], - 'pagination' => [ - 'currentPage' => 1, - 'pagesCount' => 2, - 'itemsPerPage' => 2, - 'itemsInCurrentPage' => 2, - 'totalItems' => 3, + [ + 'tag' => 'baz', + 'shortUrlsCount' => 0, + 'visitsCount' => 0, ], + ], [ + 'currentPage' => 1, + 'pagesCount' => 2, + 'itemsPerPage' => 2, + 'itemsInCurrentPage' => 2, + 'totalItems' => 3, ]]; yield 'author API key' => ['author_api_key', [], [ - 'data' => [ - [ - 'tag' => 'bar', - 'shortUrlsCount' => 1, - 'visitsCount' => 2, - ], - [ - 'tag' => 'foo', - 'shortUrlsCount' => 2, - 'visitsCount' => 5, - ], + [ + 'tag' => 'bar', + 'shortUrlsCount' => 1, + 'visitsCount' => 2, ], - 'pagination' => [ - 'currentPage' => 1, - 'pagesCount' => 1, - 'itemsPerPage' => 2, - 'itemsInCurrentPage' => 2, - 'totalItems' => 2, + [ + 'tag' => 'foo', + 'shortUrlsCount' => 2, + 'visitsCount' => 5, ], + ], [ + 'currentPage' => 1, + 'pagesCount' => 1, + 'itemsPerPage' => 2, + 'itemsInCurrentPage' => 2, + 'totalItems' => 2, ]]; yield 'author API key with pagination' => ['author_api_key', ['page' => 2, 'itemsPerPage' => 1], [ - 'data' => [ - [ - 'tag' => 'foo', - 'shortUrlsCount' => 2, - 'visitsCount' => 5, - ], - ], - 'pagination' => [ - 'currentPage' => 2, - 'pagesCount' => 2, - 'itemsPerPage' => 1, - 'itemsInCurrentPage' => 1, - 'totalItems' => 2, + [ + 'tag' => 'foo', + 'shortUrlsCount' => 2, + 'visitsCount' => 5, ], + ], [ + 'currentPage' => 2, + 'pagesCount' => 2, + 'itemsPerPage' => 1, + 'itemsInCurrentPage' => 1, + 'totalItems' => 2, ]]; yield 'domain API key' => ['domain_api_key', [], [ - 'data' => [ - [ - 'tag' => 'foo', - 'shortUrlsCount' => 1, - 'visitsCount' => 0, - ], - ], - 'pagination' => [ - 'currentPage' => 1, - 'pagesCount' => 1, - 'itemsPerPage' => 1, - 'itemsInCurrentPage' => 1, - 'totalItems' => 1, + [ + 'tag' => 'foo', + 'shortUrlsCount' => 1, + 'visitsCount' => 0, ], + ], [ + 'currentPage' => 1, + 'pagesCount' => 1, + 'itemsPerPage' => 1, + 'itemsInCurrentPage' => 1, + 'totalItems' => 1, ]]; } }