import { Given, Then } from "@badeball/cypress-cucumber-preprocessor";

const signupResponse = {
  id: 1,
  firstName: "Alice",
  lastName: "Martin",
  email: "alice@example.com",
  tokenVersion: 0,
  houseId: null as number | null,
  dietId: null,
};

// Signs up and lands on the wizard's first step (regime) — shared setup for
// every scenario in this feature, mirroring `signupAndReachOnboarding` from
// the pre-conversion spec.
Given("I have signed up", () => {
  cy.intercept("GET", "**/auth/me", { statusCode: 401 });
  cy.intercept("POST", "**/auth/signup", { statusCode: 201, body: signupResponse }).as("signup");

  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");
});

Then("the diet update request should have been made with no diet id", () => {
  cy.wait("@updateDiet").its("request.body").should("deep.equal", { dietId: null });
});

Then("the allergies update request should have been made with allergy id {int}", (id: number) => {
  cy.wait("@updateAllergies")
    .its("request.body")
    .should("deep.equal", { allergyIds: [id] });
});

Then("the allergies update request should have been made with no allergy ids", () => {
  cy.wait("@updateAllergies").its("request.body").should("deep.equal", { allergyIds: [] });
});
