fix(demo): invalidate paginated caches after seeding
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

Invalidate tenant read-model caches after generating demo data so seeded users, classes and assignments appear immediately in the UI.
This commit is contained in:
2026-03-10 22:58:06 +01:00
parent ee62beea8c
commit 0f3e57c6e6
2 changed files with 74 additions and 0 deletions

View File

@@ -4,8 +4,10 @@ declare(strict_types=1);
namespace App\Tests\Unit\Administration\Infrastructure\Service;
use App\Administration\Application\Dto\PaginatedResult;
use App\Administration\Application\Port\OfficialCalendarProvider;
use App\Administration\Application\Port\PasswordHasher;
use App\Administration\Application\Service\Cache\PaginatedQueryCache;
use App\Administration\Domain\Model\AcademicYear\PeriodType;
use App\Administration\Domain\Model\SchoolCalendar\CalendarEntry;
use App\Administration\Domain\Model\SchoolCalendar\CalendarEntryId;
@@ -34,6 +36,8 @@ use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
final class DemoDataGeneratorTest extends TestCase
{
@@ -50,6 +54,7 @@ final class DemoDataGeneratorTest extends TestCase
private InMemoryPeriodConfigurationRepository $periodConfigurationRepository;
private InMemorySchoolCalendarRepository $schoolCalendarRepository;
private GradingConfigurationRepository $gradingConfigurationRepository;
private PaginatedQueryCache $paginatedQueryCache;
private DemoDataGenerator $generator;
private TenantConfig $tenantConfig;
@@ -65,6 +70,7 @@ final class DemoDataGeneratorTest extends TestCase
$this->periodConfigurationRepository = new InMemoryPeriodConfigurationRepository();
$this->schoolCalendarRepository = new InMemorySchoolCalendarRepository();
$this->gradingConfigurationRepository = new InMemoryGradingConfigurationRepository();
$this->paginatedQueryCache = new PaginatedQueryCache(new TagAwareAdapter(new ArrayAdapter()));
$clock = new class implements Clock {
public function now(): DateTimeImmutable
@@ -136,6 +142,7 @@ final class DemoDataGeneratorTest extends TestCase
schoolCalendarRepository: $this->schoolCalendarRepository,
gradingConfigurationRepository: $this->gradingConfigurationRepository,
passwordHasher: $passwordHasher,
paginatedQueryCache: $this->paginatedQueryCache,
clock: $clock,
tenantContext: $tenantContext,
currentAcademicYearResolver: $currentAcademicYearResolver,
@@ -255,6 +262,56 @@ final class DemoDataGeneratorTest extends TestCase
self::assertCount(30, $result->accounts);
}
#[Test]
public function itInvalidatesPaginatedReadModelCacheAfterGeneration(): void
{
$loadCount = 0;
$this->paginatedQueryCache->getOrLoad(
'users',
self::TENANT_ID,
['page' => 1, 'limit' => 30, 'role' => null, 'statut' => null, 'search' => null],
static function () use (&$loadCount): PaginatedResult {
++$loadCount;
return new PaginatedResult(
items: [],
total: 0,
page: 1,
limit: 30,
);
},
);
self::assertSame(1, $loadCount);
$this->generator->generate(
tenantConfig: $this->tenantConfig,
password: 'DemoPassword123!',
schoolName: 'Établissement Démo',
zone: SchoolZone::B,
periodType: PeriodType::TRIMESTER,
);
$this->paginatedQueryCache->getOrLoad(
'users',
self::TENANT_ID,
['page' => 1, 'limit' => 30, 'role' => null, 'statut' => null, 'search' => null],
static function () use (&$loadCount): PaginatedResult {
++$loadCount;
return new PaginatedResult(
items: [],
total: 30,
page: 1,
limit: 30,
);
},
);
self::assertSame(2, $loadCount);
}
private function resolveCurrentAcademicYearId(): \App\Administration\Domain\Model\SchoolClass\AcademicYearId
{
$tenantContext = new TenantContext();