import { type CommandContext } from "@tailor-platform/erp-kit/core";
import { expect } from "vitest";

export const commandCtx: CommandContext = {
  actorId: "test-actor",
  permissions: ["sales:*"],
};

interface OkResult<T> {
  ok: true;
  value: T;
}

interface ErrResult {
  ok: false;
  error: unknown;
}

export function expectErr(
  result: OkResult<unknown> | ErrResult,
  errorClass: abstract new (...args: never[]) => Error,
) {
  expect(result.ok).toBe(false);
  if (!result.ok) {
    expect(result.error).toBeInstanceOf(errorClass);
  }
}

export function expectOk<T>(result: OkResult<T> | ErrResult) {
  expect(result.ok).toBe(true);
  if (!result.ok) {
    throw result.error;
  }
  return result.value;
}
