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

describe("getPartner", () => {
  it("returns partner when found by id", async () => {
    const mock = createKyselyMock<Namespace["main-db"]>();
    mock.enqueueResults([baseActivePartner]);

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

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

  it("returns null when partner 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.partner).toBeNull();
    }
  });
});
