mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-01-18 05:38:40 +01:00
More refactoring of the list controller and corresponding tests
This commit is contained in:
parent
6ddd82dfc2
commit
e6e9ee7228
@ -21,18 +21,6 @@ class ListUpdateRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(Request $request)
|
||||
{
|
||||
// Check if the list ID was provided
|
||||
if (!$request->get('list_id')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$list = LinkList::find($request->get('list_id'));
|
||||
|
||||
// Check if the list belongs to the user
|
||||
if ($list->user_id !== auth()->user()->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class LinkControllerTest extends TestCase
|
||||
->assertSee($link->url);
|
||||
}
|
||||
|
||||
public function testLinkCreateView(): void
|
||||
public function testCreateView(): void
|
||||
{
|
||||
$response = $this->get('links/create');
|
||||
|
||||
@ -89,7 +89,7 @@ class LinkControllerTest extends TestCase
|
||||
$this->assertEquals($tag->name, $databaseLink->tags->first()->name);
|
||||
}
|
||||
|
||||
public function testMinimalStoreRequestWithContinue(): void
|
||||
public function testStoreRequestWithContinue(): void
|
||||
{
|
||||
$response = $this->post('links', [
|
||||
'url' => 'https://example.com',
|
||||
@ -135,7 +135,7 @@ class LinkControllerTest extends TestCase
|
||||
->assertSee($link->url);
|
||||
}
|
||||
|
||||
public function testLinkEditView(): void
|
||||
public function testEditView(): void
|
||||
{
|
||||
factory(Link::class)->create();
|
||||
|
||||
@ -170,7 +170,7 @@ class LinkControllerTest extends TestCase
|
||||
$this->assertEquals('New Description', $updatedLink->description);
|
||||
}
|
||||
|
||||
public function testMissingLinkErrorForUpdate(): void
|
||||
public function testMissingMissingErrorForUpdate(): void
|
||||
{
|
||||
$response = $this->post('links/1', [
|
||||
'_method' => 'patch',
|
||||
@ -222,7 +222,7 @@ class LinkControllerTest extends TestCase
|
||||
$this->assertNotNull($databaseLink->deleted_at);
|
||||
}
|
||||
|
||||
public function testLinkMissingErrorForDelete(): void
|
||||
public function testMissingModelErrorForDelete(): void
|
||||
{
|
||||
$response = $this->post('links/1', [
|
||||
'_method' => 'delete',
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Tests\Feature\Controller\Models;
|
||||
|
||||
use App\Models\Link;
|
||||
use App\Models\LinkList;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
@ -25,7 +24,7 @@ class ListControllerTest extends TestCase
|
||||
$this->actingAs($this->user);
|
||||
}
|
||||
|
||||
public function testValidListOverviewResponse(): void
|
||||
public function testIndexView(): void
|
||||
{
|
||||
$list = factory(LinkList::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -37,7 +36,7 @@ class ListControllerTest extends TestCase
|
||||
->assertSee($list->name);
|
||||
}
|
||||
|
||||
public function testValidListCreateResponse(): void
|
||||
public function testCreateView(): void
|
||||
{
|
||||
$response = $this->get('lists/create');
|
||||
|
||||
@ -45,7 +44,7 @@ class ListControllerTest extends TestCase
|
||||
->assertSee('Add List');
|
||||
}
|
||||
|
||||
public function testValidListMinimalStoreResponse(): void
|
||||
public function testMinimalStoreRequest(): void
|
||||
{
|
||||
$response = $this->post('lists', [
|
||||
'name' => 'Test List',
|
||||
@ -60,7 +59,7 @@ class ListControllerTest extends TestCase
|
||||
$this->assertEquals('Test List', $databaseList->name);
|
||||
}
|
||||
|
||||
public function testValidListFullStoreResponse(): void
|
||||
public function testFullStoreRequest(): void
|
||||
{
|
||||
$response = $this->post('lists', [
|
||||
'name' => 'Test List',
|
||||
@ -77,7 +76,7 @@ class ListControllerTest extends TestCase
|
||||
$this->assertEquals('My custom description', $databaseList->description);
|
||||
}
|
||||
|
||||
public function testValidListStoreResponseWithContinue(): void
|
||||
public function testStoreRequestWithContinue(): void
|
||||
{
|
||||
$response = $this->post('lists', [
|
||||
'name' => 'Test List',
|
||||
@ -93,7 +92,7 @@ class ListControllerTest extends TestCase
|
||||
$this->assertEquals('Test List', $databaseList->name);
|
||||
}
|
||||
|
||||
public function testInvalidListStoreResponse(): void
|
||||
public function testInvalidStoreRequest(): void
|
||||
{
|
||||
$response = $this->post('lists', [
|
||||
'name' => null,
|
||||
@ -105,7 +104,7 @@ class ListControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testValidListDetailResponse(): void
|
||||
public function testDetailView(): void
|
||||
{
|
||||
$list = factory(LinkList::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -117,7 +116,7 @@ class ListControllerTest extends TestCase
|
||||
->assertSee($list->name);
|
||||
}
|
||||
|
||||
public function testValidListEditResponse(): void
|
||||
public function testEditView(): void
|
||||
{
|
||||
factory(LinkList::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -136,7 +135,7 @@ class ListControllerTest extends TestCase
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
public function testValidListUpdateResponse(): void
|
||||
public function testUpdateResponse(): void
|
||||
{
|
||||
$baseList = factory(LinkList::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -157,7 +156,19 @@ class ListControllerTest extends TestCase
|
||||
$this->assertEquals('New Test List', $updatedLink->name);
|
||||
}
|
||||
|
||||
public function testInvalidLinkUpdateResponse(): void
|
||||
public function testMissingModelErrorForUpdate(): void
|
||||
{
|
||||
$response = $this->post('lists/1', [
|
||||
'_method' => 'patch',
|
||||
'list_id' => '1',
|
||||
'name' => 'New Test List',
|
||||
'is_private' => '0',
|
||||
]);
|
||||
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
public function testValidationErrorForUpdate(): void
|
||||
{
|
||||
$baseList = factory(LinkList::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -175,7 +186,7 @@ class ListControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testValidListDeleteResponse(): void
|
||||
public function testDeleteResponse(): void
|
||||
{
|
||||
factory(LinkList::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
@ -194,7 +205,7 @@ class ListControllerTest extends TestCase
|
||||
$this->assertNotNull($databaseList->deleted_at);
|
||||
}
|
||||
|
||||
public function testInvalidListDeleteResponse(): void
|
||||
public function testMissingModelErrorForDelete(): void
|
||||
{
|
||||
$response = $this->post('lists/1', [
|
||||
'_method' => 'delete',
|
||||
|
Loading…
x
Reference in New Issue
Block a user