Files
SIRH/tests/Service/Notification/WorkingDayCalculatorTest.php
T
tristan 029a09dc09
Auto Tag Develop / tag (push) Successful in 17s
feat : notification de fin de contrat (veille ouvrée du dernier jour) (#35)
## Objectif
Prévenir automatiquement les administrateurs, sur le **dernier jour ouvré précédant la fin d'un contrat**, qu'un salarié arrive au terme de son emploi.

## Fonctionnement
- Commande quotidienne `app:contract:end-notifications` (à brancher sur le crontab prod, ~6h ; option `--date=YYYY-MM-DD` pour test/rattrapage).
- Cible **la dernière période de contrat** d'un employé (un changement de contrat enchaîné, ex. CDD→CDI, ne notifie pas).
- Notifie sur le **dernier jour ouvré strictement avant** `endDate` (inclusif). Week-ends **et fériés** sautés → une fin de contrat le lundi est signalée dès le vendredi. Le Lundi de Pentecôte reste un jour ouvré (cohérent avec le reste de l'app).
- Une notification par admin : message « Fin de {nature} de {Nom} le {date} », catégorie `Contrat`, lien `/employees/{id}`, sans acteur.
- **Idempotent** : déduplication par `(recipient, category, target, message)`.
- Front : la cloche (déjà admin-only) affiche proprement les notifs sans acteur.
- **Aucune migration** (réutilise la table `notifications`).

## Architecture
Logique pure isolée et testée : `WorkingDayCalculator` (week-end + férié) + `ContractEndNotificationPlanner` (fenêtre + message). Persistance dans `ContractEndNotificationService`, exposée par `ContractEndNotificationCommand`. Méthodes repo `findLatestPeriodsForAllEmployees` + `existsForRecipientCategoryTargetMessage`.

## Tests & vérification
- 11 tests unitaires ajoutés ; suite complète verte (264 tests, 564 assertions).
- Vérif e2e manuelle : run du vendredi → 6 notifs/1 contrat finissant le lundi (saut de week-end OK), relance idempotente (0), contenu BDD correct.

## Documentation
`doc/contract-end-notifications.md`, `doc/functional-rules.md` (§15), doc in-app (`documentation-content.ts`), `CLAUDE.md`.

## ⚠️ Tâche infra
Ajouter la ligne crontab prod : `0 6 * * * … bin/console app:contract:end-notifications`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-on: #35
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
2026-06-24 14:04:50 +00:00

63 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Service\Notification;
use App\Service\Notification\WorkingDayCalculator;
use App\Service\PublicHolidayServiceInterface;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
/**
* @internal
*/
final class WorkingDayCalculatorTest extends TestCase
{
public function testWeekdayIsWorkingDay(): void
{
// Mardi 08/07/2025
self::assertTrue($this->calculator()->isWorkingDay(new DateTimeImmutable('2025-07-08')));
}
public function testSaturdayAndSundayAreNotWorkingDays(): void
{
self::assertFalse($this->calculator()->isWorkingDay(new DateTimeImmutable('2025-07-12'))); // samedi
self::assertFalse($this->calculator()->isWorkingDay(new DateTimeImmutable('2025-07-13'))); // dimanche
}
public function testPublicHolidayIsNotWorkingDay(): void
{
self::assertFalse($this->calculator()->isWorkingDay(new DateTimeImmutable('2025-07-14'))); // lundi férié
}
public function testNextWorkingDayFromWeekdayIsTomorrow(): void
{
// Mardi 08/07 -> Mercredi 09/07
self::assertSame(
'2025-07-09',
$this->calculator()->nextWorkingDay(new DateTimeImmutable('2025-07-08'))->format('Y-m-d')
);
}
public function testNextWorkingDayFromFridaySkipsWeekend(): void
{
// Vendredi 11/07 -> lundi 14/07 est férié -> mardi 15/07
self::assertSame(
'2025-07-15',
$this->calculator()->nextWorkingDay(new DateTimeImmutable('2025-07-11'))->format('Y-m-d')
);
}
private function calculator(): WorkingDayCalculator
{
$holidays = $this->createStub(PublicHolidayServiceInterface::class);
$holidays->method('getHolidaysDayByYears')->willReturn([
// Lundi 14/07/2025 férié
'2025-07-14' => 'Fête nationale',
]);
return new WorkingDayCalculator($holidays);
}
}