import { createKyselyMock } from "@tailor-platform/sdk/vitest";
import { describe, expect, it } from "vitest";
import type { Namespace } 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 mock = createKyselyMock<Namespace["main-db"]>();

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

    await mock.withTx((trx) => run(trx, { currencyId: "any-currency-id" }));

    expect(mock.selects).toHaveLength(0);
    expect(mock.updates).toHaveLength(0);
  });
});
