mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 09:43:13 +08:00
Added API tests covering the excludion of bot visits
This commit is contained in:
@@ -41,21 +41,32 @@ class OrphanVisitsTest extends ApiTestCase
|
||||
* @test
|
||||
* @dataProvider provideQueries
|
||||
*/
|
||||
public function properVisitsAreReturnedBasedInQuery(array $query, int $expectedAmount, array $expectedVisits): void
|
||||
{
|
||||
public function properVisitsAreReturnedBasedInQuery(
|
||||
array $query,
|
||||
int $totalItems,
|
||||
int $expectedAmount,
|
||||
array $expectedVisits
|
||||
): void {
|
||||
$resp = $this->callApiWithKey(self::METHOD_GET, '/visits/orphan', [RequestOptions::QUERY => $query]);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
$visits = $payload['visits']['data'] ?? [];
|
||||
|
||||
self::assertEquals(3, $payload['visits']['pagination']['totalItems'] ?? -1);
|
||||
self::assertEquals($totalItems, $payload['visits']['pagination']['totalItems'] ?? -1);
|
||||
self::assertCount($expectedAmount, $visits);
|
||||
self::assertEquals($expectedVisits, $visits);
|
||||
}
|
||||
|
||||
public function provideQueries(): iterable
|
||||
{
|
||||
yield 'all data' => [[], 3, [self::INVALID_SHORT_URL, self::REGULAR_NOT_FOUND, self::BASE_URL]];
|
||||
yield 'limit items' => [['itemsPerPage' => 2], 2, [self::INVALID_SHORT_URL, self::REGULAR_NOT_FOUND]];
|
||||
yield 'limit items and page' => [['itemsPerPage' => 2, 'page' => 2], 1, [self::BASE_URL]];
|
||||
yield 'all data' => [[], 3, 3, [self::INVALID_SHORT_URL, self::REGULAR_NOT_FOUND, self::BASE_URL]];
|
||||
yield 'limit items' => [['itemsPerPage' => 2], 3, 2, [self::INVALID_SHORT_URL, self::REGULAR_NOT_FOUND]];
|
||||
yield 'limit items and page' => [['itemsPerPage' => 2, 'page' => 2], 3, 1, [self::BASE_URL]];
|
||||
yield 'exclude bots' => [['excludeBots' => true], 2, 2, [self::REGULAR_NOT_FOUND, self::BASE_URL]];
|
||||
yield 'exclude bots and limit items' => [
|
||||
['excludeBots' => true, 'itemsPerPage' => 1],
|
||||
2,
|
||||
1,
|
||||
[self::REGULAR_NOT_FOUND],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user