diff --git a/module/Rest/test-api/Action/ListTagsTest.php b/module/Rest/test-api/Action/ListTagsTest.php index de71182d..a1dade87 100644 --- a/module/Rest/test-api/Action/ListTagsTest.php +++ b/module/Rest/test-api/Action/ListTagsTest.php @@ -7,8 +7,6 @@ namespace ShlinkioApiTest\Shlink\Rest\Action; use GuzzleHttp\RequestOptions; use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase; -use function count; - class ListTagsTest extends ApiTestCase { /** @@ -19,14 +17,6 @@ class ListTagsTest extends ApiTestCase { $resp = $this->callApiWithKey(self::METHOD_GET, '/tags', [RequestOptions::QUERY => $query], $apiKey); $payload = $this->getJsonResponsePayload($resp); - $itemsCount = count($expectedTags['data']); - $expectedTags['pagination'] = [ - 'currentPage' => 1, - 'pagesCount' => 1, - 'itemsPerPage' => $itemsCount, - 'itemsInCurrentPage' => $itemsCount, - 'totalItems' => $itemsCount, - ]; self::assertEquals(['tags' => $expectedTags], $payload); } @@ -35,6 +25,23 @@ class ListTagsTest extends ApiTestCase { yield 'admin API key without stats' => ['valid_api_key', [], [ 'data' => ['bar', 'baz', 'foo'], + 'pagination' => [ + 'currentPage' => 1, + 'pagesCount' => 1, + 'itemsPerPage' => 3, + 'itemsInCurrentPage' => 3, + 'totalItems' => 3, + ], + ]]; + yield 'admin api key with pagination' => ['valid_api_key', ['page' => 2, 'itemsPerPage' => 2], [ + 'data' => ['foo'], + 'pagination' => [ + 'currentPage' => 2, + 'pagesCount' => 2, + 'itemsPerPage' => 2, + 'itemsInCurrentPage' => 1, + 'totalItems' => 3, + ], ]]; yield 'admin API key with stats' => ['valid_api_key', ['withStats' => 'true'], [ 'data' => ['bar', 'baz', 'foo'], @@ -55,10 +62,50 @@ class ListTagsTest extends ApiTestCase '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', [], [ 'data' => ['bar', 'foo'], + 'pagination' => [ + 'currentPage' => 1, + 'pagesCount' => 1, + 'itemsPerPage' => 2, + 'itemsInCurrentPage' => 2, + 'totalItems' => 2, + ], ]]; yield 'author API key with stats' => ['author_api_key', ['withStats' => 'true'], [ 'data' => ['bar', 'foo'], @@ -74,10 +121,24 @@ class ListTagsTest extends ApiTestCase 'visitsCount' => 5, ], ], + 'pagination' => [ + 'currentPage' => 1, + 'pagesCount' => 1, + 'itemsPerPage' => 2, + 'itemsInCurrentPage' => 2, + 'totalItems' => 2, + ], ]]; yield 'domain API key without stats' => ['domain_api_key', [], [ 'data' => ['foo'], + 'pagination' => [ + 'currentPage' => 1, + 'pagesCount' => 1, + 'itemsPerPage' => 1, + 'itemsInCurrentPage' => 1, + 'totalItems' => 1, + ], ]]; yield 'domain API key with stats' => ['domain_api_key', ['withStats' => 'true'], [ 'data' => ['foo'], @@ -88,6 +149,13 @@ class ListTagsTest extends ApiTestCase 'visitsCount' => 0, ], ], + 'pagination' => [ + 'currentPage' => 1, + 'pagesCount' => 1, + 'itemsPerPage' => 1, + 'itemsInCurrentPage' => 1, + 'totalItems' => 1, + ], ]]; } }