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']); } }