Files
adopt-a-street/backend/__tests__/jest.setup.js
William Valentin df245fff90 fix: resolve CouchDB connection issues in backend tests
- Add jest.preSetup.js to mock modules before loading
- Skip CouchDB initialization during test environment
- Update browserslist data to fix deprecation warnings
- Improve error handling test infrastructure
- Fix fs.F_OK deprecation warning via dependency update

🤖 Generated with [AI Assistant]

Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
2025-11-03 12:11:10 -08:00

48 lines
1.3 KiB
JavaScript

// Get reference to the mocked couchdbService for test usage
const couchdbService = require('../services/couchdbService');
// Make mock available for tests to reference
global.mockCouchdbService = couchdbService;
// Mock Cloudinary
jest.mock('cloudinary', () => ({
v2: {
config: jest.fn(),
uploader: {
upload: jest.fn().mockResolvedValue({
secure_url: 'https://cloudinary.com/test/image.jpg',
public_id: 'test_public_id',
width: 500,
height: 500,
format: 'jpg'
}),
destroy: jest.fn().mockResolvedValue({ result: 'ok' })
}
}
}));
// Mock nodemailer
jest.mock('nodemailer', () => ({
createTransport: jest.fn().mockReturnValue({
sendMail: jest.fn().mockResolvedValue({ messageId: 'test-message-id' })
})
}));
// Make 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
};