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

describe("getProductAttributeAssignment", () => {
  it("returns assignments when found by productId and attributeId", async () => {
    const mock = createKyselyMock<Namespace["main-db"]>();
    mock.enqueueResults([baseAttributeAssignment]);

    const result = await run(mock.db, {
      productId: "product-2",
      attributeId: "attr-1",
    });

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

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

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

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