import type { ApiErrorCode } from '@thebet365/shared';

export function transactionPassthrough<T extends object>(client: T) {
  return jest.fn(async <R>(fn: (tx: T) => Promise<R>) => fn(client));
}

export function createPrismaMock<T extends object>(client: T): T & { $transaction: jest.Mock } {
  return {
    ...client,
    $transaction: transactionPassthrough(client),
  };
}

export function expectAppError(code: ApiErrorCode) {
  return expect.objectContaining({
    response: expect.objectContaining({ code }),
  });
}
