mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-25 18:30:23 -06:00
Created API test for tags visits endpoint
This commit is contained in:
parent
7f39e6d768
commit
4d346d1fea
46
module/Rest/test-api/Action/TagVisitsActionTest.php
Normal file
46
module/Rest/test-api/Action/TagVisitsActionTest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
||||
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class TagVisitsActionTest extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideTags
|
||||
*/
|
||||
public function expectedVisitsAreReturned(string $tag, int $expectedVisitsAmount): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_GET, sprintf('/tags/%s/visits', $tag));
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
$this->assertArrayHasKey('visits', $payload);
|
||||
$this->assertArrayHasKey('data', $payload['visits']);
|
||||
$this->assertCount($expectedVisitsAmount, $payload['visits']['data']);
|
||||
}
|
||||
|
||||
public function provideTags(): iterable
|
||||
{
|
||||
yield 'foo' => ['foo', 5];
|
||||
yield 'bar' => ['bar', 2];
|
||||
yield 'baz' => ['baz', 0];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function notFoundErrorIsReturnedForInvalidTags(): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_GET, '/tags/invalid_tag/visits');
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
$this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
|
||||
$this->assertEquals(self::STATUS_NOT_FOUND, $payload['status']);
|
||||
$this->assertEquals('TAG_NOT_FOUND', $payload['type']);
|
||||
$this->assertEquals('Tag with name "invalid_tag" could not be found', $payload['detail']);
|
||||
$this->assertEquals('Tag not found', $payload['title']);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user