// Mocks the admin API via cy.intercept — no live backend (see // .github/workflows/ci.yml); apps/api's Mocha suite covers // `GET /admin/api/contact` against a real database. 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 messages() { return [ { id: 2, type: "bug", message: "Le bouton Envoyer ne réagit pas sur la page planning.", pageUrl: "/", userAgent: "Mozilla/5.0 (Linux; Android 14) BatchCookingApp/0.2.1", appVersion: "0.2.1", createdAt: "2026-09-07T10:00:00.000Z", author: { id: 9, firstName: "Alice", lastName: "Martin", email: "alice@example.com" }, }, { id: 1, type: "suggestion", message: "Ajoutez un mode hors-ligne pour la liste de courses.", pageUrl: "/liste-de-courses", userAgent: null, appVersion: null, createdAt: "2026-09-06T08:30:00.000Z", author: null, }, ]; } describe("Admin contact messages (/admin/messages)", () => { beforeEach(() => { cy.viewport(1400, 1000); cy.intercept("GET", "**/admin/api/auth/me", { statusCode: 200, body: adminBody }); }); it("lists the messages read-only: sender or « Compte supprimé », type badge, message", () => { cy.intercept("GET", "**/admin/api/contact*", { statusCode: 200, body: messages() }).as( "getMessages", ); cy.visit("/admin/messages"); cy.wait("@getMessages"); cy.get(".messages-table tbody tr").should("have.length", 2); cy.contains(".messages-table tr", "page planning").should("contain.text", "alice@example.com"); cy.contains(".messages-table tr", "mode hors-ligne").should("contain.text", "Compte supprimé"); // No triage controls on the page. cy.get(".messages-table button").should("not.exist"); }); it("filters by type through the query param", () => { cy.intercept("GET", "**/admin/api/contact", { statusCode: 200, body: messages() }).as("all"); cy.intercept("GET", "**/admin/api/contact?type=suggestion", { statusCode: 200, body: [messages()[1]], }).as("filtered"); cy.visit("/admin/messages"); cy.wait("@all"); cy.get(".messages-filters select").select("Suggestion"); cy.wait("@filtered"); cy.get(".messages-table tbody tr").should("have.length", 1); cy.contains(".messages-table tr", "mode hors-ligne").should("be.visible"); }); });