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>
This commit is contained in:
William Valentin
2025-11-03 12:11:10 -08:00
parent 5e872ef952
commit df245fff90
5 changed files with 255 additions and 79 deletions

View File

@@ -1,40 +1,34 @@
// 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),
};
// Get reference to the mocked couchdbService for test usage
const couchdbService = require('../services/couchdbService');
jest.mock('../services/couchdbService', () => mockCouchdbService);
// Make mock available for tests to reference
global.mockCouchdbService = couchdbService;
// Make the mock available for tests to reference
// 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