feat: Provisionner automatiquement un nouvel établissement
Some checks failed
CI / Backend Tests (push) Has been cancelled
CI / Frontend Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Naming Conventions (push) Has been cancelled
CI / Build Check (push) Has been cancelled

Lorsqu'un super-admin crée un établissement via l'interface, le système
doit automatiquement créer la base tenant, exécuter les migrations,
créer le premier utilisateur admin et envoyer l'invitation — le tout
de manière asynchrone pour ne pas bloquer la réponse HTTP.

Ce mécanisme rend chaque établissement opérationnel dès sa création
sans intervention manuelle sur l'infrastructure.
This commit is contained in:
2026-04-08 13:55:41 +02:00
parent bec211ebf0
commit 3575d095a1
106 changed files with 9586 additions and 380 deletions

View File

@@ -10,8 +10,11 @@ use App\Administration\Domain\Model\SchoolCalendar\CalendarEntryType;
use App\Administration\Domain\Model\SchoolCalendar\SchoolCalendar;
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
use App\Administration\Infrastructure\Persistence\InMemory\InMemorySchoolCalendarRepository;
use App\Scolarite\Application\Port\HomeworkRulesChecker;
use App\Scolarite\Application\Port\HomeworkRulesCheckResult;
use App\Scolarite\Application\Query\GetBlockedDates\GetBlockedDatesHandler;
use App\Scolarite\Application\Query\GetBlockedDates\GetBlockedDatesQuery;
use App\Shared\Domain\Clock;
use App\Shared\Domain\Tenant\TenantId;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
@@ -28,7 +31,29 @@ final class GetBlockedDatesHandlerTest extends TestCase
protected function setUp(): void
{
$this->calendarRepository = new InMemorySchoolCalendarRepository();
$this->handler = new GetBlockedDatesHandler($this->calendarRepository);
$rulesChecker = new class implements HomeworkRulesChecker {
public function verifier(
TenantId $tenantId,
DateTimeImmutable $dueDate,
DateTimeImmutable $creationDate,
): HomeworkRulesCheckResult {
return HomeworkRulesCheckResult::ok();
}
};
$clock = new class implements Clock {
public function now(): DateTimeImmutable
{
return new DateTimeImmutable('2026-03-01 10:00:00');
}
};
$this->handler = new GetBlockedDatesHandler(
$this->calendarRepository,
$rulesChecker,
$clock,
);
}
#[Test]
@@ -110,6 +135,93 @@ final class GetBlockedDatesHandlerTest extends TestCase
self::assertCount(5, $vacations);
}
#[Test]
public function returnsRuleHardBlockedDates(): void
{
$rulesChecker = new class implements HomeworkRulesChecker {
public function verifier(
TenantId $tenantId,
DateTimeImmutable $dueDate,
DateTimeImmutable $creationDate,
): HomeworkRulesCheckResult {
// Block Tuesday March 3
if ($dueDate->format('Y-m-d') === '2026-03-03') {
return new HomeworkRulesCheckResult(
warnings: [new \App\Scolarite\Application\Port\RuleWarning('minimum_delay', 'Délai minimum non respecté')],
bloquant: true,
);
}
return HomeworkRulesCheckResult::ok();
}
};
$clock = new class implements Clock {
public function now(): DateTimeImmutable
{
return new DateTimeImmutable('2026-03-01 10:00:00');
}
};
$handler = new GetBlockedDatesHandler($this->calendarRepository, $rulesChecker, $clock);
$result = ($handler)(new GetBlockedDatesQuery(
tenantId: self::TENANT_ID,
academicYearId: self::ACADEMIC_YEAR_ID,
startDate: '2026-03-02',
endDate: '2026-03-06',
));
$ruleBlocked = array_filter($result, static fn ($d) => $d->type === 'rule_hard');
self::assertCount(1, $ruleBlocked);
$blocked = array_values($ruleBlocked)[0];
self::assertSame('2026-03-03', $blocked->date);
self::assertSame('Délai minimum non respecté', $blocked->reason);
}
#[Test]
public function returnsRuleSoftWarningDates(): void
{
$rulesChecker = new class implements HomeworkRulesChecker {
public function verifier(
TenantId $tenantId,
DateTimeImmutable $dueDate,
DateTimeImmutable $creationDate,
): HomeworkRulesCheckResult {
if ($dueDate->format('Y-m-d') === '2026-03-04') {
return new HomeworkRulesCheckResult(
warnings: [new \App\Scolarite\Application\Port\RuleWarning('no_monday_after', 'Devoirs pour lundi déconseillés')],
bloquant: false,
);
}
return HomeworkRulesCheckResult::ok();
}
};
$clock = new class implements Clock {
public function now(): DateTimeImmutable
{
return new DateTimeImmutable('2026-03-01 10:00:00');
}
};
$handler = new GetBlockedDatesHandler($this->calendarRepository, $rulesChecker, $clock);
$result = ($handler)(new GetBlockedDatesQuery(
tenantId: self::TENANT_ID,
academicYearId: self::ACADEMIC_YEAR_ID,
startDate: '2026-03-02',
endDate: '2026-03-06',
));
$ruleSoft = array_filter($result, static fn ($d) => $d->type === 'rule_soft');
self::assertCount(1, $ruleSoft);
$soft = array_values($ruleSoft)[0];
self::assertSame('2026-03-04', $soft->date);
self::assertSame('rule_soft', $soft->type);
}
private function createCalendarWithHoliday(DateTimeImmutable $date, string $label): SchoolCalendar
{
$tenantId = TenantId::fromString(self::TENANT_ID);