import {
  extractApplicationAnswerDraft, removeApplicationAnswerDraft, upsertApplicationAnswerDraft,
} from "./applicationDrafts";

test("application answer helpers keep human notes separate", () => {
  const stored = upsertApplicationAnswerDraft("Human note", " Draft answer ");

  expect(stored).toBe("Human note\n\n<<<APPLICATION_ANSWER_DRAFT>>>\nDraft answer\n<<<END_APPLICATION_ANSWER_DRAFT>>>");
  expect(extractApplicationAnswerDraft(stored)).toBe("Draft answer");
  expect(removeApplicationAnswerDraft(stored)).toBe("Human note");
});

test("clearing an answer retains human notes and removes all marker blocks", () => {
  const duplicated = "Human note\n\n<<<APPLICATION_ANSWER_DRAFT>>>\nFirst\n<<<END_APPLICATION_ANSWER_DRAFT>>>\n\n<<<APPLICATION_ANSWER_DRAFT>>>\nSecond\n<<<END_APPLICATION_ANSWER_DRAFT>>>";

  expect(upsertApplicationAnswerDraft(duplicated, "")).toBe("Human note");
});

test("legacy application answer labels remain readable during migration", () => {
  const legacy = "Human note\n\nApplication answer draft:\nLegacy answer";

  expect(extractApplicationAnswerDraft(legacy)).toBe("Legacy answer");
  expect(removeApplicationAnswerDraft(legacy)).toBe("Human note");
});
