mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-03-14 19:59:38 +01:00
Refactor the guest lists controller and add corresponding controller tests
This commit is contained in:
parent
9537a8bb12
commit
c7f1d4534d
@ -37,7 +37,7 @@ class ListController extends Controller
|
||||
*/
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
$list = LinkList::find($id);
|
||||
$list = LinkList::isPrivate(false)->find($id);
|
||||
|
||||
if (empty($list)) {
|
||||
abort(404);
|
||||
@ -48,7 +48,7 @@ class ListController extends Controller
|
||||
if ($request->has('orderBy') && $request->has('orderDir')) {
|
||||
$links->orderBy($request->get('orderBy'), $request->get('orderDir'));
|
||||
} else {
|
||||
$links->orderBy('created_at', 'DESC');
|
||||
$links->latest();
|
||||
}
|
||||
|
||||
$links = $links->paginate(getPaginationLimit());
|
||||
|
63
tests/Feature/Controller/Guest/ListControllerTest.php
Normal file
63
tests/Feature/Controller/Guest/ListControllerTest.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Controller\Guest;
|
||||
|
||||
use App\Models\LinkList;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ListControllerTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
use DatabaseMigrations;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Setting::create([
|
||||
'key' => 'system_guest_access',
|
||||
'value' => '1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testValidListOverviewResponse(): void
|
||||
{
|
||||
factory(User::class)->create();
|
||||
|
||||
$listPublic = factory(LinkList::class)->create(['is_private' => false]);
|
||||
$listPrivate = factory(LinkList::class)->create(['is_private' => true]);
|
||||
|
||||
$response = $this->get('guest/lists');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertSee($listPublic->name)
|
||||
->assertDontSee($listPrivate->name);
|
||||
}
|
||||
|
||||
public function testValidListDetailResponse(): void
|
||||
{
|
||||
factory(User::class)->create();
|
||||
|
||||
$listPublic = factory(LinkList::class)->create(['is_private' => false]);
|
||||
|
||||
$response = $this->get('guest/lists/1');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertSee($listPublic->name);
|
||||
}
|
||||
|
||||
public function testInvalidListDetailResponse(): void
|
||||
{
|
||||
factory(User::class)->create();
|
||||
|
||||
factory(LinkList::class)->create(['is_private' => true]);
|
||||
|
||||
$response = $this->get('guest/lists/1');
|
||||
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user