import { describe, it, expect } from "vitest";
import {
  renderCommandStub,
  renderCommandTestStub,
  renderDbStub,
  renderQueryStub,
  renderQueryTestStub,
} from "./stubs";

describe("renderCommandStub", () => {
  it("generates input interface and run function", () => {
    const result = renderCommandStub("createItem");
    expect(result).toContain("export interface CreateItemInput");
    expect(result).toContain(
      "export async function run(db: Transaction, input: CreateItemInput, ctx: CommandContext)",
    );
    expect(result).toContain("return ok({})");
  });
});

describe("renderCommandTestStub", () => {
  it("generates test with createKyselyMock", () => {
    const result = renderCommandTestStub("createItem");
    expect(result).toContain('describe("createItem - test scenario"');
    expect(result).toContain("createKyselyMock<Namespace[keyof Namespace]>()");
    expect(result).toContain("CreateItemInput");
  });
});

describe("renderQueryStub", () => {
  it("generates ReadonlyDB-based stub", () => {
    const result = renderQueryStub("getProduct");
    expect(result).toContain("export interface GetProductInput");
    expect(result).toContain("ReadonlyDB<DB>");
  });
});

describe("renderQueryTestStub", () => {
  it("generates test with createKyselyMock", () => {
    const result = renderQueryTestStub("getProduct");
    expect(result).toContain('describe("getProduct"');
    expect(result).toContain("createKyselyMock<Namespace[keyof Namespace]>()");
    expect(result).toContain("type GetProductInput");
  });
});

describe("renderDbStub", () => {
  it("generates model type definition", () => {
    const result = renderDbStub("item");
    expect(result).toContain("export function createItemType");
    expect(result).toContain("export const item = createItemType({});");
    expect(result).toContain('.type("Item"');
    expect(result).toContain(".permission(defaultPermission)");
    expect(result).toContain(".gqlPermission(defaultGqlPermission)");
  });
});
