import { describe, expect, it } from "vitest";
import { createMockDb } from "../../../testing/index";
import { Transaction } from "../generated/kysely-tailordb";
import { SetBaseCurrencyDeprecatedError } from "../lib/errors.generated";
import { run } from "./setBaseCurrency";

describe("setBaseCurrency", () => {
  it("Calling SetBaseCurrency returns a deprecation error directing the caller to the organization module", async () => {
    const { db } = createMockDb<Transaction>();

    const result = await run(db, { currencyId: "any-currency-id" });

    expect(result.ok).toBe(false);
    if (!result.ok) {
      expect(result.error).toBeInstanceOf(SetBaseCurrencyDeprecatedError);
    }
  });

  it("No currency is modified when SetBaseCurrency is invoked", async () => {
    const { db, spies } = createMockDb<Transaction>();

    await run(db, { currencyId: "any-currency-id" });

    expect(spies.select).not.toHaveBeenCalled();
    expect(spies.update).not.toHaveBeenCalled();
  });
});
