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

describe("getPartnerRole", () => {
  it("returns role when found", async () => {
    const { db, spies } = createMockDb<DB>();
    spies.select.mockReturnValue(baseCustomerRole);

    const result = await run(db, { partnerId: "partner-2", role: "CUSTOMER" });

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

  it("returns null when role not found", async () => {
    const { db, spies } = createMockDb<DB>();
    spies.select.mockReturnValue(undefined);

    const result = await run(db, { partnerId: "partner-2", role: "VENDOR" });

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