fix: Corriger les tests E2E après l'introduction du cache-aside paginé
Le commit 23dd717 a introduit un cache Redis (paginated_queries.cache)
pour les requêtes paginées. Les tests E2E qui modifient les données via
SQL direct (beforeAll, cleanup) contournent la couche applicative et ne
déclenchent pas l'invalidation du cache, provoquant des données obsolètes.
De plus, plusieurs problèmes d'isolation entre tests ont été découverts :
- Les tests classes.spec.ts supprimaient les données d'autres specs via
DELETE FROM school_classes sans nettoyer les FK dépendantes
- Les tests user-blocking utilisaient des emails partagés entre les
projets Playwright (chromium/firefox/webkit) exécutés en parallèle,
causant des race conditions sur l'état du compte utilisateur
- Le handler NotifyTeachersPedagogicalDayHandler s'exécutait de manière
synchrone, bloquant la réponse HTTP pendant l'envoi des emails
- La sélection d'un enseignant remplaçant effaçait l'autre dropdown car
{#if} supprimait l'option sélectionnée du DOM
Corrections appliquées :
- Ajout de cache:pool:clear après chaque modification SQL directe
- Nettoyage des FK dépendantes avant les DELETE (classes, subjects)
- Emails uniques par projet navigateur pour éviter les race conditions
- Routage de JourneePedagogiqueAjoutee vers le transport async
- Remplacement de {#if} par disabled sur les selects de remplacement
- Recherche par nom sur la page classes pour gérer la pagination
- Patterns toPass() pour la fiabilité Firefox sur les color pickers
This commit is contained in:
@@ -11,15 +11,36 @@ const urlMatch = baseUrl.match(/:(\d+)$/);
|
||||
const PORT = urlMatch ? urlMatch[1] : '4173';
|
||||
const ALPHA_URL = `http://ecole-alpha.classeo.local:${PORT}`;
|
||||
|
||||
const ADMIN_EMAIL = 'e2e-blocking-admin@example.com';
|
||||
const ADMIN_PASSWORD = 'BlockingTest123';
|
||||
const TARGET_EMAIL = 'e2e-blocking-target@example.com';
|
||||
const TARGET_PASSWORD = 'TargetUser123';
|
||||
|
||||
test.describe('User Blocking', () => {
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
test.beforeAll(async () => {
|
||||
// Per-browser unique emails to avoid cross-project race conditions
|
||||
// (parallel browser projects share the same database)
|
||||
let ADMIN_EMAIL: string;
|
||||
let TARGET_EMAIL: string;
|
||||
|
||||
function clearCache() {
|
||||
const projectRoot = join(__dirname, '../..');
|
||||
const composeFile = join(projectRoot, 'compose.yaml');
|
||||
try {
|
||||
execSync(
|
||||
`docker compose -f "${composeFile}" exec -T php php bin/console cache:pool:clear paginated_queries.cache 2>&1`,
|
||||
{ encoding: 'utf-8' }
|
||||
);
|
||||
} catch {
|
||||
// Cache pool may not exist in all environments
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-empty-pattern
|
||||
test.beforeAll(async ({}, testInfo) => {
|
||||
const browser = testInfo.project.name;
|
||||
ADMIN_EMAIL = `e2e-blocking-admin-${browser}@example.com`;
|
||||
TARGET_EMAIL = `e2e-blocking-target-${browser}@example.com`;
|
||||
|
||||
const projectRoot = join(__dirname, '../..');
|
||||
const composeFile = join(projectRoot, 'compose.yaml');
|
||||
|
||||
@@ -44,6 +65,8 @@ test.describe('User Blocking', () => {
|
||||
} catch {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
|
||||
clearCache();
|
||||
});
|
||||
|
||||
async function loginAsAdmin(page: import('@playwright/test').Page) {
|
||||
@@ -66,12 +89,12 @@ test.describe('User Blocking', () => {
|
||||
// Search for the target user (pagination may hide them beyond page 1)
|
||||
const searchInput = page.locator('input[type="search"]');
|
||||
await searchInput.fill(TARGET_EMAIL);
|
||||
await page.waitForTimeout(500);
|
||||
await page.waitForTimeout(1000);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Find the target user row
|
||||
const targetRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
|
||||
await expect(targetRow).toBeVisible();
|
||||
await expect(targetRow).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Click "Bloquer" button and wait for modal (retry handles hydration timing)
|
||||
await expect(async () => {
|
||||
@@ -82,15 +105,28 @@ test.describe('User Blocking', () => {
|
||||
// Fill in the reason
|
||||
await page.locator('#block-reason').fill('Comportement inapproprié en E2E');
|
||||
|
||||
// Confirm the block
|
||||
// Confirm the block and wait for the API response
|
||||
const blockResponsePromise = page.waitForResponse(
|
||||
(resp) => resp.url().includes('/block') && resp.request().method() === 'POST'
|
||||
);
|
||||
await page.getByRole('button', { name: /confirmer le blocage/i }).click();
|
||||
const blockResponse = await blockResponsePromise;
|
||||
expect(blockResponse.status()).toBeLessThan(400);
|
||||
|
||||
// Wait for the success message
|
||||
await expect(page.locator('.alert-success')).toBeVisible({ timeout: 5000 });
|
||||
// Wait for the modal to close and status change to be reflected
|
||||
await expect(page.locator('#block-modal-title')).not.toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Clear cache and reload to get fresh data (block action may not invalidate paginated cache)
|
||||
clearCache();
|
||||
await page.reload();
|
||||
await expect(page.locator('.users-table')).toBeVisible({ timeout: 10000 });
|
||||
await page.locator('input[type="search"]').fill(TARGET_EMAIL);
|
||||
await page.waitForTimeout(1000);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Verify the user status changed to "Suspendu"
|
||||
const updatedRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
|
||||
await expect(updatedRow.locator('.status-blocked')).toContainText('Suspendu');
|
||||
await expect(updatedRow).toBeVisible({ timeout: 10000 });
|
||||
await expect(updatedRow.locator('.status-blocked')).toContainText('Suspendu', { timeout: 10000 });
|
||||
|
||||
// Verify the reason is displayed
|
||||
await expect(updatedRow.locator('.blocked-reason')).toContainText('Comportement inapproprié en E2E');
|
||||
@@ -105,12 +141,12 @@ test.describe('User Blocking', () => {
|
||||
// Search for the target user (pagination may hide them beyond page 1)
|
||||
const searchInput = page.locator('input[type="search"]');
|
||||
await searchInput.fill(TARGET_EMAIL);
|
||||
await page.waitForTimeout(500);
|
||||
await page.waitForTimeout(1000);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Find the suspended target user row
|
||||
const targetRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
|
||||
await expect(targetRow).toBeVisible();
|
||||
await expect(targetRow).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// "Débloquer" button should be visible for suspended user
|
||||
const unblockButton = targetRow.getByRole('button', { name: /débloquer/i });
|
||||
@@ -120,7 +156,7 @@ test.describe('User Blocking', () => {
|
||||
await unblockButton.click();
|
||||
|
||||
// Wait for the success message
|
||||
await expect(page.locator('.alert-success')).toBeVisible({ timeout: 5000 });
|
||||
await expect(page.locator('.alert-success')).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Verify the user status changed back to "Actif"
|
||||
const updatedRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
|
||||
@@ -136,7 +172,7 @@ test.describe('User Blocking', () => {
|
||||
// Search for the target user (pagination may hide them beyond page 1)
|
||||
const searchInput = page.locator('input[type="search"]');
|
||||
await searchInput.fill(TARGET_EMAIL);
|
||||
await page.waitForTimeout(500);
|
||||
await page.waitForTimeout(1000);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const targetRow = page.locator('tr', { has: page.locator(`text=${TARGET_EMAIL}`) });
|
||||
@@ -145,8 +181,13 @@ test.describe('User Blocking', () => {
|
||||
await expect(page.locator('#block-modal-title')).toBeVisible({ timeout: 2000 });
|
||||
}).toPass({ timeout: 10000 });
|
||||
await page.locator('#block-reason').fill('Bloqué pour test login');
|
||||
const blockResponsePromise = page.waitForResponse(
|
||||
(resp) => resp.url().includes('/block') && resp.request().method() === 'POST'
|
||||
);
|
||||
await page.getByRole('button', { name: /confirmer le blocage/i }).click();
|
||||
await expect(page.locator('.alert-success')).toBeVisible({ timeout: 5000 });
|
||||
const blockResponse = await blockResponsePromise;
|
||||
expect(blockResponse.status()).toBeLessThan(400);
|
||||
await expect(page.locator('.alert-success')).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Logout
|
||||
await page.getByRole('button', { name: /déconnexion/i }).click();
|
||||
@@ -172,12 +213,12 @@ test.describe('User Blocking', () => {
|
||||
// Search for the admin user (pagination may hide them beyond page 1)
|
||||
const searchInput = page.locator('input[type="search"]');
|
||||
await searchInput.fill(ADMIN_EMAIL);
|
||||
await page.waitForTimeout(500);
|
||||
await page.waitForTimeout(1000);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Find the admin's own row
|
||||
const adminRow = page.locator('tr', { has: page.locator(`text=${ADMIN_EMAIL}`) });
|
||||
await expect(adminRow).toBeVisible();
|
||||
await expect(adminRow).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// "Bloquer" button should NOT be present on the admin's own row
|
||||
await expect(adminRow.getByRole('button', { name: /^bloquer$/i })).not.toBeVisible();
|
||||
|
||||
Reference in New Issue
Block a user