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

describe("getPartnerBankAccount", () => {
  it("returns bank account when found", async () => {
    const { db, spies } = createMockDb<DB>();
    spies.select.mockReturnValue(baseDefaultBankAccount);

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

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

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

    const result = await run(db, { id: "nonexistent" });

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