64 lines
2.1 KiB
PHP
64 lines
2.1 KiB
PHP
<?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']);
|
|
}
|
|
}
|