- Replace is_admin boolean with role enum('super_admin','admin') via migration
- ProgramPolicy: admin program can only view/edit/delete own programs
- EnsureIsAdmin: accepts both roles; EnsureSuperAdmin: super_admin only
- UserController + views: super_admin can manage admin accounts
- Sidebar: user management link & role badge gated on isSuperAdmin()
- Fix Controller base class: add AuthorizesRequests trait
- Fix tests: replace nonAdmin() (invalid enum) with adminProgram() against super_admin-only route
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AuthTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_admin_can_login_and_is_redirected_to_dashboard(): void
|
|
{
|
|
$admin = User::factory()->create(['email' => 'admin@test.com', 'password' => bcrypt('password')]);
|
|
|
|
$this->post('/login', [
|
|
'email' => 'admin@test.com',
|
|
'password' => 'password',
|
|
])->assertRedirect('/admin/dashboard');
|
|
|
|
$this->assertAuthenticatedAs($admin);
|
|
}
|
|
|
|
public function test_unauthenticated_user_is_redirected_from_admin(): void
|
|
{
|
|
$this->get('/admin/dashboard')->assertRedirect('/login');
|
|
}
|
|
|
|
public function test_admin_program_cannot_access_user_management(): void
|
|
{
|
|
$admin = User::factory()->adminProgram()->create();
|
|
|
|
$this->actingAs($admin)
|
|
->get('/admin/users')
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function test_admin_can_logout(): void
|
|
{
|
|
$admin = User::factory()->create();
|
|
|
|
$this->actingAs($admin)
|
|
->post('/logout')
|
|
->assertRedirect('/');
|
|
|
|
$this->assertGuest();
|
|
}
|
|
}
|