mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-23 13:23:33 +03:00
Add DeleteOrphanVisitsTest API test
This commit is contained in:
parent
a6f0c66331
commit
3916c68126
2 changed files with 44 additions and 2 deletions
42
module/Rest/test-api/Action/DeleteOrphanVisitsTest.php
Normal file
42
module/Rest/test-api/Action/DeleteOrphanVisitsTest.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
class DeleteOrphanVisitsTest extends ApiTestCase
|
||||
{
|
||||
#[Test]
|
||||
public function deletesVisitsForShortUrlWithoutAffectingTheRest(): void
|
||||
{
|
||||
self::assertEquals(7, $this->getTotalVisits());
|
||||
self::assertEquals(3, $this->getOrphanVisits());
|
||||
|
||||
$resp = $this->callApiWithKey(self::METHOD_DELETE, '/visits/orphan');
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
self::assertEquals(200, $resp->getStatusCode());
|
||||
self::assertEquals(3, $payload['deletedVisits']);
|
||||
self::assertEquals(7, $this->getTotalVisits()); // This verifies that regular visits have not been affected
|
||||
self::assertEquals(0, $this->getOrphanVisits());
|
||||
}
|
||||
|
||||
private function getTotalVisits(): int
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_GET, '/visits/non-orphan');
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
return $payload['visits']['pagination']['totalItems'];
|
||||
}
|
||||
|
||||
private function getOrphanVisits(): int
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_GET, '/visits/orphan');
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
return $payload['visits']['pagination']['totalItems'];
|
||||
}
|
||||
}
|
|
@ -22,8 +22,8 @@ class DeleteShortUrlVisitsTest extends ApiTestCase
|
|||
|
||||
self::assertEquals(200, $resp->getStatusCode());
|
||||
self::assertEquals(3, $payload['deletedVisits']);
|
||||
self::assertEquals(4, $this->getTotalVisits());
|
||||
self::assertEquals(3, $this->getOrphanVisits());
|
||||
self::assertEquals(4, $this->getTotalVisits()); // This verifies that other visits have not been affected
|
||||
self::assertEquals(3, $this->getOrphanVisits()); // This verifies that orphan visits have not been affected
|
||||
}
|
||||
|
||||
private function getTotalVisits(): int
|
||||
|
|
Loading…
Reference in a new issue