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

describe("listProductAttributeValues", () => {
  it("returns values when found", async () => {
    const { db, spies } = createMockDb<DB>();
    spies.select.mockReturnValue([baseColorRed, baseColorBlue]);

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

    expect(result.ok).toBe(true);
    if (result.ok) {
      expect(result.value.values).toEqual([baseColorRed, baseColorBlue]);
    }
  });

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

    const result = await run(db, { attributeId: "attr-99" });

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