// 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: 1, dietId: 2, }; describe("Household & profile settings (/foyer)", () => { beforeEach(() => { cy.intercept("GET", "**/auth/me", { statusCode: 200, body: authenticatedProfile }); cy.intercept("GET", "**/house/current", { statusCode: 200, body: { id: 1, name: "Chez Alice" }, }); cy.intercept("GET", "**/reference/diets", { statusCode: 200, body: [ { id: 1, name: "Omnivore" }, { id: 2, name: "Végétarien" }, ], }); cy.intercept("GET", "**/reference/allergies", { statusCode: 200, body: [ { id: 1, name: "Arachides" }, { id: 2, name: "Gluten" }, ], }); cy.intercept("GET", "**/profile/allergies", { statusCode: 200, body: [2] }); }); it("loads the current household name, regime and allergens", () => { cy.visit("/foyer"); cy.get("#houseName").should("have.value", "Chez Alice"); cy.get("#diet").should("have.value", "2"); cy.contains("label", "Gluten").find("input[type=checkbox]").should("be.checked"); cy.contains("label", "Arachides").find("input[type=checkbox]").should("not.be.checked"); }); it("saves the household name independently of the other sections", () => { cy.intercept("PATCH", "**/house/current", { statusCode: 200, body: { id: 1, name: "Chez les Martin" }, }).as("renameHouse"); cy.visit("/foyer"); cy.get("#houseName").clear(); cy.get("#houseName").type("Chez les Martin"); cy.get("#houseName") .closest("form") .within(() => cy.contains("button", "Enregistrer").click()); cy.wait("@renameHouse").its("request.body").should("deep.equal", { name: "Chez les Martin" }); cy.get("#houseName").closest("form").contains("Enregistré ✓").should("be.visible"); }); it("saves the regime independently of the other sections", () => { cy.intercept("PATCH", "**/profile/diet", { statusCode: 200, body: { ...authenticatedProfile, dietId: 1 }, }).as("updateDiet"); cy.visit("/foyer"); cy.get("#diet").select("Omnivore"); cy.get("#diet") .closest("form") .within(() => cy.contains("button", "Enregistrer").click()); cy.wait("@updateDiet").its("request.body").should("deep.equal", { dietId: 1 }); cy.get("#diet").closest("form").contains("Enregistré ✓").should("be.visible"); }); it("saves the allergen selection independently of the other sections", () => { cy.intercept("PATCH", "**/profile/allergies", { statusCode: 200, body: [1, 2] }).as( "updateAllergies", ); cy.visit("/foyer"); cy.contains("label", "Arachides").find("input[type=checkbox]").check(); cy.contains("fieldset", "Allergies").within(() => { cy.contains("button", "Enregistrer").click(); }); cy.wait("@updateAllergies") .its("request.body") .should("deep.equal", { allergyIds: [2, 1] }); }); });