import { test, expect } from "@playwright/test";
import { USERS, login } from "./helpers";
import { poWithLineItemDescription, closeDb } from "./fixtures";

/**
 * Issue #8 — The exported PO must include the line item's optional description.
 * The export route renders the printable PO at /api/po/[id]/export?format=pdf;
 * we fetch it with the logged-in session and assert the description text is present.
 */
test.afterAll(closeDb);

test("#8 exported PO contains the line-item description", async ({ page }) => {
  const po = await poWithLineItemDescription();
  test.skip(!po, "no PO with a line-item description in staging data");

  await login(page, USERS.MANAGER);
  // page.request shares the authenticated browser cookies.
  const res = await page.request.get(`/api/po/${po!.id}/export?format=pdf`);
  expect(res.ok()).toBeTruthy();
  const body = await res.text();
  expect(body).toContain(po!.description);
});
