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

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

    const result = await run(mock.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 mock = createKyselyMock<Namespace["main-db"]>();
    mock.enqueueResults([]);

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

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