import { describe, it, expect } from "vitest";
import { renderResolverStub, renderStoryTestStub } from "./stubs";

describe("renderResolverStub", () => {
  it("generates createResolver stub with SDK imports", () => {
    const result = renderResolverStub("createItem");
    expect(result).toContain("createResolver");
    expect(result).toContain('name: "createItem"');
    expect(result).toContain('operation: "mutation"');
    expect(result).toContain('getDB("main-db")');
  });

  it("generates a createResolver stub with SDK imports and transaction boilerplate", () => {
    const result = renderResolverStub("createItem");

    expect(result).toContain('import { createResolver, t } from "@tailor-platform/sdk";');
    expect(result).toContain('import { createContext } from "@tailor-platform/erp-kit/app";');
    expect(result).toContain('import { getDB } from "@/generated/kysely-tailordb";');
    expect(result).toContain('name: "createItem"');
    expect(result).toContain('operation: "mutation"');
    expect(result).toContain('getDB("main-db")');
    expect(result).toContain("db.transaction().execute");
    expect(result).toContain('.description("CreateItem response")');
  });
});

describe("renderStoryTestStub", () => {
  it("generates integration test with graphql client and test cases", () => {
    const result = renderStoryTestStub("admin--create-item", [
      "creates item successfully",
      "rejects duplicate SKU",
    ]);
    expect(result).toContain('describe("admin--create-item"');
    expect(result).toContain("createGraphQLClient");
    expect(result).toContain('it("creates item successfully"');
    expect(result).toContain('it("rejects duplicate SKU"');
  });
});
