4.1-4.3: add PHPUnit feature tests for all endpoints + factories
Deploy Backend / deploy (push) Failing after 2m16s

This commit is contained in:
parsa aghaei committed 2026-06-23 18:37:14 +03:30
1 parent a4025256d4
commit 37a507c742
16 files changed
+504 -37

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
<?php
namespace Tests\Feature\Blog;
use App\Models\Blog\Category;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CategoryTest extends TestCase
{
use RefreshDatabase;
public function test_can_list_categories()
{
Category::factory()->count(3)->create();
$response = $this->getJson('/api/blog/categories');
$response->assertStatus(200);
}
public function test_can_get_single_category()
{
$category = Category::factory()->create();
$response = $this->getJson("/api/blog/categories/{$category->id}");
$response->assertStatus(200);
}
public function test_can_get_category_posts()
{
$category = Category::factory()->create();
$response = $this->getJson("/api/blog/categories/{$category->slug}/posts");
$response->assertStatus(200)
->assertJsonStructure(['category', 'posts', 'meta', 'links']);
}
public function test_can_create_category()
{
$response = $this->postJson('/api/blog/categories', [
'name' => 'Tech',
'slug' => 'tech',
]);
$response->assertStatus(201);
$this->assertDatabaseHas('categories', ['slug' => 'tech']);
}
public function test_can_delete_category()
{
$category = Category::factory()->create();
$response = $this->deleteJson("/api/blog/categories/{$category->id}");
$response->assertStatus(200);
$this->assertDatabaseMissing('categories', ['id' => $category->id]);
}
}