base commit
This commit is contained in:
16
tests/Unit/ExampleTest.php
Normal file
16
tests/Unit/ExampleTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
54
tests/Unit/Services/LeaveDaysCalculatorTest.php
Normal file
54
tests/Unit/Services/LeaveDaysCalculatorTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Services\Leave\LeaveDaysCalculator;
|
||||
use Carbon\Carbon;
|
||||
|
||||
beforeEach(function (): void {
|
||||
$this->calculator = new LeaveDaysCalculator;
|
||||
});
|
||||
|
||||
it('calculates inclusive calendar days between two dates', function (): void {
|
||||
config(['hr.leave_calculation' => 'calendar']);
|
||||
|
||||
$days = $this->calculator->between(
|
||||
Carbon::parse('2025-01-06'),
|
||||
Carbon::parse('2025-01-12'),
|
||||
);
|
||||
|
||||
expect($days)->toBe(7);
|
||||
});
|
||||
|
||||
it('calculates business days excluding weekends', function (): void {
|
||||
config(['hr.leave_calculation' => 'business']);
|
||||
|
||||
$days = $this->calculator->between(
|
||||
Carbon::parse('2025-01-06'),
|
||||
Carbon::parse('2025-01-12'),
|
||||
);
|
||||
|
||||
expect($days)->toBe(5);
|
||||
});
|
||||
|
||||
it('returns zero when the end date is before the start date', function (): void {
|
||||
config(['hr.leave_calculation' => 'calendar']);
|
||||
|
||||
$days = $this->calculator->between(
|
||||
Carbon::parse('2025-01-10'),
|
||||
Carbon::parse('2025-01-06'),
|
||||
);
|
||||
|
||||
expect($days)->toBe(0);
|
||||
});
|
||||
|
||||
it('counts a single day when start and end are the same', function (): void {
|
||||
config(['hr.leave_calculation' => 'calendar']);
|
||||
|
||||
$days = $this->calculator->between(
|
||||
Carbon::parse('2025-01-06'),
|
||||
Carbon::parse('2025-01-06'),
|
||||
);
|
||||
|
||||
expect($days)->toBe(1);
|
||||
});
|
||||
86
tests/Unit/Services/VacationBalanceServiceTest.php
Normal file
86
tests/Unit/Services/VacationBalanceServiceTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Enums\VacationType;
|
||||
use App\Models\Employee;
|
||||
use App\Models\Vacation;
|
||||
use App\Services\Vacation\VacationBalanceService;
|
||||
|
||||
beforeEach(function (): void {
|
||||
config(['hr.annual_leave_days' => 24]);
|
||||
|
||||
$this->service = new VacationBalanceService;
|
||||
$this->employee = Employee::factory()->create();
|
||||
});
|
||||
|
||||
it('returns annual leave entitlement from configuration', function (): void {
|
||||
expect($this->service->entitlement())->toBe(24);
|
||||
});
|
||||
|
||||
it('sums approved annual vacation days for the given year', function (): void {
|
||||
Vacation::factory()->approved()->create([
|
||||
'employee_id' => $this->employee->id,
|
||||
'type' => VacationType::Annual,
|
||||
'start_date' => '2025-03-01',
|
||||
'end_date' => '2025-03-05',
|
||||
'days' => 5,
|
||||
]);
|
||||
|
||||
Vacation::factory()->approved()->create([
|
||||
'employee_id' => $this->employee->id,
|
||||
'type' => VacationType::Annual,
|
||||
'start_date' => '2025-06-01',
|
||||
'end_date' => '2025-06-03',
|
||||
'days' => 3,
|
||||
]);
|
||||
|
||||
Vacation::factory()->pending()->create([
|
||||
'employee_id' => $this->employee->id,
|
||||
'type' => VacationType::Annual,
|
||||
'start_date' => '2025-07-01',
|
||||
'end_date' => '2025-07-10',
|
||||
'days' => 10,
|
||||
]);
|
||||
|
||||
Vacation::factory()->approved()->create([
|
||||
'employee_id' => $this->employee->id,
|
||||
'type' => VacationType::Marriage,
|
||||
'start_date' => '2025-04-01',
|
||||
'end_date' => '2025-04-05',
|
||||
'days' => 5,
|
||||
]);
|
||||
|
||||
expect($this->service->takenAnnualDays($this->employee, 2025))->toBe(8);
|
||||
});
|
||||
|
||||
it('calculates remaining annual leave days', function (): void {
|
||||
$year = (int) now()->year;
|
||||
|
||||
Vacation::factory()->approved()->create([
|
||||
'employee_id' => $this->employee->id,
|
||||
'type' => VacationType::Annual,
|
||||
'start_date' => "{$year}-02-01",
|
||||
'end_date' => "{$year}-02-06",
|
||||
'days' => 6,
|
||||
]);
|
||||
|
||||
expect($this->service->remainingAnnualDays($this->employee))->toBe(18);
|
||||
});
|
||||
|
||||
it('ignores rejected annual vacations when calculating taken days', function (): void {
|
||||
$year = (int) now()->year;
|
||||
|
||||
Vacation::factory()->pending()->create([
|
||||
'employee_id' => $this->employee->id,
|
||||
'type' => VacationType::Annual,
|
||||
'status' => ApprovalStatus::Rejected,
|
||||
'start_date' => "{$year}-01-01",
|
||||
'end_date' => "{$year}-01-05",
|
||||
'days' => 5,
|
||||
]);
|
||||
|
||||
expect($this->service->takenAnnualDays($this->employee))->toBe(0)
|
||||
->and($this->service->remainingAnnualDays($this->employee))->toBe(24);
|
||||
});
|
||||
Reference in New Issue
Block a user