// Mock CouchDB service globally for all tests const mockCouchdbService = { initialize: jest.fn().mockResolvedValue(true), isReady: jest.fn().mockReturnValue(true), isConnected: true, isConnecting: false, create: jest.fn(), getById: jest.fn(), get: jest.fn(), find: jest.fn(), destroy: jest.fn(), delete: jest.fn(), createDocument: jest.fn().mockImplementation((doc) => Promise.resolve({ _id: `test_${Date.now()}`, _rev: '1-test', ...doc })), updateDocument: jest.fn().mockImplementation((id, doc) => Promise.resolve({ _id: id, _rev: '2-test', ...doc })), deleteDocument: jest.fn().mockResolvedValue(true), findByType: jest.fn().mockResolvedValue([]), findUserById: jest.fn(), findUserByEmail: jest.fn(), update: jest.fn(), updateUserPoints: jest.fn(), getDocument: jest.fn(), findDocumentById: jest.fn(), bulkDocs: jest.fn(), shutdown: jest.fn().mockResolvedValue(true), }; jest.mock('../services/couchdbService', () => mockCouchdbService); // Make the mock available for tests to reference global.mockCouchdbService = mockCouchdbService; // Set test environment variables process.env.JWT_SECRET = 'test-jwt-secret'; 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 };