mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-26 04:09:02 +03:00
Added API tests covering pagination for tags
This commit is contained in:
parent
775f58f972
commit
2f42b2d072
1 changed files with 78 additions and 10 deletions
|
@ -7,8 +7,6 @@ namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||||
use GuzzleHttp\RequestOptions;
|
use GuzzleHttp\RequestOptions;
|
||||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||||
|
|
||||||
use function count;
|
|
||||||
|
|
||||||
class ListTagsTest extends ApiTestCase
|
class ListTagsTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -19,14 +17,6 @@ class ListTagsTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
$resp = $this->callApiWithKey(self::METHOD_GET, '/tags', [RequestOptions::QUERY => $query], $apiKey);
|
$resp = $this->callApiWithKey(self::METHOD_GET, '/tags', [RequestOptions::QUERY => $query], $apiKey);
|
||||||
$payload = $this->getJsonResponsePayload($resp);
|
$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);
|
self::assertEquals(['tags' => $expectedTags], $payload);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +25,23 @@ class ListTagsTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
yield 'admin API key without stats' => ['valid_api_key', [], [
|
yield 'admin API key without stats' => ['valid_api_key', [], [
|
||||||
'data' => ['bar', 'baz', 'foo'],
|
'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'], [
|
yield 'admin API key with stats' => ['valid_api_key', ['withStats' => 'true'], [
|
||||||
'data' => ['bar', 'baz', 'foo'],
|
'data' => ['bar', 'baz', 'foo'],
|
||||||
|
@ -55,10 +62,50 @@ class ListTagsTest extends ApiTestCase
|
||||||
'visitsCount' => 5,
|
'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 without stats' => ['author_api_key', [], [
|
||||||
'data' => ['bar', 'foo'],
|
'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'], [
|
yield 'author API key with stats' => ['author_api_key', ['withStats' => 'true'], [
|
||||||
'data' => ['bar', 'foo'],
|
'data' => ['bar', 'foo'],
|
||||||
|
@ -74,10 +121,24 @@ class ListTagsTest extends ApiTestCase
|
||||||
'visitsCount' => 5,
|
'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 without stats' => ['domain_api_key', [], [
|
||||||
'data' => ['foo'],
|
'data' => ['foo'],
|
||||||
|
'pagination' => [
|
||||||
|
'currentPage' => 1,
|
||||||
|
'pagesCount' => 1,
|
||||||
|
'itemsPerPage' => 1,
|
||||||
|
'itemsInCurrentPage' => 1,
|
||||||
|
'totalItems' => 1,
|
||||||
|
],
|
||||||
]];
|
]];
|
||||||
yield 'domain API key with stats' => ['domain_api_key', ['withStats' => 'true'], [
|
yield 'domain API key with stats' => ['domain_api_key', ['withStats' => 'true'], [
|
||||||
'data' => ['foo'],
|
'data' => ['foo'],
|
||||||
|
@ -88,6 +149,13 @@ class ListTagsTest extends ApiTestCase
|
||||||
'visitsCount' => 0,
|
'visitsCount' => 0,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'pagination' => [
|
||||||
|
'currentPage' => 1,
|
||||||
|
'pagesCount' => 1,
|
||||||
|
'itemsPerPage' => 1,
|
||||||
|
'itemsInCurrentPage' => 1,
|
||||||
|
'totalItems' => 1,
|
||||||
|
],
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue