base commit

This commit is contained in:
Mekan1206
2026-07-30 17:24:40 +05:00
commit a794dacd39
345 changed files with 29597 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
use App\Enums\EmploymentStatus;
use App\Models\Department;
use App\Models\Employee;
use App\Models\Position;
use App\Models\Shift;
use App\Notifications\EmployeeTerminatedNotification;
use App\Services\Employee\EmployeeService;
use Carbon\Carbon;
use Illuminate\Support\Facades\Notification;
beforeEach(function (): void {
seedRoles();
Notification::fake();
$this->hrManager = createUserWithRole('hr_manager');
$this->service = app(EmployeeService::class);
});
it('creates an employee with the provided data', function (): void {
$department = Department::factory()->create();
$position = Position::factory()->create();
$shift = Shift::factory()->create();
$employee = $this->service->create([
'employee_number' => 'EMP-10001',
'full_name' => 'John Doe',
'gender' => 'male',
'birth_date' => '1990-05-15',
'phone' => '+993 61 92 92 48',
'department_id' => $department->id,
'position_id' => $position->id,
'shift_id' => $shift->id,
'employment_status' => EmploymentStatus::Active,
'hire_date' => '2024-01-01',
]);
expect($employee)->toBeInstanceOf(Employee::class)
->and($employee->employee_number)->toBe('EMP-10001')
->and($employee->full_name)->toBe('John Doe')
->and($employee->employment_status)->toBe(EmploymentStatus::Active);
$this->assertDatabaseHas('employees', [
'employee_number' => 'EMP-10001',
'full_name' => 'John Doe',
]);
});
it('terminates an employee and notifies hr managers', function (): void {
$employee = Employee::factory()->active()->create();
$terminationDate = Carbon::parse('2025-06-30');
$result = $this->service->terminate($employee, $terminationDate);
expect($result->employment_status)->toBe(EmploymentStatus::Terminated)
->and($result->termination_date->toDateString())->toBe('2025-06-30');
Notification::assertSentTo(
[$this->hrManager],
EmployeeTerminatedNotification::class,
fn (EmployeeTerminatedNotification $notification): bool => $notification->employee->is($result),
);
});

View File

@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
use App\Enums\ApprovalStatus;
use App\Enums\VacationType;
use App\Models\Employee;
use App\Models\User;
use App\Models\Vacation;
use App\Notifications\VacationApprovedNotification;
use App\Notifications\VacationSubmittedNotification;
use App\Services\Vacation\VacationService;
use Illuminate\Support\Facades\Notification;
beforeEach(function (): void {
seedRoles();
Notification::fake();
$this->hrManager = createUserWithRole('hr_manager');
$this->approver = createUserWithRole('administrator');
$this->employee = Employee::factory()->create();
$this->service = app(VacationService::class);
});
it('submits a vacation request with calculated days and pending status', function (): void {
config(['hr.leave_calculation' => 'calendar']);
$vacation = $this->service->submit([
'employee_id' => $this->employee->id,
'type' => VacationType::Annual,
'start_date' => '2025-01-06',
'end_date' => '2025-01-10',
'return_date' => '2025-01-11',
'reason' => 'Family trip',
]);
expect($vacation)->toBeInstanceOf(Vacation::class)
->and($vacation->status)->toBe(ApprovalStatus::Pending)
->and($vacation->days)->toBe(5)
->and($vacation->employee_id)->toBe($this->employee->id);
Notification::assertSentTo(
[$this->hrManager],
VacationSubmittedNotification::class,
fn (VacationSubmittedNotification $notification): bool => $notification->vacation->is($vacation),
);
});
it('approves a vacation and notifies hr managers', function (): void {
$vacation = Vacation::factory()->pending()->create([
'employee_id' => $this->employee->id,
'start_date' => '2025-02-01',
'end_date' => '2025-02-05',
'days' => 5,
]);
$this->service->approve($vacation, $this->approver);
$vacation->refresh();
expect($vacation->status)->toBe(ApprovalStatus::Approved)
->and($vacation->approved_by)->toBe($this->approver->id)
->and($vacation->approved_at)->not->toBeNull();
Notification::assertSentTo(
[$this->hrManager],
VacationApprovedNotification::class,
fn (VacationApprovedNotification $notification): bool => $notification->vacation->is($vacation),
);
});
it('rejects a vacation without sending approval notifications', function (): void {
$vacation = Vacation::factory()->pending()->create([
'employee_id' => $this->employee->id,
'start_date' => '2025-03-01',
'end_date' => '2025-03-05',
'days' => 5,
]);
$this->service->reject($vacation, $this->approver);
$vacation->refresh();
expect($vacation->status)->toBe(ApprovalStatus::Rejected)
->and($vacation->approved_by)->toBe($this->approver->id)
->and($vacation->approved_at)->not->toBeNull();
Notification::assertNothingSent();
});