crate file test for damage and fix update request and add 2 option in validation
This commit is contained in:
@@ -2,11 +2,72 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\V3\Damage;
|
namespace Tests\Feature\V3\Damage;
|
||||||
|
|
||||||
|
use App\Models\Damage;
|
||||||
|
use App\Models\Permission;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class ActivateTest extends TestCase
|
class ActivateTest extends TestCase
|
||||||
{
|
{
|
||||||
|
use RefreshDatabase, WithFaker;
|
||||||
|
|
||||||
|
public function test_unauthenticated_user_cannot_activate_damage(): void
|
||||||
|
{
|
||||||
|
$response = $this->postJson(route('v3.damages.store'));
|
||||||
|
$response->assertStatus(401);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_without_permission_cannot_activate_damage(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.damages.store'));
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function test_user_with_permission_can_activate_damage(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory()->state(['name' => 'manage-damage']))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$damage = Damage::factory()->create(['status' => 0]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.damages.activate', [$damage->id]));
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertJson([
|
||||||
|
'message' => __('messages.successful')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('damages', [
|
||||||
|
'id' => $damage->id,
|
||||||
|
'status' => 1,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_with_permission_can_deactivate_damage(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()
|
||||||
|
->has(Permission::factory()->state(['name' => 'manage-damage']))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$damage = Damage::factory()->create(['status' => 1]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('v3.damages.activate', [$damage->id]));
|
||||||
|
|
||||||
|
$response->assertOk()
|
||||||
|
->assertJson([
|
||||||
|
'message' => __('messages.successful')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('damages', [
|
||||||
|
'id' => $damage->id,
|
||||||
|
'status' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,20 +16,20 @@ class IndexTest extends TestCase
|
|||||||
* A basic feature test example.
|
* A basic feature test example.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function test_user_should_have_manage_damage_permission_index(): void
|
public function test_user_should_have_manage_damage_permission_index_damage(): void
|
||||||
{
|
{
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$response = $this->actingAs($user)->getJson(route('v3.damages.index'));
|
$response = $this->actingAs($user)->getJson(route('v3.damages.index'));
|
||||||
$response->assertForbidden();
|
$response->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_user_cannot_access_authentication(): void
|
public function test_user_cannot_access_authentication_to_index_damage(): void
|
||||||
{
|
{
|
||||||
$response = $this->getJson(route('v3.damages.index'));
|
$response = $this->getJson(route('v3.damages.index'));
|
||||||
$response->assertStatus(401);
|
$response->assertStatus(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_all_damages_returned_successfully_for_index(): void
|
public function test_all_damages_returned_successfully_for_index_damage(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$user = User::factory()
|
$user = User::factory()
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ class ListTest extends TestCase
|
|||||||
{
|
{
|
||||||
use RefreshDatabase, WithFaker;
|
use RefreshDatabase, WithFaker;
|
||||||
|
|
||||||
public function test_user_cannot_access_authentication(): void
|
public function test_user_cannot_access_authentication_list_damage(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$response = $this->getJson(route('v3.damages.list'));
|
$response = $this->getJson(route('v3.damages.list'));
|
||||||
$response->assertStatus(401);
|
$response->assertStatus(401);
|
||||||
}
|
}
|
||||||
public function test_all_damages_returned_successfully_for_list(): void
|
public function test_all_damages_returned_successfully_for_list_damage(): void
|
||||||
{
|
{
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
Damage::factory()->count(5)->create();
|
Damage::factory()->count(5)->create();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class ShowTest extends TestCase
|
|||||||
{
|
{
|
||||||
use RefreshDatabase , WithFaker;
|
use RefreshDatabase , WithFaker;
|
||||||
|
|
||||||
public function test_unauthenticated_user_cannot_view_damage(): void
|
public function test_unauthenticated_user_cannot_view_show_damage(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$damage = Damage::factory()->create();;
|
$damage = Damage::factory()->create();;
|
||||||
@@ -22,7 +22,7 @@ class ShowTest extends TestCase
|
|||||||
$response->assertStatus(401);
|
$response->assertStatus(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_user_without_permission_cannot_view_damage(): void
|
public function test_user_without_permission_cannot_view_damage_show_damage(): void
|
||||||
{
|
{
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$damage = Damage::factory()->create();;
|
$damage = Damage::factory()->create();;
|
||||||
@@ -32,7 +32,7 @@ class ShowTest extends TestCase
|
|||||||
$response->assertForbidden();
|
$response->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_user_with_permission_can_view_damage(): void
|
public function test_user_with_permission_can_view_damage_to_show_damage(): void
|
||||||
{
|
{
|
||||||
$user = User::factory()
|
$user = User::factory()
|
||||||
->has(Permission::factory([
|
->has(Permission::factory([
|
||||||
|
|||||||
Reference in New Issue
Block a user