// Mocks the API via cy.intercept — see auth.cy.ts for the rationale (no // live backend in this CI job; apps/api's own Mocha/Cucumber suites cover // real API behavior against a real database). const signupResponse = { id: 1, firstName: "Alice", lastName: "Martin", email: "alice@example.com", tokenVersion: 0, houseId: 1, dietId: null, }; describe("Onboarding wizard (household → regime → allergens)", () => { it("walks through all three steps after signup and lands on the home", () => { cy.intercept("GET", "**/auth/me", { statusCode: 401 }); cy.intercept("POST", "**/auth/signup", { statusCode: 201, body: signupResponse }).as("signup"); cy.intercept("GET", "**/house/current", { statusCode: 200, body: { id: 1, name: "Foyer de Alice" }, }); cy.intercept("PATCH", "**/house/current", { statusCode: 200, body: { id: 1, name: "Chez Alice" }, }).as("renameHouse"); cy.intercept("GET", "**/reference/diets", { statusCode: 200, body: [ { id: 1, name: "Omnivore" }, { id: 2, name: "Végétarien" }, ], }); cy.intercept("PATCH", "**/profile/diet", { statusCode: 200, body: { ...signupResponse, dietId: 2 }, }).as("updateDiet"); cy.intercept("GET", "**/reference/allergies", { statusCode: 200, body: [ { id: 1, name: "Arachides", kind: "ALLERGY" }, { id: 2, name: "Gluten", kind: "INTOLERANCE" }, ], }); cy.intercept("PATCH", "**/profile/allergies", { statusCode: 200, body: [1] }).as( "updateAllergies", ); cy.intercept("GET", "**/planning/current", { statusCode: 200, body: null }); cy.visit("/signup"); cy.get("#firstName").type("Alice"); cy.get("#lastName").type("Martin"); cy.get("#email").type("alice@example.com"); cy.get("#password").type("correct-horse-battery-staple"); cy.contains("button", "Créer mon profil").click(); cy.wait("@signup"); // Step 1/3 — household name, prefilled with the auto-generated default. cy.url().should("include", "/onboarding/foyer"); cy.contains("Étape 1 sur 3").should("be.visible"); cy.get("#houseName").should("have.value", "Foyer de Alice"); cy.get("#houseName").clear(); cy.get("#houseName").type("Chez Alice"); cy.contains("button", "Continuer").click(); cy.wait("@renameHouse").its("request.body").should("deep.equal", { name: "Chez Alice" }); // Step 2/3 — dietary regime. cy.url().should("include", "/onboarding/regime"); cy.contains("Étape 2 sur 3").should("be.visible"); cy.get("#diet").select("Végétarien"); cy.contains("button", "Continuer").click(); cy.wait("@updateDiet").its("request.body").should("deep.equal", { dietId: 2 }); // Step 3/3 — allergens (grouped into two lists) and intolerances, then finish. cy.url().should("include", "/onboarding/allergenes"); cy.contains("Étape 3 sur 3").should("be.visible"); cy.contains("legend", "Allergies").should("be.visible"); cy.contains("legend", "Intolérances").should("be.visible"); cy.contains("label", "Arachides").find("input[type=checkbox]").check(); cy.contains("button", "Terminer").click(); cy.wait("@updateAllergies") .its("request.body") .should("deep.equal", { allergyIds: [1] }); cy.url().should("eq", `${Cypress.config().baseUrl}/`); cy.contains("h1", "Planning de la semaine").should("be.visible"); }); it("lets every step be skipped without changing anything", () => { cy.intercept("GET", "**/auth/me", { statusCode: 401 }); cy.intercept("POST", "**/auth/signup", { statusCode: 201, body: signupResponse }); cy.intercept("GET", "**/house/current", { statusCode: 200, body: { id: 1, name: "Foyer de Alice" }, }); cy.intercept("PATCH", "**/house/current", { statusCode: 200, body: { id: 1, name: "Foyer de Alice" }, }).as("renameHouse"); cy.intercept("GET", "**/reference/diets", { statusCode: 200, body: [] }); cy.intercept("PATCH", "**/profile/diet", { statusCode: 200, body: signupResponse }).as( "updateDiet", ); cy.intercept("GET", "**/reference/allergies", { statusCode: 200, body: [] }); cy.intercept("PATCH", "**/profile/allergies", { statusCode: 200, body: [] }).as( "updateAllergies", ); cy.intercept("GET", "**/planning/current", { statusCode: 200, body: null }); cy.visit("/signup"); cy.get("#firstName").type("Alice"); cy.get("#lastName").type("Martin"); cy.get("#email").type("alice@example.com"); cy.get("#password").type("correct-horse-battery-staple"); cy.contains("button", "Créer mon profil").click(); cy.url().should("include", "/onboarding/foyer"); cy.contains("button", "Continuer").click(); cy.wait("@renameHouse").its("request.body").should("deep.equal", { name: "Foyer de Alice" }); cy.url().should("include", "/onboarding/regime"); cy.contains("button", "Continuer").click(); cy.wait("@updateDiet").its("request.body").should("deep.equal", { dietId: null }); cy.url().should("include", "/onboarding/allergenes"); cy.contains("button", "Terminer").click(); cy.wait("@updateAllergies").its("request.body").should("deep.equal", { allergyIds: [] }); cy.url().should("eq", `${Cypress.config().baseUrl}/`); }); });