mirror of
https://github.com/shlinkio/shlink.git
synced 2025-01-22 14:33:16 -06:00
Reduced amount of duplicated code in API tests
This commit is contained in:
parent
acfc5a4676
commit
3b359cfc4f
@ -23,7 +23,7 @@ class ListTagsTest extends ApiTestCase
|
|||||||
|
|
||||||
public function provideQueries(): iterable
|
public function provideQueries(): iterable
|
||||||
{
|
{
|
||||||
yield 'admin API key without stats' => ['valid_api_key', [], [
|
yield 'admin API key' => ['valid_api_key', [], [
|
||||||
'data' => ['bar', 'baz', 'foo'],
|
'data' => ['bar', 'baz', 'foo'],
|
||||||
'pagination' => [
|
'pagination' => [
|
||||||
'currentPage' => 1,
|
'currentPage' => 1,
|
||||||
@ -43,61 +43,7 @@ class ListTagsTest extends ApiTestCase
|
|||||||
'totalItems' => 3,
|
'totalItems' => 3,
|
||||||
],
|
],
|
||||||
]];
|
]];
|
||||||
yield 'admin API key with stats' => ['valid_api_key', ['withStats' => 'true'], [
|
yield 'author API key' => ['author_api_key', [], [
|
||||||
'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', [], [
|
|
||||||
'data' => ['bar', 'foo'],
|
'data' => ['bar', 'foo'],
|
||||||
'pagination' => [
|
'pagination' => [
|
||||||
'currentPage' => 1,
|
'currentPage' => 1,
|
||||||
@ -107,30 +53,7 @@ class ListTagsTest extends ApiTestCase
|
|||||||
'totalItems' => 2,
|
'totalItems' => 2,
|
||||||
],
|
],
|
||||||
]];
|
]];
|
||||||
yield 'author API key with stats' => ['author_api_key', ['withStats' => 'true'], [
|
yield 'domain API key' => ['domain_api_key', [], [
|
||||||
'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', [], [
|
|
||||||
'data' => ['foo'],
|
'data' => ['foo'],
|
||||||
'pagination' => [
|
'pagination' => [
|
||||||
'currentPage' => 1,
|
'currentPage' => 1,
|
||||||
@ -140,22 +63,5 @@ class ListTagsTest extends ApiTestCase
|
|||||||
'totalItems' => 1,
|
'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,
|
|
||||||
],
|
|
||||||
]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,18 +13,41 @@ class TagsStatsTest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @dataProvider provideQueries
|
* @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);
|
$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
|
public function provideQueries(): iterable
|
||||||
{
|
{
|
||||||
yield 'admin API key' => ['valid_api_key', [], [
|
yield 'admin API key' => ['valid_api_key', [], [
|
||||||
'data' => [
|
|
||||||
[
|
[
|
||||||
'tag' => 'bar',
|
'tag' => 'bar',
|
||||||
'shortUrlsCount' => 1,
|
'shortUrlsCount' => 1,
|
||||||
@ -40,17 +63,14 @@ class TagsStatsTest extends ApiTestCase
|
|||||||
'shortUrlsCount' => 3,
|
'shortUrlsCount' => 3,
|
||||||
'visitsCount' => 5,
|
'visitsCount' => 5,
|
||||||
],
|
],
|
||||||
],
|
], [
|
||||||
'pagination' => [
|
|
||||||
'currentPage' => 1,
|
'currentPage' => 1,
|
||||||
'pagesCount' => 1,
|
'pagesCount' => 1,
|
||||||
'itemsPerPage' => 3,
|
'itemsPerPage' => 3,
|
||||||
'itemsInCurrentPage' => 3,
|
'itemsInCurrentPage' => 3,
|
||||||
'totalItems' => 3,
|
'totalItems' => 3,
|
||||||
],
|
|
||||||
]];
|
]];
|
||||||
yield 'admin API key with pagination' => ['valid_api_key', ['page' => 1, 'itemsPerPage' => 2], [
|
yield 'admin API key with pagination' => ['valid_api_key', ['page' => 1, 'itemsPerPage' => 2], [
|
||||||
'data' => [
|
|
||||||
[
|
[
|
||||||
'tag' => 'bar',
|
'tag' => 'bar',
|
||||||
'shortUrlsCount' => 1,
|
'shortUrlsCount' => 1,
|
||||||
@ -61,17 +81,14 @@ class TagsStatsTest extends ApiTestCase
|
|||||||
'shortUrlsCount' => 0,
|
'shortUrlsCount' => 0,
|
||||||
'visitsCount' => 0,
|
'visitsCount' => 0,
|
||||||
],
|
],
|
||||||
],
|
], [
|
||||||
'pagination' => [
|
|
||||||
'currentPage' => 1,
|
'currentPage' => 1,
|
||||||
'pagesCount' => 2,
|
'pagesCount' => 2,
|
||||||
'itemsPerPage' => 2,
|
'itemsPerPage' => 2,
|
||||||
'itemsInCurrentPage' => 2,
|
'itemsInCurrentPage' => 2,
|
||||||
'totalItems' => 3,
|
'totalItems' => 3,
|
||||||
],
|
|
||||||
]];
|
]];
|
||||||
yield 'author API key' => ['author_api_key', [], [
|
yield 'author API key' => ['author_api_key', [], [
|
||||||
'data' => [
|
|
||||||
[
|
[
|
||||||
'tag' => 'bar',
|
'tag' => 'bar',
|
||||||
'shortUrlsCount' => 1,
|
'shortUrlsCount' => 1,
|
||||||
@ -82,46 +99,38 @@ class TagsStatsTest extends ApiTestCase
|
|||||||
'shortUrlsCount' => 2,
|
'shortUrlsCount' => 2,
|
||||||
'visitsCount' => 5,
|
'visitsCount' => 5,
|
||||||
],
|
],
|
||||||
],
|
], [
|
||||||
'pagination' => [
|
|
||||||
'currentPage' => 1,
|
'currentPage' => 1,
|
||||||
'pagesCount' => 1,
|
'pagesCount' => 1,
|
||||||
'itemsPerPage' => 2,
|
'itemsPerPage' => 2,
|
||||||
'itemsInCurrentPage' => 2,
|
'itemsInCurrentPage' => 2,
|
||||||
'totalItems' => 2,
|
'totalItems' => 2,
|
||||||
],
|
|
||||||
]];
|
]];
|
||||||
yield 'author API key with pagination' => ['author_api_key', ['page' => 2, 'itemsPerPage' => 1], [
|
yield 'author API key with pagination' => ['author_api_key', ['page' => 2, 'itemsPerPage' => 1], [
|
||||||
'data' => [
|
|
||||||
[
|
[
|
||||||
'tag' => 'foo',
|
'tag' => 'foo',
|
||||||
'shortUrlsCount' => 2,
|
'shortUrlsCount' => 2,
|
||||||
'visitsCount' => 5,
|
'visitsCount' => 5,
|
||||||
],
|
],
|
||||||
],
|
], [
|
||||||
'pagination' => [
|
|
||||||
'currentPage' => 2,
|
'currentPage' => 2,
|
||||||
'pagesCount' => 2,
|
'pagesCount' => 2,
|
||||||
'itemsPerPage' => 1,
|
'itemsPerPage' => 1,
|
||||||
'itemsInCurrentPage' => 1,
|
'itemsInCurrentPage' => 1,
|
||||||
'totalItems' => 2,
|
'totalItems' => 2,
|
||||||
],
|
|
||||||
]];
|
]];
|
||||||
yield 'domain API key' => ['domain_api_key', [], [
|
yield 'domain API key' => ['domain_api_key', [], [
|
||||||
'data' => [
|
|
||||||
[
|
[
|
||||||
'tag' => 'foo',
|
'tag' => 'foo',
|
||||||
'shortUrlsCount' => 1,
|
'shortUrlsCount' => 1,
|
||||||
'visitsCount' => 0,
|
'visitsCount' => 0,
|
||||||
],
|
],
|
||||||
],
|
], [
|
||||||
'pagination' => [
|
|
||||||
'currentPage' => 1,
|
'currentPage' => 1,
|
||||||
'pagesCount' => 1,
|
'pagesCount' => 1,
|
||||||
'itemsPerPage' => 1,
|
'itemsPerPage' => 1,
|
||||||
'itemsInCurrentPage' => 1,
|
'itemsInCurrentPage' => 1,
|
||||||
'totalItems' => 1,
|
'totalItems' => 1,
|
||||||
],
|
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user