62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Database\Seeders\RoleUserSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AuthTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->seed(RoleUserSeeder::class);
|
|
}
|
|
|
|
public function test_admin_can_login_and_reach_dashboard(): void
|
|
{
|
|
$response = $this->post('/login', [
|
|
'email' => 'admin@koipb.test',
|
|
'password' => 'password',
|
|
]);
|
|
|
|
$response->assertRedirect(route('dashboard'));
|
|
$this->assertAuthenticated();
|
|
}
|
|
|
|
public function test_wrong_password_fails(): void
|
|
{
|
|
$response = $this->post('/login', [
|
|
'email' => 'admin@koipb.test',
|
|
'password' => 'salah',
|
|
]);
|
|
|
|
$response->assertSessionHasErrors('email');
|
|
$this->assertGuest();
|
|
}
|
|
|
|
public function test_kaunter_cannot_access_draw(): void
|
|
{
|
|
$user = User::where('email', 'kaunter@koipb.test')->first();
|
|
$this->actingAs($user)->get('/cabutan')->assertForbidden();
|
|
}
|
|
|
|
public function test_cabutan_cannot_access_counter(): void
|
|
{
|
|
$user = User::where('email', 'cabutan@koipb.test')->first();
|
|
$this->actingAs($user)->get('/kaunter')->assertForbidden();
|
|
}
|
|
|
|
public function test_admin_can_access_all(): void
|
|
{
|
|
$user = User::where('email', 'admin@koipb.test')->first();
|
|
$this->actingAs($user)->get('/cabutan')->assertOk();
|
|
$this->actingAs($user)->get('/kaunter')->assertOk();
|
|
$this->actingAs($user)->get('/admin/anggota')->assertOk();
|
|
}
|
|
}
|