Added API tests covering pagination for tags

This commit is contained in:
Alejandro Celaya 2022-01-05 19:16:49 +01:00
parent 775f58f972
commit 2f42b2d072

View file

@ -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,
],
]];
}
}