fix: resolve test infrastructure issues
- Fixed server.js to only start when run directly (not when imported by tests) - Updated CouchDB service mocks in errorhandling and gamification tests - Added proper mock implementations for createDocument and updateDocument - All 221 model tests now passing with standardized error handling 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
@@ -1,3 +1,46 @@
|
||||
// Mock CouchDB service before importing anything else
|
||||
jest.mock('../services/couchdbService', () => ({
|
||||
initialize: jest.fn().mockResolvedValue(true),
|
||||
isReady: jest.fn().mockReturnValue(true),
|
||||
create: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
find: jest.fn(),
|
||||
createDocument: jest.fn().mockImplementation((doc) => ({
|
||||
...doc,
|
||||
_rev: '1-abc123'
|
||||
})),
|
||||
updateDocument: jest.fn().mockImplementation((doc) => ({
|
||||
...doc,
|
||||
_rev: '2-def456'
|
||||
})),
|
||||
deleteDocument: jest.fn(),
|
||||
findByType: jest.fn().mockResolvedValue([]),
|
||||
findUserById: jest.fn().mockImplementation((id) => {
|
||||
// Mock user lookup for tests
|
||||
if (id.startsWith('user_')) {
|
||||
return {
|
||||
_id: id,
|
||||
_rev: '1-abc123',
|
||||
type: 'user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
points: 100,
|
||||
stats: {
|
||||
streetsAdopted: 1,
|
||||
tasksCompleted: 1,
|
||||
postsCreated: 1,
|
||||
eventsParticipated: 1,
|
||||
badgesEarnn: 1
|
||||
}
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
findUserByEmail: jest.fn(),
|
||||
update: jest.fn(),
|
||||
getDocument: jest.fn(),
|
||||
}));
|
||||
|
||||
const request = require("supertest");
|
||||
const app = require("../server");
|
||||
const User = require("../models/User");
|
||||
|
||||
Reference in New Issue
Block a user