mirror of
https://github.com/shlinkio/shlink.git
synced 2025-01-22 14:33:16 -06:00
Created TagStatsActionTest
This commit is contained in:
parent
d5851bbb6a
commit
a6b1647f27
@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
|
|||||||
|
|
||||||
Additionally, the endpoint also supports filtering by `searchTerm` query param. When provided, only tags matching it will be returned.
|
Additionally, the endpoint also supports filtering by `searchTerm` query param. When provided, only tags matching it will be returned.
|
||||||
|
|
||||||
|
* [#1315](https://github.com/shlinkio/shlink/issues/1315) Included new `GET /tags/stats` endpoint, which effectively deprecates `GET /tags?withStats=true`.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* [#1277](https://github.com/shlinkio/shlink/issues/1277) Reduced docker image size to 45% of the original size.
|
* [#1277](https://github.com/shlinkio/shlink/issues/1277) Reduced docker image size to 45% of the original size.
|
||||||
* [#1268](https://github.com/shlinkio/shlink/issues/1268) Updated dependencies, including symfony/console 6 and mezzio/mezzio-swoole 4.
|
* [#1268](https://github.com/shlinkio/shlink/issues/1268) Updated dependencies, including symfony/console 6 and mezzio/mezzio-swoole 4.
|
||||||
|
@ -29,8 +29,7 @@ class ListTagsAction extends AbstractRestAction
|
|||||||
|
|
||||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||||
{
|
{
|
||||||
$query = $request->getQueryParams();
|
$params = TagsParams::fromRawData($request->getQueryParams());
|
||||||
$params = TagsParams::fromRawData($query);
|
|
||||||
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
|
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
|
||||||
|
|
||||||
if (! $params->withStats()) {
|
if (! $params->withStats()) {
|
||||||
|
@ -26,8 +26,7 @@ class TagsStatsAction extends AbstractRestAction
|
|||||||
|
|
||||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||||
{
|
{
|
||||||
$query = $request->getQueryParams();
|
$params = TagsParams::fromRawData($request->getQueryParams());
|
||||||
$params = TagsParams::fromRawData($query);
|
|
||||||
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
|
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
|
||||||
$tagsInfo = $this->tagService->tagsInfo($params, $apiKey);
|
$tagsInfo = $this->tagService->tagsInfo($params, $apiKey);
|
||||||
|
|
||||||
|
73
module/Rest/test/Action/Tag/TagsStatsActionTest.php
Normal file
73
module/Rest/test/Action/Tag/TagsStatsActionTest.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ShlinkioTest\Shlink\Rest\Action\Tag;
|
||||||
|
|
||||||
|
use Laminas\Diactoros\Response\JsonResponse;
|
||||||
|
use Laminas\Diactoros\ServerRequestFactory;
|
||||||
|
use Pagerfanta\Adapter\ArrayAdapter;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use Prophecy\Prophecy\ObjectProphecy;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||||
|
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||||
|
use Shlinkio\Shlink\Core\Tag\Model\TagInfo;
|
||||||
|
use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
|
||||||
|
use Shlinkio\Shlink\Rest\Action\Tag\TagsStatsAction;
|
||||||
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||||
|
|
||||||
|
use function count;
|
||||||
|
|
||||||
|
class TagsStatsActionTest extends TestCase
|
||||||
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
|
private TagsStatsAction $action;
|
||||||
|
private ObjectProphecy $tagService;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->tagService = $this->prophesize(TagServiceInterface::class);
|
||||||
|
$this->action = new TagsStatsAction($this->tagService->reveal());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function returnsTagsStatsWhenRequested(): void
|
||||||
|
{
|
||||||
|
$stats = [
|
||||||
|
new TagInfo(new Tag('foo'), 1, 1),
|
||||||
|
new TagInfo(new Tag('bar'), 3, 10),
|
||||||
|
];
|
||||||
|
$itemsCount = count($stats);
|
||||||
|
$tagsInfo = $this->tagService->tagsInfo(Argument::any(), Argument::type(ApiKey::class))->willReturn(
|
||||||
|
new Paginator(new ArrayAdapter($stats)),
|
||||||
|
);
|
||||||
|
$req = $this->requestWithApiKey()->withQueryParams(['withStats' => 'true']);
|
||||||
|
|
||||||
|
/** @var JsonResponse $resp */
|
||||||
|
$resp = $this->action->handle($req);
|
||||||
|
$payload = $resp->getPayload();
|
||||||
|
|
||||||
|
self::assertEquals([
|
||||||
|
'tags' => [
|
||||||
|
'data' => $stats,
|
||||||
|
'pagination' => [
|
||||||
|
'currentPage' => 1,
|
||||||
|
'pagesCount' => 1,
|
||||||
|
'itemsPerPage' => 10,
|
||||||
|
'itemsInCurrentPage' => $itemsCount,
|
||||||
|
'totalItems' => $itemsCount,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
], $payload);
|
||||||
|
$tagsInfo->shouldHaveBeenCalled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function requestWithApiKey(): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, ApiKey::create());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user