Add extensive controller and model tests
This commit is contained in:
48
tests/Feature/PortalControllerTest.php
Normal file
48
tests/Feature/PortalControllerTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Forum;
|
||||
use App\Models\Post;
|
||||
use App\Models\Thread;
|
||||
use App\Models\User;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
it('returns portal summary payload', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$category = Forum::create([
|
||||
'name' => 'Category',
|
||||
'description' => null,
|
||||
'type' => 'category',
|
||||
'parent_id' => null,
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$forum = Forum::create([
|
||||
'name' => 'Forum',
|
||||
'description' => null,
|
||||
'type' => 'forum',
|
||||
'parent_id' => $category->id,
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$thread = Thread::create([
|
||||
'forum_id' => $forum->id,
|
||||
'user_id' => $user->id,
|
||||
'title' => 'Thread',
|
||||
'body' => 'Body',
|
||||
]);
|
||||
|
||||
Post::create([
|
||||
'thread_id' => $thread->id,
|
||||
'user_id' => $user->id,
|
||||
'body' => 'Reply',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
$response = $this->getJson('/api/portal/summary');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure(['forums', 'threads', 'stats', 'profile']);
|
||||
$response->assertJsonFragment(['name' => 'Forum']);
|
||||
$response->assertJsonFragment(['title' => 'Thread']);
|
||||
});
|
||||
Reference in New Issue
Block a user