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>
62 lines
2.3 KiB
TypeScript
62 lines
2.3 KiB
TypeScript
// Mocks the admin API via cy.intercept — no live backend (apps/api's Mocha
|
|
// suite covers real /admin/* behaviour).
|
|
|
|
const adminBody = {
|
|
id: 1,
|
|
email: "ops@example.com",
|
|
name: "Ops",
|
|
createdAt: "2026-08-01T00:00:00.000Z",
|
|
lastLoginAt: "2026-08-28T09:00:00.000Z",
|
|
};
|
|
|
|
describe("Admin layout", () => {
|
|
it("redirects to /login when there is no admin session", () => {
|
|
cy.intercept("GET", "**/admin/auth/me", {
|
|
statusCode: 401,
|
|
body: { code: 4011, message: "no" },
|
|
});
|
|
cy.visit("/admin/monitoring");
|
|
cy.url().should("include", "/admin/login");
|
|
cy.contains("h1", "Administration").should("be.visible");
|
|
});
|
|
|
|
it("shows the sidebar and navigates between the sections", () => {
|
|
cy.intercept("GET", "**/admin/auth/me", { statusCode: 200, body: adminBody });
|
|
cy.visit("/admin");
|
|
|
|
cy.contains("h1", "Tableau de bord").should("be.visible");
|
|
cy.contains(".admin-sidebar__who", "Ops").should("be.visible");
|
|
|
|
cy.contains("nav a", "Monitoring").click();
|
|
cy.url().should("include", "/admin/monitoring");
|
|
cy.contains("h1", "Monitoring").should("be.visible");
|
|
cy.contains("nav a", "Monitoring").should("have.class", "active");
|
|
|
|
cy.contains("nav a", "Corrections").click();
|
|
cy.url().should("include", "/admin/corrections");
|
|
cy.contains("h1", "Corrections").should("be.visible");
|
|
|
|
cy.intercept("GET", "**/admin/catalog/placeholders*", { statusCode: 200, body: [] });
|
|
cy.contains("nav a", "Catalogue").click();
|
|
cy.url().should("include", "/admin/catalogue");
|
|
cy.contains("h1", "Ingrédients hors-catalogue").should("be.visible");
|
|
|
|
cy.contains("nav a", "Tableau de bord").click();
|
|
cy.url().should("eq", `${Cypress.config().baseUrl}/admin`);
|
|
});
|
|
|
|
it("logs out back to /login", () => {
|
|
cy.intercept("GET", "**/admin/auth/me", { statusCode: 200, body: adminBody });
|
|
cy.intercept("POST", "**/admin/auth/logout", { statusCode: 204 });
|
|
cy.visit("/admin");
|
|
|
|
// Wait until the guarded layout has actually mounted before acting.
|
|
cy.contains("h1", "Tableau de bord").should("be.visible");
|
|
|
|
// Logout clears the in-memory admin state, which is what bounces the
|
|
// guard to /login — no fresh `me` round-trip involved, so nothing to
|
|
// re-stub here.
|
|
cy.contains("button", "Se déconnecter").click();
|
|
cy.url().should("include", "/admin/login");
|
|
});
|
|
});
|