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

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

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

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

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

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

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