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

describe("getDefaultPartnerBankAccount", () => {
  it("returns default bank account when one exists", async () => {
    const mock = createKyselyMock<Namespace["main-db"]>();
    mock.enqueueResults([baseDefaultBankAccount]);

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

    expect(result.ok).toBe(true);
    if (result.ok) {
      expect(result.value.partnerBankAccount).toEqual(baseDefaultBankAccount);
    }
  });

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

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

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

  it("returns null when partner has no bank accounts", async () => {
    const mock = createKyselyMock<Namespace["main-db"]>();
    mock.enqueueResults([]);

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

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