
// Set test environment variables (must be at least 32 chars for validation)
process.env.JWT_SECRET = 'test-jwt-secret-for-testing-purposes-that-is-long-enough';
process.env.NODE_ENV = 'test';
process.env.COUCHDB_URL = 'http://localhost:5984';
process.env.COUCHDB_DB_NAME = 'test-adopt-a-street';

// Suppress console logs during tests unless there's an error
global.console = {
  ...console,
  log: jest.fn(),
  debug: jest.fn(),
  info: jest.fn(),
  warn: jest.fn(),
  error: console.error, // Keep error logging
};

// Ensure each test starts with a clean in-memory DB if available
beforeEach(() => {
  if (typeof global.__resetCouchStore === 'function') {
    global.__resetCouchStore();
  }
});

// Note: Do NOT require('../services/couchdbService') here.
// We rely on jest.preSetup.js to define a virtual mock for the module.
// For tests that provide their own per-file jest.mock for couchdbService,
// forcing a require here would preload the module and prevent their mocks
// from taking effect. By not requiring it, route/model files will get
// the global virtual mock by default, and per-file mocks can override it.
