Files
Toiminnanohjaus/tests/Unit/Modules/Shared/FinnishHolidaysTest.php
T
petriandClaude Opus 5.5 b4f2f1cfaa Add the task calendar, holidays, workflow templates and customer removal
Task calendar (/jobs/calendar) replaces per-unit task Kanban columns
(K34): a two-week Gantt of tasks per person. Bars move, resize and
change person by dragging or through a keyboard dialog. Each task's
estimate is booked evenly over working days into task_bookings, and
what exceeds the daily maximum (jobs.daily_capacity_hours, 8 h) moves
to the next working day. Tasks get planned_from/planned_to on the form.

Holidays (/settings/holidays): Finnish public holidays calculated per
year, which the admin can take out of use, plus company days off.

Also includes the earlier uncommitted work: workflow templates with
adding tasks from a template, and removing customers no module refers to.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 18:13:11 +02:00

66 lines
2.8 KiB
PHP

<?php
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
use App\Modules\Shared\Domain\Exceptions\HolidayAlreadyExists;
use App\Modules\Shared\Domain\Exceptions\InvalidHolidayName;
use App\Modules\Shared\Domain\Exceptions\NotAHoliday;
use App\Modules\Shared\Domain\Services\FinnishHolidays;
use Tests\Fakes\InMemoryHolidayOverrides;
it('calculates Easter and Midsummer Eve', function (int $year, string $easter, string $midsummerEve) {
$holidays = FinnishHolidays::forYear($year);
expect(FinnishHolidays::easterSunday($year)->format('Y-m-d'))->toBe($easter)
->and(array_search('midsummer_eve', $holidays, true))->toBe($midsummerEve);
})->with([
[2025, '2025-04-20', '2025-06-20'],
[2026, '2026-04-05', '2026-06-19'],
[2027, '2027-03-28', '2027-06-25'],
]);
it('lists the holidays of a year in date order', function () {
expect(FinnishHolidays::forYear(2026))->toBe([
'2026-01-01' => 'new_years_day',
'2026-01-06' => 'epiphany',
'2026-04-03' => 'good_friday',
'2026-04-06' => 'easter_monday',
'2026-05-01' => 'may_day',
'2026-05-14' => 'ascension_day',
'2026-06-19' => 'midsummer_eve',
'2026-12-06' => 'independence_day',
'2026-12-24' => 'christmas_eve',
'2026-12-25' => 'christmas_day',
'2026-12-26' => 'st_stephens_day',
]);
});
it('takes holidays out of use and adds company days off', function () {
$calendar = new HolidayCalendar(new InMemoryHolidayOverrides);
$calendar->disable('2026-12-24');
$calendar->addCompanyDay('2026-12-23', ' Pikkujoulu ');
$december = $calendar->between('2026-12-20', '2026-12-31');
expect(array_map(fn ($holiday) => [$holiday->date, $holiday->key, $holiday->name, $holiday->active], $december))->toBe([
['2026-12-23', null, 'Pikkujoulu', true],
['2026-12-24', 'christmas_eve', null, false],
['2026-12-25', 'christmas_day', null, true],
['2026-12-26', 'st_stephens_day', null, true],
])->and($calendar->activeDatesBetween('2026-12-20', '2026-12-31'))->toBe(['2026-12-23', '2026-12-25', '2026-12-26']);
$calendar->enable('2026-12-24');
$calendar->removeCompanyDay('2026-12-23');
expect($calendar->activeDatesBetween('2026-12-20', '2026-12-31'))->toBe(['2026-12-24', '2026-12-25', '2026-12-26']);
});
it('rejects invalid holiday changes', function () {
$calendar = new HolidayCalendar(new InMemoryHolidayOverrides);
expect(fn () => $calendar->disable('2026-12-23'))->toThrow(NotAHoliday::class)
->and(fn () => $calendar->removeCompanyDay('2026-12-25'))->toThrow(NotAHoliday::class)
->and(fn () => $calendar->addCompanyDay('2026-12-25', 'Joulu'))->toThrow(HolidayAlreadyExists::class)
->and(fn () => $calendar->addCompanyDay('2026-12-23', ' '))->toThrow(InvalidHolidayName::class);
});