85 lines
2.4 KiB
PHP
85 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Tests\TestCase;
|
|
use App\Models\User;
|
|
use App\Models\Employee;
|
|
use App\Models\Shift;
|
|
use App\Models\Branch;
|
|
use App\Models\AttendanceRecord;
|
|
use App\Services\AttendanceService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
class AttendanceClockSourceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected $user;
|
|
protected $employee;
|
|
protected $branch;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$companyUser = User::create([
|
|
'name' => 'Company Admin',
|
|
'email' => 'admin@company.com',
|
|
'password' => bcrypt('password'),
|
|
'type' => 'company',
|
|
]);
|
|
|
|
$this->branch = Branch::create([
|
|
'name' => 'Main Branch',
|
|
'created_by' => $companyUser->id,
|
|
]);
|
|
|
|
$this->user = User::create([
|
|
'name' => 'Test Employee',
|
|
'email' => 'testemployee@example.com',
|
|
'password' => bcrypt('password'),
|
|
'type' => 'employee',
|
|
'created_by' => $companyUser->id,
|
|
'branch_id' => $this->branch->id,
|
|
]);
|
|
|
|
$this->employee = Employee::create([
|
|
'user_id' => $this->user->id,
|
|
'employee_id' => 'EMPTEST002',
|
|
'branch_id' => $this->branch->id,
|
|
'rest_days' => ['sunday'],
|
|
'date_of_joining' => '2026-08-01',
|
|
'created_by' => $companyUser->id,
|
|
]);
|
|
}
|
|
|
|
public function test_clock_in_and_clock_out_persists_mobile_source()
|
|
{
|
|
$service = app(AttendanceService::class);
|
|
|
|
// Clock In
|
|
$resultIn = $service->processClock($this->user, $this->employee, [
|
|
'action' => 'clock_in',
|
|
'latitude' => 14.5995,
|
|
'longitude' => 120.9842,
|
|
]);
|
|
|
|
$this->assertTrue($resultIn['success']);
|
|
$record = AttendanceRecord::where('employee_id', $this->user->id)->first();
|
|
$this->assertNotNull($record);
|
|
$this->assertEquals('mobile', $record->clock_in_source);
|
|
|
|
// Clock Out
|
|
$resultOut = $service->processClock($this->user, $this->employee, [
|
|
'action' => 'clock_out',
|
|
'latitude' => 14.5995,
|
|
'longitude' => 120.9842,
|
|
]);
|
|
|
|
$this->assertTrue($resultOut['success']);
|
|
$record->refresh();
|
|
$this->assertEquals('mobile', $record->clock_out_source);
|
|
}
|
|
}
|