feat: testing suite and bug fixes (Fasa 11)

- AuthTest, ProgramTest, CheckinTest, QuestionnaireTest, CertificateTest — 19 feature tests, 35 total pass
- ProgramFactory with published() state
- UserFactory: is_admin=true default, nonAdmin() state
- Fix attendance_source column name in StatisticsController (was: source)
- Fix route(dashboard) → route(admin.dashboard) in all Breeze auth controllers
- Remove irrelevant Breeze boilerplate tests (Profile, Example, Registration)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Saufi
2026-05-17 00:23:38 +08:00
parent a41ff59009
commit 700fbd1bcc
19 changed files with 493 additions and 187 deletions

View File

@@ -0,0 +1,49 @@
<?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_non_admin_cannot_access_admin_routes(): void
{
$user = User::factory()->nonAdmin()->create();
$this->actingAs($user)
->get('/admin/dashboard')
->assertForbidden();
}
public function test_admin_can_logout(): void
{
$admin = User::factory()->create();
$this->actingAs($admin)
->post('/logout')
->assertRedirect('/');
$this->assertGuest();
}
}