mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-03-20 06:39:38 +01:00
Adjust tests to cover more cases
This commit is contained in:
parent
17d1cdaf82
commit
e461d3c2c2
@ -5,26 +5,51 @@ namespace Tests\Controller\API;
|
||||
use App\Models\Link;
|
||||
use App\Models\LinkList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\Controller\Traits\PreparesTestData;
|
||||
|
||||
class ListLinksTest extends ApiTestCase
|
||||
{
|
||||
use PreparesTestData;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function testLinksRequest(): void
|
||||
{
|
||||
$link = Link::factory()->create();
|
||||
$list = LinkList::factory()->create();
|
||||
$this->createTestLists();
|
||||
[$link, $link2, $link3] = $this->createTestLinks();
|
||||
$link->lists()->sync([1, 2]);
|
||||
$link2->lists()->sync([1, 2]);
|
||||
$link3->lists()->sync([1, 2]);
|
||||
|
||||
$link->lists()->sync([$list->id]);
|
||||
|
||||
$response = $this->getJsonAuthorized('api/v1/lists/1/links');
|
||||
|
||||
$response->assertOk()
|
||||
$this->getJsonAuthorized('api/v1/lists/1/links')
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'data' => [
|
||||
['url' => $link->url],
|
||||
['url' => $link2->url],
|
||||
],
|
||||
])
|
||||
->assertJsonMissing([
|
||||
'data' => [
|
||||
['url' => $link3->url],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->getJsonAuthorized('api/v1/lists/2/links')
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'data' => [
|
||||
['url' => $link->url],
|
||||
['url' => $link2->url],
|
||||
],
|
||||
])
|
||||
->assertJsonMissing([
|
||||
'data' => [
|
||||
['url' => $link3->url],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->getJsonAuthorized('api/v1/lists/3/links')
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testLinksRequestWithoutLinks(): void
|
||||
@ -37,16 +62,10 @@ class ListLinksTest extends ApiTestCase
|
||||
->assertJson([
|
||||
'data' => [],
|
||||
]);
|
||||
|
||||
$responseBody = json_decode($response->content());
|
||||
|
||||
$this->assertEmpty($responseBody->data);
|
||||
}
|
||||
|
||||
public function testShowRequestNotFound(): void
|
||||
{
|
||||
$response = $this->getJsonAuthorized('api/v1/lists/1/links');
|
||||
|
||||
$response->assertNotFound();
|
||||
$this->getJsonAuthorized('api/v1/lists/1/links')->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class SearchControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private $user;
|
||||
private User $user;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
@ -27,23 +27,35 @@ class SearchControllerTest extends TestCase
|
||||
|
||||
public function testValidSearchResponse(): void
|
||||
{
|
||||
$response = $this->get('search');
|
||||
|
||||
$response->assertOk()
|
||||
$this->get('search')
|
||||
->assertOk()
|
||||
->assertSee('Search');
|
||||
}
|
||||
|
||||
public function testValidSearchResult(): void
|
||||
{
|
||||
$response = $this->post('search', [
|
||||
$this->post('search', [
|
||||
'query' => 'example',
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
])
|
||||
->assertOk()
|
||||
->assertSee('https://example.com')
|
||||
->assertDontSee('https://test.com');
|
||||
}
|
||||
|
||||
public function testValidSearchWithOrdering(): void
|
||||
{
|
||||
$response = $this->post('search', [
|
||||
'query' => 'example',
|
||||
'order_by' => 'title:asc',
|
||||
]);
|
||||
|
||||
$body = $response->content();
|
||||
$posLink1 = strpos($body, 'https://empty-test.com');
|
||||
$posLink2 = strpos($body, 'https://example.com');
|
||||
|
||||
$this->assertTrue($posLink1 < $posLink2);
|
||||
}
|
||||
|
||||
public function testValidUrlSearchResult(): void
|
||||
{
|
||||
$response = $this->post('search', [
|
||||
|
@ -242,9 +242,9 @@ class LinkControllerTest extends TestCase
|
||||
{
|
||||
$this->createTestLinks();
|
||||
|
||||
$this->get('links/1')->assertOk()->assertSee('https://public-link.com');
|
||||
$this->get('links/2')->assertOk()->assertSee('https://internal-link.com');
|
||||
$this->get('links/3')->assertForbidden();
|
||||
$this->get('links/1/edit')->assertOk()->assertSee('https://public-link.com');
|
||||
$this->get('links/2/edit')->assertOk()->assertSee('https://internal-link.com');
|
||||
$this->get('links/3/edit')->assertForbidden();
|
||||
}
|
||||
|
||||
public function testUpdateResponse(): void
|
||||
|
Loading…
x
Reference in New Issue
Block a user