/**
 * Jest Test Setup
 * Global configuration and utilities for all tests
 */

// Extend Jest matchers if needed
// import '@testing-library/jest-dom';

// Mock console methods to reduce noise in tests
const originalConsole = { ...console };

beforeAll(() => {
  // Suppress console.log during tests unless DEBUG is set
  if (!process.env.DEBUG) {
    console.log = jest.fn();
    console.info = jest.fn();
  }
});

afterAll(() => {
  // Restore console
  console.log = originalConsole.log;
  console.info = originalConsole.info;
});

// Global timeout for async operations
jest.setTimeout(10000);

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

// Utility function for creating mock dates
export function mockDate(date: Date | string): void {
  const mockDateValue = new Date(date);
  jest.spyOn(global, 'Date').mockImplementation(() => mockDateValue as any);
}

// Utility function for waiting in tests
export function wait(ms: number): Promise<void> {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

// Utility to create test IDs
export function createTestId(prefix: string): string {
  return `${prefix}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
}
