import { Given, Then } from "@badeball/cypress-cucumber-preprocessor"; // The page also loads the reference ingredient list + the profile's // disliked-ingredients selection for `DislikedIngredientsField` — added // alongside diets/allergies in the same `Promise.all` (see // PreferencesPage.tsx), so both need mocking here too or that `Promise.all` // rejects and the whole page renders its error state instead of the form, // taking `#diet`/the allergy checkboxes down with it. Given("the dietary preferences reference data is ready", () => { cy.intercept("GET", "**/reference/diets", { statusCode: 200, body: [ { id: 1, key: "omnivore" }, { id: 2, key: "vegetarian" }, ], }); cy.intercept("GET", "**/reference/allergies", { statusCode: 200, body: [ { id: 1, key: "peanuts", kind: "ALLERGY" }, { id: 2, key: "gluten", kind: "INTOLERANCE" }, ], }); cy.intercept("GET", "**/profile/allergies", { statusCode: 200, body: [2] }); cy.intercept("GET", "**/reference/ingredients", { statusCode: 200, body: [] }); cy.intercept("GET", "**/profile/disliked-ingredients", { statusCode: 200, body: [] }); }); Given("selecting the diet will succeed", () => { cy.intercept("PATCH", "**/profile/diet", { statusCode: 200, body: { dietId: 1 } }).as( "updateDiet", ); }); Then("the diet update request should have been made with diet id {int}", (dietId: number) => { cy.wait("@updateDiet").its("request.body").should("deep.equal", { dietId }); }); Given("updating allergies will succeed", () => { cy.intercept("PATCH", "**/profile/allergies", { statusCode: 200, body: [2, 1] }).as( "updateAllergies", ); }); Then( "the allergies update request should have been made with allergy ids {int} and {int}", (first: number, second: number) => { cy.wait("@updateAllergies") .its("request.body") .should("deep.equal", { allergyIds: [first, second] }); }, );