4.1-4.3: add PHPUnit feature tests for all endpoints + factories
This commit is contained in:
1 parent
afb202f333
commit
9ff5b93157
16 files changed
+504
-37
No files matched your search
@@ -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]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user