ERP-API/tests/Feature/Auth/Role/UpdateTest.php

86 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature\Auth\Role;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\Role;
use App\Models\Permission;
use App\Models\User;
use Laravel\Sanctum\Sanctum;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class UpdateTest extends TestCase
{
use DatabaseTransactions;
/**
* A basic feature test example.
*/
public function test_success(): void
{
$permission = Permission::where("code","auth.role:update")->first();
$role = Role::factory()->create();
$role->permissions()->attach($permission->id);
$user = User::factory()->create();
$user->roles()->attach($role->id);
Sanctum::actingAs($user);
$data = Role::factory()->create();
$response = $this->post('/auth/role/'.$data->id,[
"name" => "update role",
]);
$response->assertStatus(200);
$response->assertJson([
"data" => [
"name" => "update role",
]
]);
}
/**
* A basic feature test example.
*/
public function test_with_roles_success(): void
{
$permission = Permission::where("code","auth.role:update")->first();
$role = Role::factory()->create();
$role->permissions()->attach($permission->id);
$user = User::factory()->create();
$user->roles()->attach($role->id);
Sanctum::actingAs($user);
$data = Role::factory()->create();
$role2 = Role::factory()->create();
$response = $this->post('/auth/role/'.$data->id,[
"name" => "update role",
"permissions" => [
$permission->id
]
]);
$response->assertStatus(200);
$response->assertJson([
"data" => [
"name" => "update role",
"permissions" => [
[
"id" => $permission->id
]
]
]
]);
}
}