// Test setup file for Jest
export {}; // Make this file a module

// Mock AppDataSource
jest.mock('../config/typeorm', () => ({
  AppDataSource: {
    getRepository: jest.fn(),
    isInitialized: true,
    initialize: jest.fn(() => Promise.resolve()),
    destroy: jest.fn(() => Promise.resolve()),
  },
}));

// Mock logger
jest.mock('../shared/utils/logger', () => ({
  logger: {
    debug: jest.fn(),
    info: jest.fn(),
    warn: jest.fn(),
    error: jest.fn(),
  },
}));

// Global test utilities
(global as any).testTenantId = 'test-tenant-uuid';
(global as any).testUserId = 'test-user-uuid';

// Extend global types for tests
declare global {
  var testTenantId: string;
  var testUserId: string;
}

// Clean up mocks after each test
afterEach(() => {
  jest.clearAllMocks();
});

// Handle unhandled promise rejections
process.on('unhandledRejection', (reason) => {
  console.error('Unhandled Rejection:', reason);
});
