L'admin etait une 2e app front Vite independante (apps/admin-web, port 5174,
Dockerfile nginx, service compose dedie, job CI propre) non demandee. Toute
l'UI passe dans apps/web sous le prefixe /admin ; seul le frontend est
fusionne, l'authentification admin reste entierement separee.
Front (apps/web/src) :
- pages -> pages/admin/{login,dashboard,monitoring,corrections,catalog}/,
layout -> layouts/AdminLayout.tsx, contexte + garde -> features/admin/.
- client API -> api/admin-client.ts : classe AdminApiError (evite la
collision avec ApiError), lit VITE_API_URL (plus de VITE_ADMIN_API_URL).
- routes /admin/* dans App.tsx, enveloppees d'AdminAuthProvider +
RequireAdmin -> le probe GET /admin/auth/me ne tourne que sous /admin.
- reutilise l'i18n, lib/zod-errors, services/error-message.service et le
theme SCSS de apps/web ; bloc i18n admin.* fusionne dans la locale fr
(les cles errors etaient deja toutes presentes).
- corrige une race dans CatalogPage (reponse d'un onglet precedent qui
ecrasait l'onglet courant, exposee par le double-mount StrictMode) via
un ref requestSeq.
Auth admin inchangee : table AdminUser, cookie admin_session,
ADMIN_JWT_SECRET, script create-admin.ts.
Infra :
- docker-compose : service admin-web + ADMIN_WEB_PORT supprimes (l'app
`app` sert deja le front construit).
- ADMIN_CORS_ORIGIN retire (meme origine) : env.ts, app.ts, .env.example.
- job CI "Run admin-web E2E tests" supprime ; les specs admin-* tournent
dans le job web (apps/web/cypress/e2e/admin-*.{cy.ts,feature}).
- apps/api/.env.example : ajout ADMIN_JWT_SECRET / ADMIN_INITIAL_*.
- recharts ajoute a apps/web ; pnpm-lock regenere.
- specs/backend-architecture.md : section admin mise a jour.
Verifie : biome + tsc -b (web/api) + pnpm -r build verts ; Cypress web
102/103 (l'unique echec est le flake pre-existant recipe-form.feature
"Preloads ..." de clipping headless, sans rapport) ; 16/16 specs admin ;
45/45 composants.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
// Mocks the admin API via cy.intercept — no live backend.
|
|
|
|
const adminBody = {
|
|
id: 1,
|
|
email: "ops@example.com",
|
|
name: "Ops",
|
|
createdAt: "2026-08-01T00:00:00.000Z",
|
|
lastLoginAt: "2026-08-28T09:00:00.000Z",
|
|
};
|
|
|
|
function monitoringFixture() {
|
|
return {
|
|
generatedAt: "2026-08-28T09:15:00.000Z",
|
|
services: [
|
|
{
|
|
key: "postgres",
|
|
status: "up",
|
|
latencyMs: 3.2,
|
|
detail: null,
|
|
checkedAt: "2026-08-28T09:15:00.000Z",
|
|
},
|
|
{
|
|
key: "api",
|
|
status: "up",
|
|
latencyMs: 0,
|
|
detail: "uptime 3 h 12 min · RSS 120 Mo",
|
|
checkedAt: "2026-08-28T09:15:00.000Z",
|
|
},
|
|
{
|
|
key: "intent-service",
|
|
status: "down",
|
|
latencyMs: null,
|
|
detail: "fetch failed",
|
|
checkedAt: "2026-08-28T09:15:00.000Z",
|
|
},
|
|
{
|
|
key: "tech-step-llm-worker",
|
|
status: "degraded",
|
|
latencyMs: null,
|
|
detail: "dernier battement il y a 9 j",
|
|
checkedAt: "2026-08-28T09:15:00.000Z",
|
|
lastRunAt: "2026-08-19T03:00:00.000Z",
|
|
lastResult: { job: "audit-low-confidence", ok: true, counts: { suggestions: 2 } },
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
describe("Admin monitoring", () => {
|
|
beforeEach(() => {
|
|
cy.viewport(1400, 900);
|
|
cy.intercept("GET", "**/admin/auth/me", { statusCode: 200, body: adminBody });
|
|
});
|
|
|
|
it("renders one card per service with its status and details", () => {
|
|
cy.intercept("GET", "http://localhost:3000/admin/monitoring", {
|
|
statusCode: 200,
|
|
body: monitoringFixture(),
|
|
}).as("getMonitoring");
|
|
cy.visit("/admin/monitoring");
|
|
cy.wait("@getMonitoring");
|
|
|
|
cy.get(".monitoring-card").should("have.length", 4);
|
|
|
|
cy.contains(".monitoring-card", "Base de données")
|
|
.should("have.class", "monitoring-card--up")
|
|
.and("contain.text", "3.2 ms");
|
|
cy.contains(".monitoring-card", "Service NLP (spaCy)")
|
|
.should("have.class", "monitoring-card--down")
|
|
.and("contain.text", "Hors service");
|
|
cy.contains(".monitoring-card", "Worker LLM")
|
|
.should("have.class", "monitoring-card--degraded")
|
|
.and("contain.text", "audit-low-confidence");
|
|
});
|
|
|
|
it("shows an error state when the request fails", () => {
|
|
cy.intercept("GET", "http://localhost:3000/admin/monitoring", {
|
|
statusCode: 500,
|
|
body: { code: 5000, message: "x" },
|
|
});
|
|
cy.visit("/admin/monitoring");
|
|
cy.contains("Impossible de charger").should("be.visible");
|
|
});
|
|
});
|