import { describe, it, expect } from "vitest";
import { buildGroceryExportPayload, groceryExportToText } from "../grocery-export";

describe("buildGroceryExportPayload", () => {
  it("maps unchecked items and drops checked ones", () => {
    const payload = buildGroceryExportPayload({
      name: "Weekly groceries",
      items: [
        { rawName: "Milk", quantity: "1", unit: "L", checked: false },
        { rawName: "Eggs", quantity: "12", unit: null, checked: true },
      ],
    });
    expect(payload.listName).toBe("Weekly groceries");
    expect(payload.items).toEqual([{ name: "Milk", quantity: "1", unit: "L" }]);
  });
});

describe("groceryExportToText", () => {
  it("renders a plain-text list with quantities", () => {
    const text = groceryExportToText({
      listName: "Weekly groceries",
      items: [
        { name: "Milk", quantity: "1", unit: "L" },
        { name: "Bananas", quantity: null, unit: null },
      ],
    });
    expect(text).toBe("Weekly groceries\n\n1 L Milk\nBananas");
  });
});
