import { describe, expect, it } from "vitest";
import { createMockDb } from "../../../testing/index";
import type { DB } from "../generated/kysely-tailordb";
import { baseChildCategory } from "../testing/fixtures";
import { run } from "./listProductCategoryChildren";

describe("listProductCategoryChildren", () => {
  it("returns children when found", async () => {
    const { db, spies } = createMockDb<DB>();
    spies.select.mockReturnValue([baseChildCategory]);

    const result = await run(db, { parentId: "category-1" });

    expect(result.ok).toBe(true);
    if (result.ok) {
      expect(result.value.children).toEqual([baseChildCategory]);
    }
  });

  it("returns empty array when no children", async () => {
    const { db, spies } = createMockDb<DB>();
    spies.select.mockReturnValue([]);

    const result = await run(db, { parentId: "category-3" });

    expect(result.ok).toBe(true);
    if (result.ok) {
      expect(result.value.children).toEqual([]);
    }
  });
});
