parsaaghayi-backend/tests/Feature/Blog/CategoryTest.php

62 lines
1.5 KiB
PHP

<?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]);
}
}