2020-05-01 11:40:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2020-05-01 11:40:02 +02:00
|
|
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
|
|
|
|
2021-01-24 09:25:36 +01:00
|
|
|
class GlobalVisitsTest extends ApiTestCase
|
2020-05-01 11:40:02 +02:00
|
|
|
{
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test, DataProvider('provideApiKeys')]
|
2023-05-31 09:22:40 +02:00
|
|
|
public function returnsExpectedVisitsStats(string $apiKey, int $expectedVisits, int $expectedOrphanVisits): void
|
2020-05-01 11:40:02 +02:00
|
|
|
{
|
2021-01-10 09:36:10 +01:00
|
|
|
$resp = $this->callApiWithKey(self::METHOD_GET, '/visits', [], $apiKey);
|
2020-05-01 11:40:02 +02:00
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
|
|
|
|
2020-10-04 00:35:14 +02:00
|
|
|
self::assertArrayHasKey('visits', $payload);
|
2024-02-12 20:29:40 +01:00
|
|
|
self::assertEquals($expectedVisits, $payload['visits']['nonOrphanVisits']['total']);
|
|
|
|
self::assertEquals($expectedOrphanVisits, $payload['visits']['orphanVisits']['total']);
|
2021-01-10 09:36:10 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 09:32:38 +01:00
|
|
|
public static function provideApiKeys(): iterable
|
2021-01-10 09:36:10 +01:00
|
|
|
{
|
2023-05-31 09:22:40 +02:00
|
|
|
yield 'admin API key' => ['valid_api_key', 7, 3];
|
|
|
|
yield 'domain API key' => ['domain_api_key', 0, 3];
|
|
|
|
yield 'author API key' => ['author_api_key', 5, 3];
|
|
|
|
yield 'no orphans API key' => ['no_orphans_api_key', 7, 0];
|
2020-05-01 11:40:02 +02:00
|
|
|
}
|
|
|
|
}
|