100 lines
3.7 KiB
PHP
100 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\AttendanceRecord;
|
|
use App\Models\Branch;
|
|
use App\Models\Employee;
|
|
use App\Models\Shift;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AttendanceGpsSummaryTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_attendance_index_returns_gps_and_biometric_stats(): void
|
|
{
|
|
$company = User::factory()->create(['type' => 'company']);
|
|
$branch = Branch::create(['name' => 'Main Branch', 'created_by' => $company->id]);
|
|
$employee = User::factory()->create(['type' => 'employee', 'created_by' => $company->id]);
|
|
Employee::create([
|
|
'user_id' => $employee->id,
|
|
'employee_id' => 'EMP-001',
|
|
'branch_id' => $branch->id,
|
|
'created_by' => $company->id,
|
|
]);
|
|
$employee2 = User::factory()->create(['type' => 'employee', 'created_by' => $company->id]);
|
|
Employee::create([
|
|
'user_id' => $employee2->id,
|
|
'employee_id' => 'EMP-002',
|
|
'branch_id' => $branch->id,
|
|
'created_by' => $company->id,
|
|
]);
|
|
|
|
$shift = Shift::create(['name' => 'Morning', 'start_time' => '08:00:00', 'end_time' => '17:00:00', 'created_by' => $company->id]);
|
|
|
|
$today = Carbon::today()->toDateString();
|
|
|
|
// 1. Record with GPS
|
|
AttendanceRecord::create([
|
|
'employee_id' => $employee->id,
|
|
'shift_id' => $shift->id,
|
|
'branch_id' => $branch->id,
|
|
'date' => $today,
|
|
'status' => 'present',
|
|
'clock_in' => '08:00:00',
|
|
'clock_in_latitude' => 14.5995,
|
|
'clock_in_longitude' => 120.9842,
|
|
'clock_in_source' => 'mobile',
|
|
'created_by' => $company->id,
|
|
]);
|
|
|
|
// 2. Record with Biometric
|
|
AttendanceRecord::create([
|
|
'employee_id' => $employee2->id,
|
|
'shift_id' => $shift->id,
|
|
'branch_id' => $branch->id,
|
|
'date' => $today,
|
|
'status' => 'present',
|
|
'clock_in' => '08:05:00',
|
|
'clock_in_source' => 'zkteco',
|
|
'created_by' => $company->id,
|
|
]);
|
|
|
|
\Spatie\Permission\Models\Permission::firstOrCreate(['name' => 'manage-attendance-records']);
|
|
\Spatie\Permission\Models\Permission::firstOrCreate(['name' => 'manage-any-attendance-records']);
|
|
$company->givePermissionTo(['manage-attendance-records', 'manage-any-attendance-records']);
|
|
|
|
$response = $this->actingAs($company)
|
|
->get(route('hr.attendance-records.index', ['view' => 'list']));
|
|
|
|
$response->assertOk();
|
|
$response->assertInertia(fn ($page) =>
|
|
$page->component('hr/attendance-records/index')
|
|
->has('todayStats.gps_clock_ins')
|
|
->has('todayStats.biometric_clock_ins')
|
|
->where('todayStats.gps_clock_ins', 1)
|
|
->where('todayStats.biometric_clock_ins', 1)
|
|
);
|
|
|
|
// Test filtering by source=gps
|
|
$gpsFilterResponse = $this->actingAs($company)
|
|
->get(route('hr.attendance-records.index', ['view' => 'list', 'source' => 'gps']));
|
|
$gpsFilterResponse->assertOk();
|
|
$gpsFilterResponse->assertInertia(fn ($page) =>
|
|
$page->where('attendanceRecords.total', 1)
|
|
);
|
|
|
|
// Test filtering by source=zkteco
|
|
$bioFilterResponse = $this->actingAs($company)
|
|
->get(route('hr.attendance-records.index', ['view' => 'list', 'source' => 'zkteco']));
|
|
$bioFilterResponse->assertOk();
|
|
$bioFilterResponse->assertInertia(fn ($page) =>
|
|
$page->where('attendanceRecords.total', 1)
|
|
);
|
|
}
|
|
}
|