import { describe, expect, it } from "vitest";
import { createMockDb } from "../../../testing/index";
import type { DB } from "../generated/kysely-tailordb";
import { baseCurrencyUSD } from "../testing/fixtures";
import { getBaseCurrency } from "./getBaseCurrency.generated";
import type { QueryContext } from "@tailor-platform/erp-kit/module";

describe("getBaseCurrency", () => {
  const ctx: QueryContext = { actorId: "test-actor" };

  it("returns base currency when set", async () => {
    const { db, spies } = createMockDb<DB>();
    spies.select.mockReturnValue(baseCurrencyUSD);

    const result = await getBaseCurrency(db, undefined, ctx);

    expect(result.ok).toBe(true);
    if (result.ok) {
      expect(result.value.currency).toEqual(baseCurrencyUSD);
    }
  });

  it("returns null when no base currency is set", async () => {
    const { db, spies } = createMockDb<DB>();
    spies.select.mockReturnValue(undefined);

    const result = await getBaseCurrency(db, undefined, ctx);

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