import { describe, it, expect } from "vitest";
import { resolveAppDocPath } from "./doc";

describe("resolveAppDocPath", () => {
  it("resolves actor doc path", () => {
    const result = resolveAppDocPath("actor", "admin", "examples/my-app");
    expect(result).toBe("examples/my-app/docs/actor/admin.md");
  });

  it("resolves business-flow doc path", () => {
    const result = resolveAppDocPath("business-flow", "onboarding", "examples/my-app");
    expect(result).toBe("examples/my-app/docs/business-flow/onboarding/README.md");
  });

  it("resolves story doc path with flow/name format", () => {
    const result = resolveAppDocPath("story", "onboarding/admin--create-user", "examples/my-app");
    expect(result).toBe(
      "examples/my-app/docs/business-flow/onboarding/story/admin--create-user.md",
    );
  });

  it("resolves screen doc path", () => {
    const result = resolveAppDocPath("screen", "supplier-list", "examples/my-app");
    expect(result).toBe("examples/my-app/docs/screen/supplier-list.md");
  });

  it("resolves resolver doc path", () => {
    const result = resolveAppDocPath("resolver", "create-supplier", "examples/my-app");
    expect(result).toBe("examples/my-app/docs/resolver/create-supplier.md");
  });

  it("throws when name is missing", () => {
    expect(() => resolveAppDocPath("actor", undefined, "examples/my-app")).toThrow(
      "Name is required",
    );
  });

  it("throws when story name is not flow/name format", () => {
    expect(() => resolveAppDocPath("story", "bad-name", "examples/my-app")).toThrow(
      "Story name must be",
    );
  });
});
