Add extensive controller and model tests
This commit is contained in:
85
tests/Feature/StatsControllerTest.php
Normal file
85
tests/Feature/StatsControllerTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Attachment;
|
||||
use App\Models\Forum;
|
||||
use App\Models\Post;
|
||||
use App\Models\Thread;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
it('returns forum statistics summary', function (): void {
|
||||
Storage::fake('public');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$forum = Forum::create([
|
||||
'name' => 'Category',
|
||||
'description' => null,
|
||||
'type' => 'category',
|
||||
'parent_id' => null,
|
||||
'position' => 1,
|
||||
]);
|
||||
$child = Forum::create([
|
||||
'name' => 'Forum',
|
||||
'description' => null,
|
||||
'type' => 'forum',
|
||||
'parent_id' => $forum->id,
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$thread = Thread::create([
|
||||
'forum_id' => $child->id,
|
||||
'user_id' => $user->id,
|
||||
'title' => 'Thread',
|
||||
'body' => 'Body',
|
||||
]);
|
||||
|
||||
Post::create([
|
||||
'thread_id' => $thread->id,
|
||||
'user_id' => $user->id,
|
||||
'body' => 'Post',
|
||||
]);
|
||||
|
||||
Attachment::create([
|
||||
'thread_id' => $thread->id,
|
||||
'post_id' => null,
|
||||
'attachment_extension_id' => null,
|
||||
'attachment_group_id' => null,
|
||||
'user_id' => $user->id,
|
||||
'disk' => 'local',
|
||||
'path' => 'attachments/threads/'.$thread->id.'/file.pdf',
|
||||
'original_name' => 'file.pdf',
|
||||
'extension' => 'pdf',
|
||||
'mime_type' => 'application/pdf',
|
||||
'size_bytes' => 123,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/stats');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([
|
||||
'threads',
|
||||
'posts',
|
||||
'users',
|
||||
'attachments',
|
||||
'board_started_at',
|
||||
'attachments_size_bytes',
|
||||
'avatar_directory_size_bytes',
|
||||
'database_size_bytes',
|
||||
'database_server',
|
||||
'gzip_compression',
|
||||
'php_version',
|
||||
'orphan_attachments',
|
||||
'board_version',
|
||||
'posts_per_day',
|
||||
'topics_per_day',
|
||||
'users_per_day',
|
||||
'attachments_per_day',
|
||||
]);
|
||||
|
||||
$response->assertJsonFragment([
|
||||
'threads' => 1,
|
||||
'users' => 1,
|
||||
'attachments' => 1,
|
||||
'attachments_size_bytes' => 123,
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user