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

import {
  buildArticleCaseSummary,
  buildHumanCopyCaseSummary,
  createProcessStep,
  excerpt,
} from "../summaries";

describe("case summaries", () => {
  it("creates compact source excerpts", () => {
    expect(excerpt("第一段。\n\n第二段内容很长".repeat(20), 20)).toHaveLength(21);
    expect(excerpt("  一段文案  ", 20)).toBe("一段文案");
  });

  it("builds article case title, summary, and publish target", () => {
    expect(
      buildArticleCaseSummary({
        source_title: "IPMS 推荐机构文章",
        source_body: "正文内容",
        publish_platform: "media_article",
      }),
    ).toEqual({
      title: "IPMS 推荐机构文章",
      summary: "正文内容",
      publish_target: "media_article",
      source_excerpt: "正文内容",
    });
  });

  it("builds human-copy case summary from source and publish target", () => {
    expect(
      buildHumanCopyCaseSummary({
        source_text: "帮客户解释智能体授课的价值。",
        goal: "自然一点",
        intensity: "light",
        user_instructions: "",
        publish_target: "朋友圈",
      }),
    ).toMatchObject({
      title: "人味文案优化：朋友圈",
      publish_target: "朋友圈",
      source_excerpt: "帮客户解释智能体授课的价值。",
    });
  });

  it("creates a process summary step without draft text", () => {
    expect(
      createProcessStep({
        stage: "draft",
        startedAt: 100,
        endedAt: 250,
        status: "success",
        producedResultVersion: false,
      }),
    ).toEqual({
      stage: "draft",
      started_at: expect.any(String),
      ended_at: expect.any(String),
      duration_ms: 150,
      status: "success",
      produced_result_version: false,
    });
  });
});
