import { expect, test } from "@playwright/test";
import { createCase, openCaseOnStep, sendChat, sendMany, STEP_SCRIPT } from "./helpers";

test("step 2 Demographics & loan facts: needs age/DOB and loan_balance", async ({ request, page }) => {
  const created = await createCase(request);
  const c = await sendMany(request, created.caseId, [
    STEP_SCRIPT.name,
    STEP_SCRIPT.state,
    STEP_SCRIPT.intent,
  ]);
  expect(c.process.step).toBe(2);
  expect(c.process.missingRequired).toEqual(
    expect.arrayContaining(["date_of_birth", "loan_balance"])
  );

  await openCaseOnStep(page, c.caseId);
  await expect(page.getByTestId("process-current")).toHaveText("Demographics & loan facts");
  await expect(page.getByTestId("process-exit-gate")).toContainText("Age or DOB + loan_balance");

  const aged = await sendChat(request, c.caseId, STEP_SCRIPT.age);
  expect(aged.profile.age).toBe(40);
  expect(aged.process.step).toBe(2);

  const loaned = await sendChat(request, c.caseId, STEP_SCRIPT.loan);
  expect(loaned.profile.loan_balance).toBe(180000);
  expect(loaned.profile.loan_term_years).toBe(20);
  expect(loaned.process.step).toBe(3);
});
