mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-27 07:53:00 +03:00
Added API test for the visits stats endpoint
This commit is contained in:
parent
30e34151ed
commit
8ecc241a4b
1 changed files with 68 additions and 0 deletions
68
module/Rest/test-api/Action/VisitStatsTest.php
Normal file
68
module/Rest/test-api/Action/VisitStatsTest.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
class VisitStatsTest extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideApiKeysAndResults
|
||||
*/
|
||||
public function expectedStatsAreReturned(string $apiKey, array $expectedPayload): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_GET, '/visits', apiKey: $apiKey);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
self::assertEquals(['visits' => $expectedPayload], $payload);
|
||||
}
|
||||
|
||||
public function provideApiKeysAndResults(): iterable
|
||||
{
|
||||
yield 'valid API key' => ['valid_api_key', [
|
||||
'nonOrphanVisits' => [
|
||||
'total' => 7,
|
||||
'nonBots' => 6,
|
||||
'bots' => 1,
|
||||
],
|
||||
'orphanVisits' => [
|
||||
'total' => 3,
|
||||
'nonBots' => 2,
|
||||
'bots' => 1,
|
||||
],
|
||||
'visitsCount' => 7,
|
||||
'orphanVisitsCount' => 3,
|
||||
]];
|
||||
yield 'domain-only API key' => ['domain_api_key', [
|
||||
'nonOrphanVisits' => [
|
||||
'total' => 0,
|
||||
'nonBots' => 0,
|
||||
'bots' => 0,
|
||||
],
|
||||
'orphanVisits' => [
|
||||
'total' => 3,
|
||||
'nonBots' => 2,
|
||||
'bots' => 1,
|
||||
],
|
||||
'visitsCount' => 0,
|
||||
'orphanVisitsCount' => 3,
|
||||
]];
|
||||
yield 'author API key' => ['author_api_key', [
|
||||
'nonOrphanVisits' => [
|
||||
'total' => 5,
|
||||
'nonBots' => 4,
|
||||
'bots' => 1,
|
||||
],
|
||||
'orphanVisits' => [
|
||||
'total' => 3,
|
||||
'nonBots' => 2,
|
||||
'bots' => 1,
|
||||
],
|
||||
'visitsCount' => 5,
|
||||
'orphanVisitsCount' => 3,
|
||||
]];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue