import { ErrorCode } from "@batch-cooking/shared"; // Mocks the API via cy.intercept — see auth.cy.ts for the rationale. const authenticatedProfile = { id: 1, firstName: "Alice", lastName: "Martin", email: "alice@example.com", tokenVersion: 0, houseId: null, dietId: null, }; describe("Account settings (/parametres/compte)", () => { beforeEach(() => { cy.intercept("GET", "**/auth/me", { statusCode: 200, body: authenticatedProfile }); }); it("shows the signed-in profile's identity", () => { cy.visit("/parametres/compte"); cy.contains("Alice").should("be.visible"); cy.contains("Martin").should("be.visible"); cy.contains("alice@example.com").should("be.visible"); }); it("shows an error and keeps the session when the password is wrong", () => { cy.intercept("DELETE", "**/auth/me", { statusCode: 401, body: { code: ErrorCode.INVALID_CREDENTIALS, message: "Invalid password" }, }).as("deleteAccount"); cy.visit("/parametres/compte"); cy.contains("button", "Supprimer mon compte").click(); cy.get("#deleteAccountPassword").type("wrong-password"); cy.contains("button", "Confirmer la suppression").click(); cy.wait("@deleteAccount"); cy.contains("Email ou mot de passe incorrect").should("be.visible"); cy.url().should("include", "/parametres/compte"); }); it("deletes the account and returns to the login page", () => { cy.intercept("DELETE", "**/auth/me", { statusCode: 204 }).as("deleteAccount"); cy.visit("/parametres/compte"); cy.contains("button", "Supprimer mon compte").click(); cy.get("#deleteAccountPassword").type("correct-horse-battery-staple"); cy.contains("button", "Confirmer la suppression").click(); cy.wait("@deleteAccount") .its("request.body") .should("deep.equal", { password: "correct-horse-battery-staple" }); cy.url().should("include", "/login"); }); it("cancels the deletion without calling the API", () => { cy.intercept("DELETE", "**/auth/me").as("deleteAccount"); cy.visit("/parametres/compte"); cy.contains("button", "Supprimer mon compte").click(); cy.contains("button", "Annuler").click(); cy.contains("button", "Confirmer la suppression").should("not.exist"); cy.get("@deleteAccount.all").should("have.length", 0); }); });