feat: Calculer automatiquement les moyennes après chaque saisie de notes
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

Les enseignants ont besoin de moyennes à jour immédiatement après la
publication ou modification des notes, sans attendre un batch nocturne.

Le système recalcule via Domain Events synchrones : statistiques
d'évaluation (min/max/moyenne/médiane), moyennes matières pondérées
(normalisation /20), et moyenne générale par élève. Les résultats sont
stockés dans des tables dénormalisées avec cache Redis (TTL 5 min).

Trois endpoints API exposent les données avec contrôle d'accès par rôle.
Une commande console permet le backfill des données historiques au
déploiement.
This commit is contained in:
2026-03-30 06:22:03 +02:00
parent b70d5ec2ad
commit e745cf326a
733 changed files with 113156 additions and 286 deletions

View File

@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Scolarite\Application\Command\DeleteAppreciationTemplate;
use App\Administration\Domain\Model\User\UserId;
use App\Scolarite\Application\Command\DeleteAppreciationTemplate\DeleteAppreciationTemplateCommand;
use App\Scolarite\Application\Command\DeleteAppreciationTemplate\DeleteAppreciationTemplateHandler;
use App\Scolarite\Domain\Exception\AppreciationTemplateNonTrouveeException;
use App\Scolarite\Domain\Exception\NonProprietaireDuModeleException;
use App\Scolarite\Domain\Model\Grade\AppreciationCategory;
use App\Scolarite\Domain\Model\Grade\AppreciationTemplate;
use App\Scolarite\Infrastructure\Persistence\InMemory\InMemoryAppreciationTemplateRepository;
use App\Shared\Domain\Clock;
use App\Shared\Domain\Tenant\TenantId;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class DeleteAppreciationTemplateHandlerTest extends TestCase
{
private const string TENANT_ID = '550e8400-e29b-41d4-a716-446655440001';
private const string TEACHER_ID = '550e8400-e29b-41d4-a716-446655440010';
private InMemoryAppreciationTemplateRepository $templateRepository;
private Clock $clock;
protected function setUp(): void
{
$this->templateRepository = new InMemoryAppreciationTemplateRepository();
$this->clock = new class implements Clock {
public function now(): DateTimeImmutable
{
return new DateTimeImmutable('2026-03-31 10:00:00');
}
};
}
#[Test]
public function itDeletesTemplate(): void
{
$template = $this->seedTemplate();
$handler = new DeleteAppreciationTemplateHandler($this->templateRepository);
$handler(new DeleteAppreciationTemplateCommand(
tenantId: self::TENANT_ID,
teacherId: self::TEACHER_ID,
templateId: (string) $template->id,
));
$found = $this->templateRepository->findById(
$template->id,
TenantId::fromString(self::TENANT_ID),
);
self::assertNull($found);
}
#[Test]
public function itThrowsWhenTemplateNotFound(): void
{
$handler = new DeleteAppreciationTemplateHandler($this->templateRepository);
$this->expectException(AppreciationTemplateNonTrouveeException::class);
$handler(new DeleteAppreciationTemplateCommand(
tenantId: self::TENANT_ID,
teacherId: self::TEACHER_ID,
templateId: '550e8400-e29b-41d4-a716-446655440099',
));
}
#[Test]
public function itThrowsWhenTeacherNotOwner(): void
{
$template = $this->seedTemplate();
$handler = new DeleteAppreciationTemplateHandler($this->templateRepository);
$this->expectException(NonProprietaireDuModeleException::class);
$handler(new DeleteAppreciationTemplateCommand(
tenantId: self::TENANT_ID,
teacherId: '550e8400-e29b-41d4-a716-446655440099',
templateId: (string) $template->id,
));
}
private function seedTemplate(): AppreciationTemplate
{
$template = AppreciationTemplate::creer(
tenantId: TenantId::fromString(self::TENANT_ID),
teacherId: UserId::fromString(self::TEACHER_ID),
title: 'Template test',
content: 'Contenu test',
category: AppreciationCategory::POSITIVE,
now: $this->clock->now(),
);
$this->templateRepository->save($template);
return $template;
}
}