1
0
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:
Kovah 2020-02-12 17:20:41 +01:00
parent 6ddd82dfc2
commit e6e9ee7228
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B
3 changed files with 29 additions and 30 deletions

View File

@ -21,18 +21,6 @@ class ListUpdateRequest extends FormRequest
*/ */
public function authorize(Request $request) 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; return true;
} }

View File

@ -36,7 +36,7 @@ class LinkControllerTest extends TestCase
->assertSee($link->url); ->assertSee($link->url);
} }
public function testLinkCreateView(): void public function testCreateView(): void
{ {
$response = $this->get('links/create'); $response = $this->get('links/create');
@ -89,7 +89,7 @@ class LinkControllerTest extends TestCase
$this->assertEquals($tag->name, $databaseLink->tags->first()->name); $this->assertEquals($tag->name, $databaseLink->tags->first()->name);
} }
public function testMinimalStoreRequestWithContinue(): void public function testStoreRequestWithContinue(): void
{ {
$response = $this->post('links', [ $response = $this->post('links', [
'url' => 'https://example.com', 'url' => 'https://example.com',
@ -135,7 +135,7 @@ class LinkControllerTest extends TestCase
->assertSee($link->url); ->assertSee($link->url);
} }
public function testLinkEditView(): void public function testEditView(): void
{ {
factory(Link::class)->create(); factory(Link::class)->create();
@ -170,7 +170,7 @@ class LinkControllerTest extends TestCase
$this->assertEquals('New Description', $updatedLink->description); $this->assertEquals('New Description', $updatedLink->description);
} }
public function testMissingLinkErrorForUpdate(): void public function testMissingMissingErrorForUpdate(): void
{ {
$response = $this->post('links/1', [ $response = $this->post('links/1', [
'_method' => 'patch', '_method' => 'patch',
@ -222,7 +222,7 @@ class LinkControllerTest extends TestCase
$this->assertNotNull($databaseLink->deleted_at); $this->assertNotNull($databaseLink->deleted_at);
} }
public function testLinkMissingErrorForDelete(): void public function testMissingModelErrorForDelete(): void
{ {
$response = $this->post('links/1', [ $response = $this->post('links/1', [
'_method' => 'delete', '_method' => 'delete',

View File

@ -2,7 +2,6 @@
namespace Tests\Feature\Controller\Models; namespace Tests\Feature\Controller\Models;
use App\Models\Link;
use App\Models\LinkList; use App\Models\LinkList;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
@ -25,7 +24,7 @@ class ListControllerTest extends TestCase
$this->actingAs($this->user); $this->actingAs($this->user);
} }
public function testValidListOverviewResponse(): void public function testIndexView(): void
{ {
$list = factory(LinkList::class)->create([ $list = factory(LinkList::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
@ -37,7 +36,7 @@ class ListControllerTest extends TestCase
->assertSee($list->name); ->assertSee($list->name);
} }
public function testValidListCreateResponse(): void public function testCreateView(): void
{ {
$response = $this->get('lists/create'); $response = $this->get('lists/create');
@ -45,7 +44,7 @@ class ListControllerTest extends TestCase
->assertSee('Add List'); ->assertSee('Add List');
} }
public function testValidListMinimalStoreResponse(): void public function testMinimalStoreRequest(): void
{ {
$response = $this->post('lists', [ $response = $this->post('lists', [
'name' => 'Test List', 'name' => 'Test List',
@ -60,7 +59,7 @@ class ListControllerTest extends TestCase
$this->assertEquals('Test List', $databaseList->name); $this->assertEquals('Test List', $databaseList->name);
} }
public function testValidListFullStoreResponse(): void public function testFullStoreRequest(): void
{ {
$response = $this->post('lists', [ $response = $this->post('lists', [
'name' => 'Test List', 'name' => 'Test List',
@ -77,7 +76,7 @@ class ListControllerTest extends TestCase
$this->assertEquals('My custom description', $databaseList->description); $this->assertEquals('My custom description', $databaseList->description);
} }
public function testValidListStoreResponseWithContinue(): void public function testStoreRequestWithContinue(): void
{ {
$response = $this->post('lists', [ $response = $this->post('lists', [
'name' => 'Test List', 'name' => 'Test List',
@ -93,7 +92,7 @@ class ListControllerTest extends TestCase
$this->assertEquals('Test List', $databaseList->name); $this->assertEquals('Test List', $databaseList->name);
} }
public function testInvalidListStoreResponse(): void public function testInvalidStoreRequest(): void
{ {
$response = $this->post('lists', [ $response = $this->post('lists', [
'name' => null, 'name' => null,
@ -105,7 +104,7 @@ class ListControllerTest extends TestCase
]); ]);
} }
public function testValidListDetailResponse(): void public function testDetailView(): void
{ {
$list = factory(LinkList::class)->create([ $list = factory(LinkList::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
@ -117,7 +116,7 @@ class ListControllerTest extends TestCase
->assertSee($list->name); ->assertSee($list->name);
} }
public function testValidListEditResponse(): void public function testEditView(): void
{ {
factory(LinkList::class)->create([ factory(LinkList::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
@ -136,7 +135,7 @@ class ListControllerTest extends TestCase
$response->assertStatus(404); $response->assertStatus(404);
} }
public function testValidListUpdateResponse(): void public function testUpdateResponse(): void
{ {
$baseList = factory(LinkList::class)->create([ $baseList = factory(LinkList::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
@ -157,7 +156,19 @@ class ListControllerTest extends TestCase
$this->assertEquals('New Test List', $updatedLink->name); $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([ $baseList = factory(LinkList::class)->create([
'user_id' => $this->user->id, '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([ factory(LinkList::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
@ -194,7 +205,7 @@ class ListControllerTest extends TestCase
$this->assertNotNull($databaseList->deleted_at); $this->assertNotNull($databaseList->deleted_at);
} }
public function testInvalidListDeleteResponse(): void public function testMissingModelErrorForDelete(): void
{ {
$response = $this->post('lists/1', [ $response = $this->post('lists/1', [
'_method' => 'delete', '_method' => 'delete',