crate file test for damage and fix update request and add 2 option in validation
This commit is contained in:
66
tests/Feature/V3/Damage/IndexTest.php
Normal file
66
tests/Feature/V3/Damage/IndexTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\V3\Damage;
|
||||
|
||||
use App\Models\Damage;
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
|
||||
class IndexTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*/
|
||||
|
||||
public function test_user_should_have_manage_damage_permission_index(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->getJson(route('v3.damages.index'));
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_user_cannot_access_authentication(): void
|
||||
{
|
||||
$response = $this->getJson(route('v3.damages.index'));
|
||||
$response->assertStatus(401);
|
||||
}
|
||||
|
||||
public function test_all_damages_returned_successfully_for_index(): void
|
||||
{
|
||||
|
||||
$user = User::factory()
|
||||
->has(factory: Permission::factory([
|
||||
'name' => 'manage-damage'
|
||||
]))
|
||||
->create();
|
||||
|
||||
|
||||
Damage::factory()->count(5)->create();
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('v3.damages.index', [
|
||||
'start' => 0,
|
||||
'size' => 10,
|
||||
'filters' => json_encode([]),
|
||||
'sorting' => json_encode([]),
|
||||
]));
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([
|
||||
'data' => [
|
||||
'*' => [
|
||||
'id',
|
||||
'title',
|
||||
'unit',
|
||||
'base_price',
|
||||
'status',
|
||||
],
|
||||
],
|
||||
'meta' => [
|
||||
'totalRowCount',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user