write test for another items and change some part of the code
This commit is contained in:
41
tests/Feature/Category/ListTest.php
Normal file
41
tests/Feature/Category/ListTest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Category;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ListTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
|
||||
public function test_guest_user_cannot_access_list(): void
|
||||
{
|
||||
$response = $this->getJson(route('categories.list'));
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
public function test_user_can_see_list(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->getJson(route('categories.list'));
|
||||
|
||||
Category::factory()->count(3)->create();
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([
|
||||
'data' => [
|
||||
'*' => [
|
||||
'id',
|
||||
'category_id',
|
||||
'category_name',
|
||||
'subcategory_id',
|
||||
'subcategory_name'
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user