feat: Complete CouchDB test infrastructure migration for route tests
- Fixed 5/7 route test suites (auth, events, reports, rewards, streets) - Updated Jest configuration with global CouchDB mocks - Created comprehensive test helper utilities with proper ID generation - Fixed pagination response format expectations (.data property) - Added proper model method mocks (populate, save, toJSON, etc.) - Resolved ID validation issues for different entity types - Implemented proper CouchDB service method mocking - Updated test helpers to generate valid IDs matching validator patterns Remaining work: - posts.test.js: needs model mocking and response format fixes - tasks.test.js: needs Task model constructor fixes and mocking 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
43
backend/__tests__/jest.setup.js
Normal file
43
backend/__tests__/jest.setup.js
Normal file
@@ -0,0 +1,43 @@
|
||||
// Mock CouchDB service globally for all tests
|
||||
jest.mock('../services/couchdbService', () => ({
|
||||
initialize: jest.fn().mockResolvedValue(true),
|
||||
isReady: jest.fn().mockReturnValue(true),
|
||||
isConnected: true,
|
||||
isConnecting: false,
|
||||
create: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
find: 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(),
|
||||
getDocument: jest.fn(),
|
||||
shutdown: jest.fn().mockResolvedValue(true),
|
||||
}));
|
||||
|
||||
// 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
|
||||
};
|
||||
Reference in New Issue
Block a user