Le super admin (table super_admins, master DB) ne pouvait pas se connecter via /api/login car ce firewall n'utilisait que le provider tenant. De même, le JWT n'était pas enrichi pour les super admins, l'endpoint /api/me/roles les rejetait, et le frontend redirigeait systématiquement vers /dashboard. Un chain provider (super_admin + tenant) résout l'authentification, le JwtPayloadEnricher et MyRolesProvider gèrent désormais les deux types d'utilisateurs, et le frontend redirige selon le rôle après login.
75 lines
2.4 KiB
PHP
75 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\SuperAdmin\Application\Command\CreateEstablishment;
|
|
|
|
use App\Shared\Domain\Clock;
|
|
use App\SuperAdmin\Application\Command\CreateEstablishment\CreateEstablishmentCommand;
|
|
use App\SuperAdmin\Application\Command\CreateEstablishment\CreateEstablishmentHandler;
|
|
use App\SuperAdmin\Infrastructure\Persistence\InMemory\InMemoryEstablishmentRepository;
|
|
use DateTimeImmutable;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class CreateEstablishmentHandlerTest extends TestCase
|
|
{
|
|
private const string SUPER_ADMIN_ID = '550e8400-e29b-41d4-a716-446655440001';
|
|
|
|
private InMemoryEstablishmentRepository $repository;
|
|
private CreateEstablishmentHandler $handler;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->repository = new InMemoryEstablishmentRepository();
|
|
|
|
$clock = new class implements Clock {
|
|
public function now(): DateTimeImmutable
|
|
{
|
|
return new DateTimeImmutable('2026-02-16 10:00:00');
|
|
}
|
|
};
|
|
|
|
$this->handler = new CreateEstablishmentHandler(
|
|
$this->repository,
|
|
$clock,
|
|
);
|
|
}
|
|
|
|
#[Test]
|
|
public function createsEstablishmentAndReturnsResult(): void
|
|
{
|
|
$command = new CreateEstablishmentCommand(
|
|
name: 'École Alpha',
|
|
subdomain: 'ecole-alpha',
|
|
adminEmail: 'admin@ecole-alpha.fr',
|
|
superAdminId: self::SUPER_ADMIN_ID,
|
|
);
|
|
|
|
$result = ($this->handler)($command);
|
|
|
|
self::assertNotEmpty($result->establishmentId);
|
|
self::assertNotEmpty($result->tenantId);
|
|
self::assertSame('École Alpha', $result->name);
|
|
self::assertSame('ecole-alpha', $result->subdomain);
|
|
self::assertStringStartsWith('classeo_tenant_', $result->databaseName);
|
|
}
|
|
|
|
#[Test]
|
|
public function savesEstablishmentToRepository(): void
|
|
{
|
|
$command = new CreateEstablishmentCommand(
|
|
name: 'École Beta',
|
|
subdomain: 'ecole-beta',
|
|
adminEmail: 'admin@ecole-beta.fr',
|
|
superAdminId: self::SUPER_ADMIN_ID,
|
|
);
|
|
|
|
$result = ($this->handler)($command);
|
|
|
|
$establishments = $this->repository->findAll();
|
|
self::assertCount(1, $establishments);
|
|
self::assertSame($result->establishmentId, (string) $establishments[0]->id);
|
|
}
|
|
}
|