Files
KarbonDatacenter/tests/Feature/ConsultantManagementTest.php
2026-06-24 20:32:14 +08:00

66 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Consultant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ConsultantManagementTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seedRolesAndPermissions();
}
public function test_jpp_can_create_consultant(): void
{
$jpp = $this->makeUserWithRole('JPP Admin');
$response = $this->actingAs($jpp)->post(route('consultants.store'), [
'nama_perunding' => 'Perunding Hijau Sdn Bhd',
'no_pendaftaran_syarikat' => '202301000999',
'emel' => 'hijau@example.com',
'telefon' => '07-9998888',
'aktif' => 1,
]);
$this->assertDatabaseHas('consultants', ['nama_perunding' => 'Perunding Hijau Sdn Bhd']);
$response->assertRedirect();
}
public function test_jpp_can_create_consultant_with_login_account(): void
{
$jpp = $this->makeUserWithRole('JPP Admin');
$this->actingAs($jpp)->post(route('consultants.store'), [
'nama_perunding' => 'Perunding Akaun Sdn Bhd',
'aktif' => 1,
'buat_akaun' => 1,
'user_name' => 'Perunding Akaun',
'user_email' => 'akaun@example.com',
'user_password' => 'rahsia12345',
]);
$this->assertDatabaseHas('users', ['email' => 'akaun@example.com']);
$consultant = Consultant::where('nama_perunding', 'Perunding Akaun Sdn Bhd')->first();
$this->assertNotNull($consultant->user_id);
$this->assertTrue($consultant->user->hasRole('Perunding'));
}
public function test_perunding_cannot_create_consultant(): void
{
[$user] = $this->makeConsultantUser();
$this->actingAs($user)->post(route('consultants.store'), [
'nama_perunding' => 'Tidak Dibenarkan',
'aktif' => 1,
])->assertForbidden();
$this->assertDatabaseMissing('consultants', ['nama_perunding' => 'Tidak Dibenarkan']);
}
}