2022-01-16 14:24:02 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|
|
|
|
|
|
|
use Cake\Chronos\Chronos;
|
|
|
|
use GuzzleHttp\RequestOptions;
|
2023-02-09 22:42:18 +03:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2022-01-16 14:24:02 +03:00
|
|
|
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
|
|
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
|
|
|
|
|
|
|
class NonOrphanVisitsTest extends ApiTestCase
|
|
|
|
{
|
2023-02-09 22:42:18 +03:00
|
|
|
#[Test, DataProvider('provideQueries')]
|
2022-01-16 14:24:02 +03:00
|
|
|
public function properVisitsAreReturnedBasedInQuery(array $query, int $totalItems, int $returnedItems): void
|
|
|
|
{
|
|
|
|
$resp = $this->callApiWithKey(self::METHOD_GET, '/visits/non-orphan', [RequestOptions::QUERY => $query]);
|
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
|
|
|
|
|
|
|
self::assertEquals($totalItems, $payload['visits']['pagination']['totalItems'] ?? Paginator::ALL_ITEMS);
|
|
|
|
self::assertCount($returnedItems, $payload['visits']['data'] ?? []);
|
|
|
|
}
|
|
|
|
|
2023-02-09 11:32:38 +03:00
|
|
|
public static function provideQueries(): iterable
|
2022-01-16 14:24:02 +03:00
|
|
|
{
|
|
|
|
yield 'all data' => [[], 7, 7];
|
|
|
|
yield 'middle page' => [['page' => 2, 'itemsPerPage' => 3], 7, 3];
|
|
|
|
yield 'last page' => [['page' => 3, 'itemsPerPage' => 3], 7, 1];
|
|
|
|
yield 'bots excluded' => [['excludeBots' => 'true'], 6, 6];
|
|
|
|
yield 'bots excluded and pagination' => [['excludeBots' => 'true', 'page' => 1, 'itemsPerPage' => 4], 6, 4];
|
2023-08-19 12:48:04 +03:00
|
|
|
yield 'date filter' => [['startDate' => Chronos::now()->addDays(1)->toAtomString()], 0, 0];
|
2022-01-16 14:24:02 +03:00
|
|
|
}
|
|
|
|
}
|