Files
Classeo/backend/tests/Unit/Scolarite/Application/Command/CreateAppreciationTemplate/CreateAppreciationTemplateHandlerTest.php
Mathias STRASSER b7dc27f2a5
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
feat: Calculer automatiquement les moyennes après chaque saisie de notes
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.
2026-04-04 02:25:00 +02:00

94 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Unit\Scolarite\Application\Command\CreateAppreciationTemplate;
use App\Scolarite\Application\Command\CreateAppreciationTemplate\CreateAppreciationTemplateCommand;
use App\Scolarite\Application\Command\CreateAppreciationTemplate\CreateAppreciationTemplateHandler;
use App\Scolarite\Domain\Model\Grade\AppreciationCategory;
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 CreateAppreciationTemplateHandlerTest 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 itCreatesTemplate(): void
{
$handler = new CreateAppreciationTemplateHandler($this->templateRepository, $this->clock);
$template = $handler(new CreateAppreciationTemplateCommand(
tenantId: self::TENANT_ID,
teacherId: self::TEACHER_ID,
title: 'Très bon travail',
content: 'Très bon travail, continuez ainsi !',
category: 'positive',
));
self::assertSame('Très bon travail', $template->title);
self::assertSame('Très bon travail, continuez ainsi !', $template->content);
self::assertSame(AppreciationCategory::POSITIVE, $template->category);
self::assertSame(0, $template->usageCount);
}
#[Test]
public function itPersistsTemplate(): void
{
$handler = new CreateAppreciationTemplateHandler($this->templateRepository, $this->clock);
$template = $handler(new CreateAppreciationTemplateCommand(
tenantId: self::TENANT_ID,
teacherId: self::TEACHER_ID,
title: 'Test',
content: 'Contenu test',
category: null,
));
$found = $this->templateRepository->findById(
$template->id,
TenantId::fromString(self::TENANT_ID),
);
self::assertNotNull($found);
self::assertSame('Test', $found->title);
self::assertNull($found->category);
}
#[Test]
public function itCreatesTemplateWithNullCategory(): void
{
$handler = new CreateAppreciationTemplateHandler($this->templateRepository, $this->clock);
$template = $handler(new CreateAppreciationTemplateCommand(
tenantId: self::TENANT_ID,
teacherId: self::TEACHER_ID,
title: 'Sans catégorie',
content: 'Contenu',
category: null,
));
self::assertNull($template->category);
}
}