import { Test, TestingModule } from '@nestjs/testing';
import { TenantContextService, TenantInfo } from '@it0/common';

export const TEST_TENANT: TenantInfo = {
  tenantId: 't_test',
  tenantName: 'Test Tenant',
  plan: 'enterprise',
  schemaName: 'it0_t_test',
  maxServers: -1,
  maxUsers: -1,
  maxStandingOrders: -1,
  maxAgentTokensPerMonth: -1,
};

export function withTenant<T>(fn: () => T, tenant: TenantInfo = TEST_TENANT): T {
  return TenantContextService.run(tenant, fn);
}

export async function createTestingModule(
  metadata: Parameters<typeof Test.createTestingModule>[0],
): Promise<TestingModule> {
  return Test.createTestingModule(metadata).compile();
}
