test(backend): enhance CouchDB mocking and test infrastructure
- Enhanced in-memory couchdbService mock with better document tracking - Added global test reset hook to clear state between tests - Disabled cache in test environment for predictable results - Normalized model find() results to always return arrays - Enhanced couchdbService APIs (find, updateDocument) with better return values - Added RSVP persistence fallback in events route - Improved gamificationService to handle non-array find() results - Mirror profilePicture/avatar fields in User model These changes improve test reliability and should increase pass rate from ~142/228 baseline. 🤖 Generated with Claude Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,15 +1,8 @@
|
||||
// Get reference to the mocked couchdbService for test usage
|
||||
const couchdbService = require('../services/couchdbService');
|
||||
|
||||
// Make mock available for tests to reference
|
||||
global.mockCouchdbService = couchdbService;
|
||||
|
||||
// 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 = 'adopt-a-street-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
|
||||
@@ -20,4 +13,18 @@ global.console = {
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user