Added API tests covering the excludion of bot visits

This commit is contained in:
Alejandro Celaya
2021-05-22 21:05:54 +02:00
parent 69d72e754f
commit a12c9f54c4
5 changed files with 68 additions and 17 deletions

View File

@@ -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],
];
}
}