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:
98
tests/Feature/CertificateTest.php
Normal file
98
tests/Feature/CertificateTest.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Attendance;
|
||||
use App\Models\Certificate;
|
||||
use App\Models\Participant;
|
||||
use App\Models\Program;
|
||||
use App\Models\ProgramParticipant;
|
||||
use App\Models\ProgramQrCode;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CertificateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Program $program;
|
||||
private Participant $participant;
|
||||
private Certificate $certificate;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$admin = User::factory()->create();
|
||||
$this->program = Program::factory()->published()->create(['created_by' => $admin->id]);
|
||||
|
||||
$this->participant = Participant::create([
|
||||
'name' => 'Peserta Sijil',
|
||||
'no_kp' => '900101011234',
|
||||
'email' => 'sijil@test.com',
|
||||
'participant_type' => 'staff',
|
||||
]);
|
||||
|
||||
$this->certificate = Certificate::create([
|
||||
'program_id' => $this->program->id,
|
||||
'participant_id' => $this->participant->id,
|
||||
'token' => 'cert-token-test-48-chars-xxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
'status' => 'generated',
|
||||
'generated_at' => now(),
|
||||
'certificate_no' => 'ECT/2025/0001',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_certificate_show_page_loads_for_generated_certificate(): void
|
||||
{
|
||||
$this->get("/certificate/{$this->certificate->token}")
|
||||
->assertOk()
|
||||
->assertSee('Sijil Sedia Dimuat Turun');
|
||||
}
|
||||
|
||||
public function test_pending_certificate_shows_not_ready_message(): void
|
||||
{
|
||||
$this->certificate->update(['status' => 'pending']);
|
||||
|
||||
$this->get("/certificate/{$this->certificate->token}")
|
||||
->assertOk()
|
||||
->assertSee('Sijil Belum Sedia');
|
||||
}
|
||||
|
||||
public function test_invalid_certificate_token_returns_404(): void
|
||||
{
|
||||
$this->get('/certificate/invalid-token-xxxx')->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_semak_kehadiran_shows_result_for_valid_no_kp(): void
|
||||
{
|
||||
$qrCode = ProgramQrCode::create([
|
||||
'program_id' => $this->program->id,
|
||||
'token' => 'semak-token-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
'qr_image_path' => 'qrcodes/test.png',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
ProgramParticipant::create([
|
||||
'program_id' => $this->program->id,
|
||||
'participant_id' => $this->participant->id,
|
||||
'registration_source' => 'pre_registered',
|
||||
'is_pre_registered' => true,
|
||||
'pre_registered_session' => 'pagi',
|
||||
'status' => 'checked_in',
|
||||
]);
|
||||
|
||||
Attendance::create([
|
||||
'program_id' => $this->program->id,
|
||||
'participant_id' => $this->participant->id,
|
||||
'attendance_session' => 'pagi',
|
||||
'attendance_source' => 'pre_registered_staff',
|
||||
'checked_in_at' => now(),
|
||||
]);
|
||||
|
||||
$this->post("/p/{$qrCode->token}/semak", [
|
||||
'no_kp' => '900101011234',
|
||||
])->assertViewIs('public.semak.result');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user