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

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

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

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

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

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

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