fix(demo): invalidate paginated caches after seeding
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user