93 lines
2.3 KiB
PHP
93 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Accounting\Account;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Tests\TestCase;
|
|
|
|
use App\Models\Account;
|
|
|
|
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","accounting.account:update")->first();
|
|
$role = Role::factory()->create();
|
|
$role->permissions()->attach($permission->id);
|
|
$user = User::factory()->create();
|
|
$user->roles()->attach($role->id);
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$data = Account::factory()->create();
|
|
|
|
$response = $this->post('/accounting/account/'.$data->id,[
|
|
"name" => "update role",
|
|
"code" => "code",
|
|
"sheet" => "sheet",
|
|
"structure" => "structure",
|
|
"type" => "type",
|
|
"category" => "category",
|
|
"subcategory" => "subcategory",
|
|
]);
|
|
|
|
$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","accounting.account:update")->first();
|
|
$role = Role::factory()->create();
|
|
$role->permissions()->attach($permission->id);
|
|
|
|
$user = User::factory()->create();
|
|
$user->roles()->attach($role->id);
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$data = Account::factory()->create();
|
|
$role2 = Role::factory()->create();
|
|
|
|
$response = $this->post('/accounting/account/'.$data->id,[
|
|
|
|
"name" => "update role",
|
|
"code" => "code",
|
|
"sheet" => "sheet",
|
|
"structure" => "structure",
|
|
"type" => "type",
|
|
"category" => "category",
|
|
"subcategory" => "subcategory",
|
|
]);
|
|
|
|
$response->assertStatus(200);
|
|
$response->assertJson([
|
|
"data" => [
|
|
"name" => "update role"
|
|
]
|
|
]);
|
|
}
|
|
}
|