import { createKyselyMock } from "@tailor-platform/sdk/vitest";
import { describe, expect, it } from "vitest";
import type { Namespace } from "../generated/kysely-tailordb";
import { baseColorRed } from "../testing/fixtures";
import { run } from "./getProductAttributeValue";

describe("getProductAttributeValue", () => {
  it("returns value when found", async () => {
    const mock = createKyselyMock<Namespace["main-db"]>();
    mock.enqueueResults([baseColorRed]);

    const result = await run(mock.db, { id: "value-1" });

    expect(result.ok).toBe(true);
    if (result.ok) {
      expect(result.value.value).toEqual(baseColorRed);
    }
  });

  it("returns null when not found", async () => {
    const mock = createKyselyMock<Namespace["main-db"]>();
    mock.enqueueResults([]);

    const result = await run(mock.db, { id: "nonexistent" });

    expect(result.ok).toBe(true);
    if (result.ok) {
      expect(result.value.value).toBeNull();
    }
  });
});
