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

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

    const result = await run(db, { productId: "product-2" });

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

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

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

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