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:
116
tests/Feature/QuestionnaireTest.php
Normal file
116
tests/Feature/QuestionnaireTest.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Participant;
|
||||
use App\Models\Program;
|
||||
use App\Models\ProgramParticipant;
|
||||
use App\Models\ProgramQrCode;
|
||||
use App\Models\ProgramQuestionnaire;
|
||||
use App\Models\QuestionnaireQuestion;
|
||||
use App\Models\QuestionnaireResponse;
|
||||
use App\Models\QuestionnaireSet;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class QuestionnaireTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Program $program;
|
||||
private ProgramQrCode $qrCode;
|
||||
private Participant $participant;
|
||||
private QuestionnaireQuestion $question;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$admin = User::factory()->create();
|
||||
$this->program = Program::factory()->published()->create(['created_by' => $admin->id]);
|
||||
|
||||
$this->qrCode = ProgramQrCode::create([
|
||||
'program_id' => $this->program->id,
|
||||
'token' => 'qr-token-test-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
'qr_image_path' => 'qrcodes/test.png',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->participant = Participant::create([
|
||||
'name' => 'Peserta Ujian',
|
||||
'no_kp' => '900101011234',
|
||||
'email' => 'peserta@test.com',
|
||||
'participant_type' => 'staff',
|
||||
]);
|
||||
|
||||
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',
|
||||
]);
|
||||
|
||||
$set = QuestionnaireSet::create([
|
||||
'title' => 'Borang Penilaian Ujian',
|
||||
'status' => 'published',
|
||||
'created_by' => $admin->id,
|
||||
]);
|
||||
|
||||
$this->question = QuestionnaireQuestion::create([
|
||||
'questionnaire_set_id' => $set->id,
|
||||
'question_text' => 'Bagaimana penilaian anda?',
|
||||
'question_type' => 'rating',
|
||||
'is_required' => true,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
ProgramQuestionnaire::create([
|
||||
'program_id' => $this->program->id,
|
||||
'questionnaire_set_id' => $set->id,
|
||||
'is_confirmed' => true,
|
||||
'confirmed_at' => now(),
|
||||
'confirmed_by' => $admin->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_questionnaire_form_is_shown_to_participant(): void
|
||||
{
|
||||
$url = "/p/{$this->qrCode->token}/questionnaire/{$this->participant->uuid}";
|
||||
|
||||
$this->get($url)
|
||||
->assertOk()
|
||||
->assertSee('Bagaimana penilaian anda?');
|
||||
}
|
||||
|
||||
public function test_participant_can_submit_questionnaire(): void
|
||||
{
|
||||
$url = "/p/{$this->qrCode->token}/questionnaire/{$this->participant->uuid}";
|
||||
|
||||
$this->post($url, [
|
||||
'q_' . $this->question->id => 4,
|
||||
])->assertViewIs('public.questionnaire.thankyou');
|
||||
|
||||
$this->assertDatabaseHas('questionnaire_responses', [
|
||||
'program_id' => $this->program->id,
|
||||
'participant_id' => $this->participant->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_double_submission_shows_already_view(): void
|
||||
{
|
||||
QuestionnaireResponse::create([
|
||||
'program_id' => $this->program->id,
|
||||
'participant_id' => $this->participant->id,
|
||||
'questionnaire_set_id' => $this->question->questionnaire_set_id,
|
||||
'submitted_at' => now(),
|
||||
'ip_address' => '127.0.0.1',
|
||||
]);
|
||||
|
||||
$url = "/p/{$this->qrCode->token}/questionnaire/{$this->participant->uuid}";
|
||||
|
||||
$this->get($url)->assertViewIs('public.questionnaire.already');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user