Merhabalar. Aşağıdaki gibi bir test yazdım. İncelemelerinizi ve önerilerinizi okumak isterim. İyi çalışmalar.
<?php
namespace Tests\Feature\Customer;
use App\Libraries\Enum\Roles;
use App\Models\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CreateTest extends TestCase
{
use DatabaseTransactions;
public function registerAndLogin($Role = Roles::ENGINEER)
{
$user = User::factory()->create();
$user->syncRoles([$Role]);
$this->post('/login', [
'email' => $user->email,
'password' => 'password',
]);
$this->assertAuthenticated();
}
/**
* Test for Engineer
*/
public function test_render_customer_create_page_for_engineer()
{
$this->registerAndLogin(Roles::ENGINEER);
$response = $this->get('/customer/create');
$response->assertStatus(200);
}
public function test_store_customer_for_engineer()
{
$this->registerAndLogin(Roles::ENGINEER);
$response = $this->post('/customer/store', [
'name' => 'Test Customer',
'tracking_number' => 'Test Customer',
'user_id' => 1
]);
$this->followRedirects($response)->assertStatus(200);
}
/**
* Test for User
*/
public function test_render_customer_create_page_for_user()
{
$this->registerAndLogin(Roles::USER);
$response = $this->get('/customer/create');
$response->assertStatus(403);
}
public function test_store_customer_for_user()
{
$this->registerAndLogin(Roles::USER);
$response = $this->post('/customer/store', [
'name' => 'Test Customer',
'tracking_number' => 'Test Customer',
'user_id' => 1
]);
$this->followRedirects($response)->assertStatus(403);
}
/**
* Test for Supervisor
*/
public function test_render_customer_create_page_for_supervisor()
{
$this->registerAndLogin(Roles::SUPERVISOR);
$response = $this->get('/customer/create');
$response->assertStatus(403);
}
public function test_store_customer_for_supervisor()
{
$this->registerAndLogin(Roles::SUPERVISOR);
$response = $this->post('/customer/store', [
'name' => 'Test Customer',
'tracking_number' => 'Test Customer',
'user_id' => 1
]);
$this->followRedirects($response)->assertStatus(403);
}
}