shlink/module/Rest/test-api/Action/GlobalVisitsTest.php

32 lines
1.1 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\Action;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
2021-01-24 02:25:36 -06:00
class GlobalVisitsTest extends ApiTestCase
{
#[Test, DataProvider('provideApiKeys')]
public function returnsExpectedVisitsStats(string $apiKey, int $expectedVisits, int $expectedOrphanVisits): void
{
$resp = $this->callApiWithKey(self::METHOD_GET, '/visits', [], $apiKey);
$payload = $this->getJsonResponsePayload($resp);
2020-10-03 17:35:14 -05:00
self::assertArrayHasKey('visits', $payload);
2024-02-12 13:29:40 -06:00
self::assertEquals($expectedVisits, $payload['visits']['nonOrphanVisits']['total']);
self::assertEquals($expectedOrphanVisits, $payload['visits']['orphanVisits']['total']);
}
2023-02-09 02:32:38 -06:00
public static function provideApiKeys(): iterable
{
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];
}
}