This commit is contained in:
Saufi
2026-06-03 08:51:22 +08:00
commit a14d43fe34
347 changed files with 38197 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
<?php
namespace Tests\Unit;
use App\Models\Attendance;
use App\Models\Position;
use App\Models\PusatMengundi;
use App\Models\StaffAssignment;
use App\Services\Attendance\AttendanceSummaryService;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AttendanceSummaryServiceTest extends TestCase
{
use RefreshDatabase;
public function test_attendance_summary_counts_present_absent_and_not_recorded(): void
{
$this->seed(DatabaseSeeder::class);
$pusat = PusatMengundi::query()->where('code', 'PM001')->firstOrFail();
$position = Position::query()->where('code', 'PAPM')->firstOrFail();
$assignmentOne = StaffAssignment::query()->create([
'election_id' => $pusat->election_id,
'position_id' => $position->id,
'pusat_mengundi_id' => $pusat->id,
'status' => 'active',
'assigned_at' => now(),
'source' => 'test',
]);
$assignmentTwo = StaffAssignment::query()->create([
'election_id' => $pusat->election_id,
'position_id' => $position->id,
'pusat_mengundi_id' => $pusat->id,
'status' => 'active',
'assigned_at' => now(),
'source' => 'test',
]);
Attendance::query()->create([
'election_id' => $pusat->election_id,
'staff_assignment_id' => $assignmentOne->id,
'pusat_mengundi_id' => $pusat->id,
'position_id' => $position->id,
'status' => 'present',
]);
Attendance::query()->create([
'election_id' => $pusat->election_id,
'staff_assignment_id' => $assignmentTwo->id,
'pusat_mengundi_id' => $pusat->id,
'position_id' => $position->id,
'status' => 'absent',
]);
$summary = app(AttendanceSummaryService::class)->totalsForPusat($pusat);
$this->assertSame(5, $summary['total_staff']);
$this->assertSame(1, $summary['present']);
$this->assertSame(1, $summary['absent']);
$this->assertSame(3, $summary['not_recorded']);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Tests\Unit;
use App\Models\Position;
use App\Models\PusatMengundi;
use App\Models\StaffAssignment;
use App\Models\User;
use App\Services\Public\KtmVacancyService;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class KtmVacancyServiceTest extends TestCase
{
use RefreshDatabase;
public function test_ktm_vacancy_options_are_removed_when_quota_is_full(): void
{
$this->seed(DatabaseSeeder::class);
$service = new KtmVacancyService;
$pusat = PusatMengundi::query()->where('code', 'PM001')->firstOrFail();
$ktmAssignment = $this->ktmAssignment($pusat);
$kpPosition = Position::query()->where('code', 'KP')->firstOrFail();
$this->assertNotEmpty($service->optionsForRoles($pusat, ['KP'])['KP']);
foreach (range(1, 4) as $sequence) {
StaffAssignment::query()->create([
'election_id' => $pusat->election_id,
'user_id' => User::factory()->create()->id,
'position_id' => $kpPosition->id,
'pusat_mengundi_id' => $pusat->id,
'saluran_mengundi_id' => $ktmAssignment->saluran_mengundi_id,
'reports_to_assignment_id' => $ktmAssignment->id,
'status' => 'active',
'assigned_at' => now()->subMinutes($sequence),
'source' => 'test',
]);
}
$this->assertFalse($service->hasVacancyForAssignment($ktmAssignment->id, $pusat, 'KP'));
}
private function ktmAssignment(PusatMengundi $pusatMengundi): StaffAssignment
{
$ktmPosition = Position::query()->where('code', 'KTM')->firstOrFail();
return StaffAssignment::query()
->where('election_id', $pusatMengundi->election_id)
->where('pusat_mengundi_id', $pusatMengundi->id)
->where('position_id', $ktmPosition->id)
->where('status', 'active')
->whereNotNull('saluran_mengundi_id')
->firstOrFail();
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Tests\Unit;
use App\Models\Election;
use App\Services\RegistrationPeriodService;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class RegistrationPeriodServiceTest extends TestCase
{
use RefreshDatabase;
public function test_registration_period_uses_dates_and_open_flag(): void
{
$this->seed(DatabaseSeeder::class);
$service = new RegistrationPeriodService;
$election = Election::query()->where('code', 'PRN2026')->firstOrFail();
$this->assertTrue($service->isOpen($election));
$election->settings()->update([
'is_registration_open' => false,
'is_registration_open_override' => null,
]);
$election->refresh()->load('settings');
$this->assertFalse($service->isOpen($election));
}
public function test_registration_override_can_explicitly_open_or_close(): void
{
$this->seed(DatabaseSeeder::class);
$service = new RegistrationPeriodService;
$election = Election::query()->where('code', 'PRN2026')->firstOrFail();
$election->settings()->update([
'registration_start_date' => now()->subWeeks(4)->toDateString(),
'registration_end_date' => now()->subDay()->toDateString(),
'is_registration_open' => true,
'is_registration_open_override' => true,
]);
$election->refresh()->load('settings');
$this->assertTrue($service->isOpen($election));
$election->settings()->update([
'is_registration_open_override' => false,
]);
$election->refresh()->load('settings');
$this->assertFalse($service->isOpen($election));
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Tests\Unit;
use App\Support\SensitiveData;
use PHPUnit\Framework\TestCase;
class SensitiveDataTest extends TestCase
{
public function test_sensitive_data_masking(): void
{
$this->assertSame('9001****5555', SensitiveData::maskIc('900101105555'));
$this->assertSame('123***7890', SensitiveData::maskAccount('1234567890'));
$this->assertSame('012****789', SensitiveData::maskPhone('0123456789'));
$this->assertSame('-', SensitiveData::maskAccount(null));
}
}