import { describe, expect, it } from "vitest";

import {
  extractJobIdFromExportHref,
  validateExportBody,
} from "../e2e/sample-flow/page-flow";

describe("page-flow helpers", () => {
  it("extracts job ids from optimized export links", () => {
    expect(
      extractJobIdFromExportHref("/api/jobs/job_abc123/exports/optimized.md"),
    ).toBe("job_abc123");
  });

  it("validates export response bodies", () => {
    expect(validateExportBody("optimized.md", Buffer.from("# 标题"))).toBeUndefined();
    expect(
      validateExportBody(
        "optimized.docx",
        Buffer.from([0x50, 0x4b, 0x03, 0x04]),
      ),
    ).toBeUndefined();
    expect(
      validateExportBody(
        "qa_report.json",
        Buffer.from(
          JSON.stringify({
            overall_status: "pass",
            checks: [],
          }),
        ),
      ),
    ).toBeUndefined();
    expect(validateExportBody("optimized.md", Buffer.from(""))).toBe(
      "empty export body",
    );
  });
});
