feat: Provisionner automatiquement un nouvel établissement
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:
@@ -9,6 +9,8 @@ use App\Administration\Domain\Model\Subject\SubjectId;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Application\Command\SaveAppreciation\SaveAppreciationCommand;
|
||||
use App\Scolarite\Application\Command\SaveAppreciation\SaveAppreciationHandler;
|
||||
use App\Scolarite\Application\Port\EnseignantAffectationChecker;
|
||||
use App\Scolarite\Application\Service\AutorisationSaisieNotesChecker;
|
||||
use App\Scolarite\Domain\Exception\AppreciationTropLongueException;
|
||||
use App\Scolarite\Domain\Exception\GradeNotFoundException;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDeLEvaluationException;
|
||||
@@ -22,6 +24,7 @@ use App\Scolarite\Domain\Model\Grade\GradeStatus;
|
||||
use App\Scolarite\Domain\Model\Grade\GradeValue;
|
||||
use App\Scolarite\Infrastructure\Persistence\InMemory\InMemoryEvaluationRepository;
|
||||
use App\Scolarite\Infrastructure\Persistence\InMemory\InMemoryGradeRepository;
|
||||
use App\Scolarite\Infrastructure\Persistence\InMemory\InMemoryTeacherReplacementRepository;
|
||||
use App\Shared\Domain\Clock;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
@@ -39,13 +42,18 @@ final class SaveAppreciationHandlerTest extends TestCase
|
||||
|
||||
private InMemoryEvaluationRepository $evaluationRepository;
|
||||
private InMemoryGradeRepository $gradeRepository;
|
||||
private InMemoryTeacherReplacementRepository $replacementRepository;
|
||||
private Clock $clock;
|
||||
private string $gradeId;
|
||||
|
||||
/** @var array<string, bool> */
|
||||
private array $affectationResults = [];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->evaluationRepository = new InMemoryEvaluationRepository();
|
||||
$this->gradeRepository = new InMemoryGradeRepository();
|
||||
$this->replacementRepository = new InMemoryTeacherReplacementRepository();
|
||||
$this->clock = new class implements Clock {
|
||||
public function now(): DateTimeImmutable
|
||||
{
|
||||
@@ -53,9 +61,16 @@ final class SaveAppreciationHandlerTest extends TestCase
|
||||
}
|
||||
};
|
||||
|
||||
$this->affectationResults = [];
|
||||
$this->affectationResults[self::TEACHER_ID] = true;
|
||||
$this->seedEvaluationAndGrade();
|
||||
}
|
||||
|
||||
public function isTeacherAffecte(string $teacherId): bool
|
||||
{
|
||||
return $this->affectationResults[$teacherId] ?? false;
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itSavesAppreciation(): void
|
||||
{
|
||||
@@ -144,10 +159,35 @@ final class SaveAppreciationHandlerTest extends TestCase
|
||||
return new SaveAppreciationHandler(
|
||||
$this->evaluationRepository,
|
||||
$this->gradeRepository,
|
||||
$this->createAutorisationChecker(),
|
||||
$this->clock,
|
||||
);
|
||||
}
|
||||
|
||||
private function createAutorisationChecker(): AutorisationSaisieNotesChecker
|
||||
{
|
||||
$test = $this;
|
||||
$affectationChecker = new class($test) implements EnseignantAffectationChecker {
|
||||
public function __construct(private readonly SaveAppreciationHandlerTest $test)
|
||||
{
|
||||
}
|
||||
|
||||
public function estAffecte(
|
||||
UserId $teacherId,
|
||||
ClassId $classId,
|
||||
SubjectId $subjectId,
|
||||
TenantId $tenantId,
|
||||
): bool {
|
||||
return $this->test->isTeacherAffecte((string) $teacherId);
|
||||
}
|
||||
};
|
||||
|
||||
return new AutorisationSaisieNotesChecker(
|
||||
$affectationChecker,
|
||||
$this->replacementRepository,
|
||||
);
|
||||
}
|
||||
|
||||
private function seedEvaluationAndGrade(): void
|
||||
{
|
||||
$tenantId = TenantId::fromString(self::TENANT_ID);
|
||||
|
||||
Reference in New Issue
Block a user