mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-24 05:38:06 +03:00
Added API test for visits with and without domain
This commit is contained in:
parent
881002634a
commit
e58f2a384e
5 changed files with 39 additions and 3 deletions
|
@ -128,10 +128,10 @@ class EditShortUrlActionTest extends ApiTestCase
|
|||
|
||||
public function provideDomains(): iterable
|
||||
{
|
||||
yield 'domain' => [null, 'https://shlink.io/documentation/'];
|
||||
yield 'no domain' => [
|
||||
yield 'domain' => [
|
||||
'example.com',
|
||||
'https://blog.alejandrocelaya.com/2019/04/27/considerations-to-properly-use-open-source-software-projects/',
|
||||
];
|
||||
yield 'no domain' => [null, 'https://shlink.io/documentation/'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use Laminas\Diactoros\Uri;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
use function GuzzleHttp\Psr7\build_query;
|
||||
use function sprintf;
|
||||
|
||||
class GetVisitsActionTest extends ApiTestCase
|
||||
{
|
||||
/** @test */
|
||||
|
@ -23,4 +27,30 @@ class GetVisitsActionTest extends ApiTestCase
|
|||
$this->assertEquals('Short URL not found', $payload['title']);
|
||||
$this->assertEquals('invalid', $payload['shortCode']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideDomains
|
||||
*/
|
||||
public function properVisitsAreReturnedWhenDomainIsProvided(?string $domain, int $expectedAmountOfVisits): void
|
||||
{
|
||||
$shortCode = 'ghi789';
|
||||
$url = new Uri(sprintf('/short-urls/%s/visits', $shortCode));
|
||||
|
||||
if ($domain !== null) {
|
||||
$url = $url->withQuery(build_query(['domain' => $domain]));
|
||||
}
|
||||
|
||||
$resp = $this->callApiWithKey(self::METHOD_GET, (string) $url);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
$this->assertEquals($expectedAmountOfVisits, $payload['visits']['pagination']['totalItems'] ?? -1);
|
||||
$this->assertCount($expectedAmountOfVisits, $payload['visits']['data'] ?? []);
|
||||
}
|
||||
|
||||
public function provideDomains(): iterable
|
||||
{
|
||||
yield 'domain' => ['example.com', 0];
|
||||
yield 'no domain' => [null, 2];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class ListShortUrlsTest extends ApiTestCase
|
|||
'shortUrl' => 'http://doma.in/ghi789',
|
||||
'longUrl' => 'https://shlink.io/documentation/',
|
||||
'dateCreated' => '2018-05-01T00:00:00+00:00',
|
||||
'visitsCount' => 0,
|
||||
'visitsCount' => 2,
|
||||
'tags' => [],
|
||||
'meta' => [
|
||||
'validSince' => null,
|
||||
|
|
|
@ -59,6 +59,7 @@ class ShortUrlsFixture extends AbstractFixture
|
|||
|
||||
$this->addReference('abc123_short_url', $abcShortUrl);
|
||||
$this->addReference('def456_short_url', $defShortUrl);
|
||||
$this->addReference('ghi789_short_url', $ghiShortUrl);
|
||||
}
|
||||
|
||||
private function setShortUrlDate(ShortUrl $shortUrl, string $date): ShortUrl
|
||||
|
|
|
@ -31,6 +31,11 @@ class VisitsFixture extends AbstractFixture implements DependentFixtureInterface
|
|||
$manager->persist(new Visit($defShortUrl, new Visitor('shlink-tests-agent', '', '127.0.0.1')));
|
||||
$manager->persist(new Visit($defShortUrl, new Visitor('shlink-tests-agent', 'https://app.shlink.io', '')));
|
||||
|
||||
/** @var ShortUrl $defShortUrl */
|
||||
$defShortUrl = $this->getReference('ghi789_short_url');
|
||||
$manager->persist(new Visit($defShortUrl, new Visitor('shlink-tests-agent', '', '1.2.3.4')));
|
||||
$manager->persist(new Visit($defShortUrl, new Visitor('shlink-tests-agent', 'https://app.shlink.io', '')));
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue